Reputation: 2370
I need to convert a html file in a pdf file using Cocoa and Objective c. I found some examples here in Stackoverflow but all are for iPhone and not for Cocoa, so I could not succed with them. If someone could give me some lines of code for achieving this task or at least give me some clues on how to do it. Thanks for any help
Upvotes: 2
Views: 1104
Reputation: 2370
After some hours of frustration I finally found the way to do this... I really don't understand why someone downvoted my question... I thought this was a place where you can honestly ask things you don't know how to do and you can not find the answer googling it... but maybe I was wrong... Anyway I will post the code I finally found so if someone else will need to do this kind of stuff won't risk to get downvotes for asking it! Peace
NSString *fileName = [NSString stringWithFormat:@"%@/mypdf.pdf", documentsDirectory];
NSData *pdfFinal = [[[[webView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webView mainFrame] frameView] documentView].frame];
PDFDocument *doc = [[PDFDocument alloc] initWithData:pdfFinal];
[doc writeToFile:fileName];
Upvotes: 4