Itext pdf Merge : Document overflow outside pdf (Text truncated) page and not displaying

后端 未结 2 1170
长情又很酷
长情又很酷 2020-12-22 07:30

i am trying to merge 2 pdf in one. Merging is working fine but contents overflow from pdf page. A shown in attachment. Original Document pdf is as Follows.

相关标签:
2条回答
  • 2020-12-22 07:39

    Please download chapter 6 of my book and take a look at table 6.1. You're making the mistake merging two documents using PdfWriter instead of using PdfCopy as documented. Take a look at listing 6.22 to find out how to add page numbers when using PdfCopy.

    0 讨论(0)
  • 2020-12-22 07:46

    i used "PdfCopyFields" Snippet as follows :

    public static boolean concatPDFFiles(List<String> listOfFiles,
            String outputfilepath) throws FileNotFoundException, DocumentException {
        PdfCopyFields copy = null;
        try {
            copy = new PdfCopyFields(new FileOutputStream(outputfilepath));
        } catch (DocumentException ex) {
            Logger.getLogger(MergerGoogleDocsToPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            for (String fileName : listOfFiles) {
                PdfReader reader1 = new PdfReader(fileName);
                copy.addDocument(reader1);
            }
        } catch (IOException ex) {
            Logger.getLogger(MergerGoogleDocsToPDF.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            copy.close();
        }
        if (new File(outputfilepath).exists()) {
            double bytes = new File(outputfilepath).length();
            //double kilobytes = (bytes / 1024);
            if (bytes != 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    
    0 讨论(0)
提交回复
热议问题