Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用itext 5附加PDF_Pdf_Append_Itext - Fatal编程技术网

如何使用itext 5附加PDF

如何使用itext 5附加PDF,pdf,append,itext,Pdf,Append,Itext,我尝试将我的PDF附加到新的ITEXT文档中,但这是不可能的,我创建了我想要添加的文档。如何从文档级别执行此操作?需要以某种方式转换为字节吗 String inputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700.pdf"; // Existing file String outputFilePath = "C:\\Users\\yol\\Deskt

我尝试将我的PDF附加到新的ITEXT文档中,但这是不可能的,我创建了我想要添加的文档。如何从文档级别执行此操作?需要以某种方式转换为字节吗

  String inputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700.pdf"; // Existing file
    String outputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700_new.pdf"; // New file

    Document document = new Document();
    OutputStream fos = new FileOutputStream(new File(outputFilePath));
    PdfReader pdfReader = new PdfReader(inputFilePath);
    PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
    pdfStamper.insertPage(pdfReader.getNumberOfPages() + 1, pdfReader.getPageSizeWithRotation(1));


    PdfContentByte pdfContentByte = pdfStamper.getUnderContent(pdfReader.getNumberOfPages());

    pdfContentByte.beginText();
    pdfContentByte.setFontAndSize(BaseFont.createFont
                    (BaseFont.TIMES_ROMAN,
                            BaseFont.CP1257,
                            BaseFont.NOT_EMBEDDED
                    )
            , 12);
    pdfContentByte.setTextMatrix(35, 760);
    document.open();
    Chapter chapter = new Chapter("", 0);
    chapter.setNumberDepth(0);
    Paragraph time = new Paragraph("");
    Paragraph date = new Paragraph("");
    Paragraph type = new Paragraph("");


    chapter.add(time);
    chapter.add(date);
    chapter.add(type);
    document.add(chapter);





    pdfContentByte.endText();
    document.close();
    pdfStamper.close();
    pdfReader.close();

不要试图一次做完所有的事。首先使用
文档
&
PdfWriter
创建一个包含新内容的新PDF,并将其写入临时位置(文件系统或内存中)。然后使用新的
文档
PdfCopy
将所有要打包的文档合并到一个文档中。不要试图一次完成所有操作。首先使用
文档
&
PdfWriter
创建一个包含新内容的新PDF,并将其写入临时位置(文件系统或内存中)。然后使用新的
文档
PdfCopy
将所有要打包的文档合并到一个文档中。