@Test public void directInIndirectChain() throws IOException { String filename = destinationFolder + "directInIndirectChain.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); PdfArray level1 = new PdfArray(); level1.add(new PdfNumber(1).makeIndirect(pdfDoc)); PdfDictionary level2 = new PdfDictionary(); level1.add(level2); PdfArray level3 = new PdfArray(); level2.put(new PdfName("level3"), level3); level2.put(new PdfName("num"), new PdfNumber(2).makeIndirect(pdfDoc)); level3.add(new PdfNumber(3).makeIndirect(pdfDoc)); level3.add(new PdfNumber(3).makeIndirect(pdfDoc)); PdfDictionary level4 = new PdfDictionary(); level4.put(new PdfName("num"), new PdfNumber(4).makeIndirect(pdfDoc)); level3.add(level4); PdfPage page1 = pdfDoc.addNewPage(); page1.getPdfObject().put(new PdfName("test"), level1); pdfDoc.close(); PdfReader reader = new PdfReader(filename); PdfDocument pdfDocument = new PdfDocument(reader); Assert.assertEquals("Rebuilt", false, reader.hasRebuiltXref()); Assert.assertEquals("Page count", 1, pdfDocument.getNumberOfPages()); PdfDictionary page = pdfDocument.getPage(1).getPdfObject(); Assert.assertEquals(PdfName.Page, page.get(PdfName.Type)); pdfDocument.close(); }
@Override public void close() throws IOException { try { super.close(); } finally { try { if (duplicateStream != null) { duplicateStream.close(); } } catch (Exception ex) { Logger logger = LoggerFactory.getLogger(PdfWriter.class); logger.error("Closing of the duplicatedStream failed.", ex); } } }
PdfWriter extends PdfOutputStream implements Serializable { @Override public void close() throws IOException { try { super.close(); } finally { try { if (duplicateStream != null) { duplicateStream.close(); } } catch (Exception ex) { Logger logger = LoggerFactory.getLogger(PdfWriter.class); logger.error("Closing of the duplicatedStream failed.", ex); } } } }
PdfWriter extends PdfOutputStream implements Serializable { @Override public void close() throws IOException { try { super.close(); } finally { try { if (duplicateStream != null) { duplicateStream.close(); } } catch (Exception ex) { Logger logger = LoggerFactory.getLogger(PdfWriter.class); logger.error("Closing of the duplicatedStream failed.", ex); } } } PdfWriter(java.io.File file);  PdfWriter(java.io.OutputStream os);  PdfWriter(java.io.OutputStream os, WriterProperties properties);  PdfWriter(String filename);  PdfWriter(String filename, WriterProperties properties); }
PdfWriter extends PdfOutputStream implements Serializable { @Override public void close() throws IOException { try { super.close(); } finally { try { if (duplicateStream != null) { duplicateStream.close(); } } catch (Exception ex) { Logger logger = LoggerFactory.getLogger(PdfWriter.class); logger.error("Closing of the duplicatedStream failed.", ex); } } } PdfWriter(java.io.File file);  PdfWriter(java.io.OutputStream os);  PdfWriter(java.io.OutputStream os, WriterProperties properties);  PdfWriter(String filename);  PdfWriter(String filename, WriterProperties properties); boolean isFullCompression(); int getCompressionLevel(); PdfWriter setCompressionLevel(int compressionLevel); PdfWriter setSmartMode(boolean smartMode); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void close(); }
PdfWriter extends PdfOutputStream implements Serializable { @Override public void close() throws IOException { try { super.close(); } finally { try { if (duplicateStream != null) { duplicateStream.close(); } } catch (Exception ex) { Logger logger = LoggerFactory.getLogger(PdfWriter.class); logger.error("Closing of the duplicatedStream failed.", ex); } } } PdfWriter(java.io.File file);  PdfWriter(java.io.OutputStream os);  PdfWriter(java.io.OutputStream os, WriterProperties properties);  PdfWriter(String filename);  PdfWriter(String filename, WriterProperties properties); boolean isFullCompression(); int getCompressionLevel(); PdfWriter setCompressionLevel(int compressionLevel); PdfWriter setSmartMode(boolean smartMode); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void close();  }