PdfXrefTable implements Serializable { public PdfIndirectReference get(int index) { if (index > count) { return null; } return xref[index]; } PdfXrefTable();  PdfXrefTable(int capacity); PdfIndirectReference add(PdfIndirectReference reference); int size(); int getCountOfIndirectObjects(); PdfIndirectReference get(int index);  }
@Test public void testCreateAndUpdateXMP() throws IOException { String created = destinationFolder + "testCreateAndUpdateXMP_create.pdf"; String updated = destinationFolder + "testCreateAndUpdateXMP_update.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(created)); pdfDocument.addNewPage(); pdfDocument.getXmpMetadata(true); pdfDocument.close(); pdfDocument = new PdfDocument(new PdfReader(created), new PdfWriter(updated)); PdfXrefTable xref = pdfDocument.getXref(); PdfDictionary catalog = pdfDocument.getCatalog().getPdfObject(); ((PdfIndirectReference)catalog.remove(PdfName.Metadata)).setFree(); PdfIndirectReference ref0 = xref.get(0); PdfIndirectReference freeRef = xref.get(6); pdfDocument.close(); Assert.assertTrue(freeRef.isFree()); Assert.assertEquals(ref0.offsetOrIndex, freeRef.objNr); Assert.assertEquals(1, freeRef.genNr); }
@Test public void testCreateAndUpdateTwiceXMP() throws IOException { String created = destinationFolder + "testCreateAndUpdateTwiceXMP_create.pdf"; String updated = destinationFolder + "testCreateAndUpdateTwiceXMP_update.pdf"; String updatedAgain = destinationFolder + "testCreateAndUpdateTwiceXMP_updatedAgain.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(created)); pdfDocument.addNewPage(); pdfDocument.getXmpMetadata(true); pdfDocument.close(); pdfDocument = new PdfDocument(new PdfReader(created), new PdfWriter(updated)); PdfDictionary catalog = pdfDocument.getCatalog().getPdfObject(); ((PdfIndirectReference)catalog.remove(PdfName.Metadata)).setFree(); pdfDocument.close(); pdfDocument = new PdfDocument(new PdfReader(updated), new PdfWriter(updatedAgain)); catalog = pdfDocument.getCatalog().getPdfObject(); ((PdfIndirectReference)catalog.remove(PdfName.Metadata)).setFree(); PdfXrefTable xref = pdfDocument.getXref(); PdfIndirectReference ref0 = xref.get(0); PdfIndirectReference freeRef1 = xref.get(6); PdfIndirectReference freeRef2 = xref.get(7); pdfDocument.close(); Assert.assertTrue(freeRef1.isFree()); Assert.assertEquals(ref0.offsetOrIndex, freeRef1.objNr); Assert.assertEquals(1, freeRef1.genNr); Assert.assertTrue(freeRef2.isFree()); Assert.assertEquals(freeRef1.offsetOrIndex, freeRef2.objNr); Assert.assertEquals(1, freeRef2.genNr); pdfDocument.close(); }