如何使用 Cocoa 将 html 文件转换为 pdf
How to convert html files to pdf using Cocoa
我需要使用 Cocoa 和 Objective c 将 html 文件转换为 pdf 文件。我在 Whosebug 中找到了一些例子,但都是针对 iPhone 而不是 Cocoa,所以我无法成功。
如果有人可以给我一些代码行来完成这个任务,或者至少给我一些如何做的线索。
感谢您的帮助
经过几个小时的挫折,我终于找到了解决这个问题的方法......我真的不明白为什么有人不赞成我的问题......我认为这是一个你可以诚实地问你不问的问题的地方'我不知道该怎么做,用谷歌搜索也找不到答案……但也许我错了……无论如何,我会 post 我终于找到的代码,这样如果其他人需要做这种事情不会因为提出问题而被否决!和平
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];
我需要使用 Cocoa 和 Objective c 将 html 文件转换为 pdf 文件。我在 Whosebug 中找到了一些例子,但都是针对 iPhone 而不是 Cocoa,所以我无法成功。 如果有人可以给我一些代码行来完成这个任务,或者至少给我一些如何做的线索。 感谢您的帮助
经过几个小时的挫折,我终于找到了解决这个问题的方法......我真的不明白为什么有人不赞成我的问题......我认为这是一个你可以诚实地问你不问的问题的地方'我不知道该怎么做,用谷歌搜索也找不到答案……但也许我错了……无论如何,我会 post 我终于找到的代码,这样如果其他人需要做这种事情不会因为提出问题而被否决!和平
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];