0

We are using iText Pdf API version 5.5.3 and we are trying to merge pdf documents which sometimes contain checkboxes , we write pdf document in servlet output stream and displays in iframe.

It works well in IE(tried in 11) but checkbox doesn't appear in Chrome(tried in 52).

Below is the sample code we use to display PDF.

                    InputStream in = docFile.getImage()
                            .getBinaryStream();
                    reader = new PdfReader(in);
                    pdfReaderList.add(reader);


                    document = new Document(PageSize.A4);
                    byteArrayOutputStream = new ByteArrayOutputStream();
                    PdfCopy copy = new PdfCopy(document, byteArrayOutputStream);
                    document.setMargins(35, 35, 48, 75);
                    document.open();
                    copy.setMargins(35, 35, 48, 75);
                    // add a document

                    Iterator<PdfReader> pdfReader = pdfReaderList.iterator();
                    while (pdfReader.hasNext()){
                        PdfImportedPage page;
                        reader = MCPDFFileWriter.unlockPdf(pdfReader.next());
                        for (int currentPage = 1; currentPage <= reader.getNumberOfPages(); currentPage++) {
                            page = copy.getImportedPage(reader, currentPage);
                            pageNum++;
                            copy.addPage(page);
                            footerNamesList.add(fileName);
                            footerMap.put(footerMap.size() + 1, fileName);

                        }
                    }

                    document.close ();
                    reader.close();
                    copy.close();

I also gone through this Link and given solution seems to be working when I use below code -

                    InputStream in = docFile.getImage()
                            .getBinaryStream();
                    reader = new PdfReader(in);
                    pdfReaderList.add(reader);


                    document = new Document(PageSize.A4);
                    byteArrayOutputStream = new ByteArrayOutputStream();
                    PdfCopy copy = new PdfCopy(document, byteArrayOutputStream);
                    document.setMargins(35, 35, 48, 75);
                    document.open();
                    copy.setMargins(35, 35, 48, 75);
                    **copy.setMergeFields();**

                    // add a document
                    **copy.addDocument(reader);**                                   
                    document.close ();
                    reader.close();
                    copy.close();

However I sometimes face OutOfMemoryError and looking for some idea if there is any known issue with copy.setMergeFields();copy.addDocument(reader); and how it can be overcome ?

A bug was also reported in chrome ( in the thought of plugin issue) and sample pdf are attached there

Community
  • 1
  • 1
csarathe
  • 420
  • 1
  • 5
  • 12
  • There were some issues in the 5.4.5 line related to OOM and `setMergeFields()` that was supposed to be addressed int 5.4.6 but some people are still reporting it as of 5.5.3. On difference between your sample and others is that they call `copy.setMergeFields()` _before_ `document.open()`, so maybe try that first. Otherwise I'd recommend trying the most recent version of the 5.x line which is 5.5.9. – Chris Haas Sep 07 '16 at 15:55
  • Thanks. Without API upgrade I could solve OOM Error. – csarathe Sep 28 '16 at 06:49

0 Answers0