1

I am new to PDF creation technique in MAC OSx.

Can you please help me to create PDF programmatically from NSString. I have a multiple HTML files and I am going to create the PDF of each one and this html file I am not going to display on Screen.So printing technique also not help to me.

 NSPrintInfo *printInfo;
 NSPrintInfo *sharedInfo;
 NSPrintOperation *printOp;
 NSMutableDictionary *printInfoDict;
 NSMutableDictionary *sharedDict;
sharedInfo = [NSPrintInfo sharedPrintInfo];
sharedDict = [sharedInfo dictionary];
 printInfoDict = [NSMutableDictionary 
 dictionaryWithDictionary:sharedDict];
[printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
NSString *tempFileName = 
[NSString stringWithFormat:@"%@_file_%lu.pdf", 
[[NSProcessInfo processInfo] globallyUniqueString], fileNumber];
NSURL *poTempfileURL = 
[_tempDirectoryURL URLByAppendingPathComponent:tempFileName];
[printInfoDict setObject:poTempfileURL forKey:NSPrintJobSavingURL];
printInfo = 
[[NSPrintInfo alloc] initWithDictionary:printInfoDict];//1
[printInfo setHorizontalPagination: NSAutoPagination];//2
[printInfo setVerticalPagination: NSAutoPagination];//3
[printInfo setVerticallyCentered:NO];//4

printOp = [NSPrintOperation printOperationWithView:textView printInfo:printInfo];//5
[printOp setShowsPrintPanel:NO];
[printOp setShowsProgressPanel:NO];//6
DLog(@"poTempfileURL=%@",poTempfileURL);

BOOL didRunOK = [printOp runOperation];//7

As you see '[NSPrintOperation printOperationWithView:textView printInfo:printInfo];' this line required view to print and I not going to display my content to any view. So please help me out to find out the best way to same.

Swapnil1156035
  • 343
  • 1
  • 10
  • 1
    Possible duplicate of [Create pdf using cocoa?](http://stackoverflow.com/questions/1976507/create-pdf-using-cocoa) – Amin Negm-Awad Feb 17 '16 at 09:49
  • Thanks for reply but [Create-pdf-using-cocoa](http://stackoverflow.com/questions/1976507/create-pdf-using-cocoa) contains some link and which is not working.Please help me out. – Swapnil1156035 Feb 19 '16 at 05:36
  • Please note that my issue is to create PDF from html file,I have multiple html file from that I have to create that. I am not going to display that HTML in webView so may be printing technique also not help to me. I just want to pass that HTML string and make PDF from that. – Swapnil1156035 Feb 19 '16 at 05:40
  • Googling the title of the link does not find the new location of the document? Everything is a PDF(TM). So it does not depend on displaying the content. As you know from many applications, printing layout can be completely different. – Amin Negm-Awad Feb 19 '16 at 06:00
  • Yes,I found it [Cocoa Printing Architecture](http://mirror.informatimago.com/next/developer.apple.com/documentation/Cocoa/Conceptual/Printing/Concepts/architecture.html) but my problem not with the printing.I have only HTML file from that I want to create PDF. – Swapnil1156035 Feb 19 '16 at 06:08
  • As explained in the linkes Q, printing, drawing, whatever, always creates a PDF. What you see on the screen, the paper, what is stored to disk *is* a PDF. So you can simply take it out from the view: `-dataWithPDFInsideRect:` (`NSView`). – Amin Negm-Awad Feb 19 '16 at 08:35
  • Possible duplicate of [How to create a PDF in Swift with Cocoa (Mac)](http://stackoverflow.com/questions/38947782/how-to-create-a-pdf-in-swift-with-cocoa-mac) – owlswipe Sep 13 '16 at 21:27

0 Answers0