【问题标题】:Saving a webview as html and pdf将 webview 保存为 html 和 pdf
【发布时间】:2012-06-02 07:58:28
【问题描述】:

我正在可可中创建一个类似应用程序的浏览器。我想在我的硬盘中将 web 视图保存为 html 和 PDF 文件。请指导我如何进行。举个例子会很有帮助。

【问题讨论】:

  • 您到底需要什么帮助?
  • 我只是想要一个加载了 url 的 webview 框架以保存在 pdf 中。我试过这个: NSData *pdfData = [webView dataWithPDFInsideRect:[webView frame]]; PDFDocument *document = [[PDFDocument alloc] initWithData:pdfData]; [文档 writeToURL:[NSURL URLWithString:@"file:///Users/tmp/test.pdf"]];它不工作

标签: macos cocoa webview


【解决方案1】:

你有答案吗?如果不试试这个。

    NSData *pdfData = [[[[webview mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[webview mainFrame] frameView] documentView].frame]; 
PDFDocument *document = [[PDFDocument alloc] initWithData:pdfData];
[document writeToFile:@"/Users/MyName/Desktop/test.pdf"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 2014-01-12
    • 2017-05-27
    • 2019-01-17
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    相关资源
    最近更新 更多