gpt4 book ai didi

ios - PDFTron:带有自定义图像的 PTFileAttachment 未显示

转载 作者:行者123 更新时间:2023-11-30 11:17:19 25 4
gpt4 key购买 nike

我正处于最终确定 PDFTron 的阶段,并且正在尝试一些重要的功能。有必要在 PDF 上显示图像并对用户交互使用react。通过给定的示例,我发现我必须使用 PTFileAttachment,如下所示:

let file_attach = PTFileAttachment.createFileAttch(withPath: doc.getSDFDoc(), pos: PTPDFRect(x1: 80, y1: 280, x2: 200, y2: 320), path: Bundle.main.path(forResource: "peppers", ofType: "jpg"), icon_name: e_ptPushPin)
first_page.annotPushBack(file_attach)

似乎即使在给定的示例中它也不起作用。 PTFileAttachment 显示的是图钉而不是图像。因此我的问题是:

  1. 上述方法通过用户交互在 PDF 上呈现图像是否正确?否则正确的方法是什么?
  2. 为什么不唤醒?我还需要做什么?
  3. 如何设置图像的宽高比,例如宽屏、信箱或平移和扫描。

谢谢!

问你瑞安的问题

假设有一个平面图(pdf),我必须用精确的图片(特定窗口的图形表示)来定位和显示那里的所有 window 。换句话说,只是简单地将图像定位在 pdf 上。 PDF 的尺寸可以是 600 单位 x 600 单位,图像在 x: 200 和 y:300 位置处可以是 40 单位 x 40 单位。可以有很多窗口。

根据 PDFTron 的文档 PTFileAttachment 是满足要求的正确工具,但如何使用是问题。从您自己的示例中,有一个示例知道AnnotationsMiscellaneous Swift Samples,但它似乎也不起作用。我尝试了您提供的代码作为答案并进行了许多更正,但它仍然显示图钉而不是显示图像。

复制步骤

  1. 复制并粘贴您自己的代码
  2. 复制图像 peppers.jpg
  3. 运行,您将只看到图钉,而不是 peppers.jpg

最佳答案

听起来您想更改文件附件注释的外观:

func createImageAppearance(doc: PTPDFDoc, img: PTImage) -> PTObj {
let builder: PTElementBuilder = PTElementBuilder()
let writer: PTElementWriter = PTElementWriter()
writer.writerBegin(with: doc.getSDFDoc(), compress: true)
let w: Int32 = img.getWidth()
let h: Int32 = img.getHeight()
let element = builder.createImage(withCornerAndScale: img, x: 0, y: 0, hscale: Double(w), vscale: Double(h))
writer.writePlacedElement(element)
let appearance_stream: PTObj = writer.end()
appearance_stream.putRect("BBox", x1: 0, y1: 0, x2: Double(w), y2: Double(h))
return appearance_stream
}

let image: PTImage = PTImage.create(doc.getSDFDoc(), filename: Bundle.main.path(forResource: "peppers", ofType: "jpg"))
let file_attach: PTFileAttachment = PTFileAttachment.createFileAttch(withPath: doc.getSDFDoc(), pos: PTPDFRect(x1: 80, y1: 280, x2: 200, y2: 320), path: Bundle.main.path(forResource: "peppers", ofType: "jpg"), icon_name: e_ptPushPin)
first_page.annotPushBack(file_attach)
let app_stm: PTObj = createImageAppearance(doc: doc, img: image)
file_attach.setAppearance(app_stm, annot_state: e_ptnormal, app_state: "")

关于ios - PDFTron:带有自定义图像的 PTFileAttachment 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com