Skip to content

Commit

Permalink
Calculate page margins manually
Browse files Browse the repository at this point in the history
Based on implementation found at https://github.com/scottgarner/URL2PDF

Fix #190.
  • Loading branch information
uranusjr committed Nov 3, 2014
1 parent 06ce7f9 commit 967056a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion MacDown/Code/Document/MPDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,30 @@ - (IBAction)exportPdf:(id)sender
[panel beginSheetModalForWindow:w completionHandler:^(NSInteger result) {
if (result != NSFileHandlingPanelOKButton)
return;

// Margin calculation based on https://github.com/scottgarner/URL2PDF
NSPrintInfo *info = self.printInfo;
NSRect imageableBounds = info.imageablePageBounds;
NSSize paperSize = info.paperSize;
if (imageableBounds.size.width > paperSize.width)
{
imageableBounds.origin.x = 0;
imageableBounds.size.width = paperSize.width;
}
if (imageableBounds.size.height > paperSize.height)
{
imageableBounds.origin.y = 0;
imageableBounds.size.height = paperSize.height;
}
[info.dictionary addEntriesFromDictionary:@{
NSPrintJobDisposition: NSPrintSaveJob,
NSPrintJobSavingURL: panel.URL
NSPrintJobSavingURL: panel.URL,
NSPrintBottomMargin: @(imageableBounds.origin.y / 2.0),
NSPrintTopMargin: @(imageableBounds.origin.y / 2.0),
NSPrintLeftMargin: @(imageableBounds.origin.x / 2.0),
NSPrintRightMargin: @(imageableBounds.origin.x / 2.0),
}];

NSView *view = self.preview.mainFrame.frameView.documentView;
NSPrintOperation *op = [NSPrintOperation printOperationWithView:view
printInfo:info];
Expand Down

0 comments on commit 967056a

Please sign in to comment.