@Test public void copyObject3() throws IOException { { PdfDocument pdfDoc1 = new PdfDocument(new PdfWriter(destinationFolder + "copyObject3_1.pdf")); PdfPage page1 = pdfDoc1.addNewPage(); page1.flush(); PdfDictionary catalog1 = pdfDoc1.getCatalog().getPdfObject(); PdfArray arr1 = (PdfArray) new PdfArray().makeIndirect(pdfDoc1); PdfArray arr2 = (PdfArray) new PdfArray().makeIndirect(pdfDoc1); arr1.add(arr2); PdfDictionary dic1 = (PdfDictionary) new PdfDictionary().makeIndirect(pdfDoc1); arr2.add(dic1); PdfDictionary dic2 = (PdfDictionary) new PdfDictionary().makeIndirect(pdfDoc1); dic1.put(new PdfName("dic2"), dic2); PdfName arr1Name = new PdfName("arr1"); dic2.put(arr1Name, arr1); catalog1.put(arr1Name, arr1); pdfDoc1.close(); PdfDocument pdfDoc1R = new PdfDocument(new PdfReader(destinationFolder + "copyObject3_1.pdf")); arr1 = (PdfArray) pdfDoc1R.getCatalog().getPdfObject().get(arr1Name); PdfDocument pdfDoc2 = new PdfDocument(new PdfWriter(destinationFolder + "copyObject3_2.pdf")); PdfPage page2 = pdfDoc2.addNewPage(); page2.flush(); PdfDictionary catalog2 = pdfDoc2.getCatalog().getPdfObject(); catalog2.put(arr1Name, arr1.copyTo(pdfDoc2)); pdfDoc1R.close(); pdfDoc2.close(); } { PdfReader reader = new PdfReader(destinationFolder + "copyObject3_2.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); Assert.assertEquals("Rebuilt", false, reader.hasRebuiltXref()); PdfDictionary catalog = pdfDocument.getCatalog().getPdfObject(); PdfArray arr1 = catalog.getAsArray(new PdfName("arr1")); PdfArray arr2 = arr1.getAsArray(0); PdfDictionary dic1 = arr2.getAsDictionary(0); PdfDictionary dic2 = dic1.getAsDictionary(new PdfName("dic2")); Assert.assertEquals(arr1, dic2.getAsArray(new PdfName("arr1"))); 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();  }