英文:
How to add image annotation to pdf in pspdf flutter?
问题
我想要添加图像到PDF的代码。我在我的Flutter应用中使用pspdfkit。
我看到了pspdfkit flutter的官方文档。在那里,他们解释了如何将图像注释添加到pspdfkit web,但没有说明如何在pspdfkit flutter中添加图像注释。我需要代码或任何指南,帮助我在pspdfkit flutter中添加图像注释。
英文:
I want the code that adds an image to pdf. I am using pspdfkit in my flutter app.
I saw the official documentation of pspdfkit flutter. There they have explained how to add image annotation to pspdfkit web, but not pspdfkit flutter. I need code or any guide that would help me adding image annotation to pspdfkit flutter.
答案1
得分: 1
我尝试在Flutter中以交互方式(缩放/拖放/旋转)将签名图像插入到PDF中。以下是一些建议:
- PSPDFKit 不是免费且不开源。因此,如果您正在开发商业应用程序,必须注意这一点。对于我来说,我的公司和老板不希望依赖于付费库,所以我不能使用这个包。
- 在使用开源库的情况下:目前(截止到 2023年5月6日),没有真正的Flutter/Dart包允许您将图像添加到PDF中。因此,您必须在原生Kotlin + Swift中处理它。
这将需要大量的努力,您可以像我一样挑战自己:D:
- Kotlin/Java Android:使用Android Sticker View(我使用了Wuapnjie的StickerView)来处理交互;我使用了barteksc/AndroidPdfViewer来处理PDF。
- Swift:使用Swift的PDFKit。
注1:这是一项困难的任务,因为如果要正确地将图像插入到PDF中,您需要计算PDF中图像的坐标。请记住,PDF的坐标从底部左侧开始,而手机的坐标从顶部左侧开始。而PDF的度量单位是点(POINTS),而其他度量单位可以是像素或DIP。
注2:您可以使用MethodChannel将整个Flutter屏幕完全转换为本地代码,或者您可以使用Platform View将Flutter与本地结合使用(这样可以更容易在Flutter和本地之间进行通信,但更难创建)。我正在使用后一种选项。
也许这不是您想要的答案,但也许将来有些人可能会遇到同样的问题,所以我仍然在这里回答,也许在某一天会有所帮助。
英文:
I tried to insert signature image to PDF in Flutter in an interactive way (scale/drag & drop/rotate). Here are some advices for you:
- PSPDFKit is NOT free and NOT open-source. Therefore if you are making an commercial app, you must notice about this. For me, my company & boss doesn't want to depend on a paid library, so I cannot use this package.
- In case of open-source library: Currently (at this time 5/6/2023), there's no TRUE Flutter/Dart package that allow you to add image to a PDF. Therefore, you must handle it in native Kotlin + Swift.
This will take A LOT of effort, you could challenge yourself, like I did :
- Kotlin/Java Android: Use Android Sticker View (I used StickerView of Wuapnjie) to handle interactive; And I used barteksc/AndroidPdfViewer) to handle PDF.
- Swift: Use PDFKit of Swift.
Note 1: This is a hard task because if you want to insert an image to PDF correctly, you need to calculate COORDINATES of image in PDF. Keep in mind, coordinates of PDF is from bottom-left whereas phone is top-left. And the measurement of PDF is POINTS, whereas other can be pixels or DIP.
Note 2: You can use MethodChannel to completely change your Flutter entire screen to native code, or you can use Platform View to combine Flutter + native (that could easier to communicate between Flutter + native but harder to create). I'm using the latter option.
Well this maybe not a answer that you want, but maybe in future some guys could meet the same problem so I still answer here, maybe helpful some days.
答案2
得分: 0
方法通常在任何应用程序/ PDF 中都是相同的,要放置在页面上的对象通常是通过叠加来追加的,因此 PDF 或图像都不重要,您可能会发现某些应用程序将其称为水印。
至于代码,我只能指向相关示例,可以在 GitHub 上找到,例如 https://github.com/PSPDFKit/pspdfkit-android-catalog/blob/32476b0ce1dd482c740786217582135b646310e4/app/src/main/java/com/pspdfkit/catalog/examples/java/activities/AnnotationWithAlphaCreationActivity.java
英文:
The method is in general the same in any application/pdf the object to be placed over a page is normally appended by over stamping, thus PDF or image it should not matter you may find some applications call it watermark.
As for code I cannot help except to point to related examples can be found in github such as https://github.com/PSPDFKit/pspdfkit-android-catalog/blob/32476b0ce1dd482c740786217582135b646310e4/app/src/main/java/com/pspdfkit/catalog/examples/java/activities/AnnotationWithAlphaCreationActivity.java
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论