@Test public void createEmptyDocument() throws IOException { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(destinationFolder + "emptyDocument.pdf")); pdfDoc.getDocumentInfo().setAuthor("Alexander Chingarev"). setCreator("iText 6"). setTitle("Empty iText 6 Document"); PdfPage page = pdfDoc.addNewPage(); page.flush(); pdfDoc.close(); PdfReader reader = new PdfReader(destinationFolder + "emptyDocument.pdf"); PdfDocument pdfDocument = new PdfDocument(reader); Assert.assertEquals("Rebuilt", false, reader.hasRebuiltXref()); Assert.assertNotNull(pdfDocument.getPage(1)); String date = pdfDocument.getDocumentInfo().getPdfObject().getAsString(PdfName.CreationDate).getValue(); Calendar cl = PdfDate.decode(date); double diff = DateTimeUtil.getUtcMillisFromEpoch(null) - DateTimeUtil.getUtcMillisFromEpoch(cl); String message = "Unexpected creation date. Different from now is " + (float) diff / 1000 + "s"; Assert.assertTrue(message, diff < 5000); 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();  }