【问题标题】:Adding text to existing PDF page in Cocoa under OS X在 OS X 下向 Cocoa 中的现有 PDF 页面添加文本
【发布时间】:2013-09-14 00:11:58
【问题描述】:

我正在努力使用 PDFkit 向现有 PDF 页面添加文本。不确定我是否需要深入研究 CGPDF 或者我错过了一些简单的东西。

在这里,我正在获取现有的单页 PDF 并(尝试)添加一行文本。

PDFDocument *thisPDF = [[PDFDocument alloc]initWithURL:PDFURL];
PDFPage *aPage =[thisPDF pageAtIndex:0];
NSRect pdfRect = [aPage boundsForBox:kPDFDisplayBoxArtBox];
[@“Text on PDF Page" drawInRect:pdfRect withAttributes:NULL];

我知道我应该添加一些属性,这可能是问题所在,但我正在寻找一些关于如何在这一点上添加文本的指导。我已经通过了 Quartz Guide,但这仅引用了 CGPDF 的东西,我已经尝试过但未能成功实现。

我可以只用 PDFKit 做我想做的事吗?我的方向正确吗?

【问题讨论】:

    标签: macos cocoa pdf


    【解决方案1】:

    好吧,不必像 CGPDF 那样走得太远,所需要的只是将 PDFPage 子类化并创建一个自定义 init 方法,传入我想要作为基础的 PDF 页面,覆盖以下方法:

    - (void) drawWithBox: (PDFDisplayBox) box
    - (NSRect) boundsForBox: (PDFDisplayBox) box
    

    感谢http://www.cocoabuilder.com/archive/cocoa/207723-pdfpage-creation-query.html 为我指明了正确的方向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 1970-01-01
      相关资源
      最近更新 更多