Folks;
macOS 10.15 - Xcode 11.3.1
I've been somewhat successful getting this method to create a PDFDocument from the contents of an NSTextView.
However, the contents of this NSTextView is an NSAttributedString (set using TextStorage).
The view behaves as expected and there is .pdf document created.
The contents of the .pdf file appears to be the .string value of the NSTextView.
How do I use this NSPrintOperation to produce a PDFDocument which retains the attributed string?
Thanks for any thoughts!
Steve
BTW: If anyone has a means of producing a PDFDocument from NSAttributedString for macOS that does not involve NSPrintOperation I would appreciate a quick example or a link... I used to use 'cupsfilter' but it has been marked deprecated AND it also yields this same result... It logs
'cupsfilter: No filter to convert from text/rtf to application/pdf.' but creates the file...(but loses the attributed string)
If anyone is still following along...
Thanks go to janabanan for staying with this thread!!
Here's simplified code which produces a .pdf file which retains the links embedded in the NSAttributedString which is displayed in 'sourceTextView'. This .pdf file is also appropriately paginated.
[savePanel beginSheetModalForWindow:self.windowController.window completionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setHorizontalPagination:NSFitPagination];
[printInfo setVerticallyCentered:NO];
[printInfo setHorizontallyCentered:NO];
[printInfo setLeftMargin:67.0];
[printInfo setRightMargin:67.0];
[printInfo setTopMargin:72.0];
[printInfo setBottomMargin:72.0];
[printInfo dictionary] [NSPrintJobDisposition] = NSPrintSaveJob;
[printInfo dictionary] [NSPrintJobSavingURL] = [savePanel URL];
NSPrintOperation *op = [NSPrintOperation printOperationWithView:self.windowController.sourceSourceTextView printInfo:printInfo];
[op setShowsPrintPanel:NO];
[op setShowsProgressPanel:NO];
[op runOperation];
}
[savePanel orderOut:self];
}];