【问题标题】:Android iText addTemplate Stamp pdf form fields overtop exisiting PDF documentAndroid iText addTemplate Stamp pdf 表单字段覆盖现有 PDF 文档
【发布时间】:2012-09-12 14:47:41
【问题描述】:

我正在尝试从 Android 中的旧应用程序打开标准 PDF 表单,使用 iText 覆盖表单字段并传递给 Android 上的 Adob​​e Reader 以填写表单。

我已经能够手动创建 TextFields,但我更喜欢使用 pdf 文件作为模板来加快流程并更好地控制质量。

这是我到目前为止的代码,它遵循 itext 示例。

    AssetFileDescriptor descriptor = getAssets().openFd("standardWO_Template_v1_fo.pdf");
            File templateFile = new File(descriptor.getFileDescriptor().toString());
            PdfReader reader = new PdfReader(intent.getData().getPath());
            reader.selectPages("1");
            PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath());
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file));
            // Stamp the template onto the document
            PdfImportedPage page = stamper.getImportedPage(templateReader, 1);
            PdfContentByte cb = stamper.getOverContent(1);
            cb.addTemplate(page, 0, 0);

我遇到的问题在最后一行。 cb.addTemplate(page, 0,0);

Eclipse 报告以下错误。无法解析 java.awt.geom.AffineTransform 类型。它是从所需的 .class 文件中间接引用的

据我所知,java.awt.geom.AffineTransform 仅适用于 Android 的 Java。

有没有其他方法可以完成我的任务或让 AffineTransform 在 Android 中工作?

【问题讨论】:

    标签: android itext pdf-manipulation android-droidtext


    【解决方案1】:

    经过一番搜索,我找到了这种方法。首先,我必须从在我的 android 项目中使用 iText5.3.1 库更改为 droidText 库。

    一旦我安装了 droidText 库,就可以使用以下代码。 (以及 Eclipse 中的 ctrl-o)

        File templateFile = new File(dir.getAbsolutePath() + "/templates/standardWO.pdf");
                // Read the incoming file
                PdfReader reader = new PdfReader(intent.getData().getPath());
                // Read the template form information
                PdfReader templateReader = new PdfReader(templateFile.getAbsolutePath());
                // Create the stamper from the incoming file.
                PdfStamper stamper = new PdfStamper(templateReader, new FileOutputStream(file));
                // Import the template information
                PdfImportedPage iPage = stamper.getImportedPage(reader, 1);
                // get the direct content
                PdfContentByte cb = stamper.getUnderContent(1);
                // Add the imported page to the content
                cb.addTemplate(iPage, 0, 0);
                stamper.close();
                Log.v(TAG, "Opening file in adobe reader: " + file.getAbsolutePath());
                loadDocInReader(file);
    

    【讨论】:

    • 嘿,谢谢尼克,为这个特殊的信息。我正在尝试在 Eclipse 的 java 应用程序中使用 pdfReader api。这给出了:pdfreader 无法解析为类型错误。你能告诉我,在这里做什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 2014-01-03
    相关资源
    最近更新 更多