PdfObject implements Serializable { public PdfObject makeIndirect(PdfDocument document, PdfIndirectReference reference) { if (document == null || indirectReference != null) { return this; } if (document.getWriter() == null) { throw new PdfException(PdfException.ThereIsNoAssociatePdfWriterForMakingIndirects); } if (reference == null) { indirectReference = document.createNextIndirectReference(); indirectReference.setRefersTo(this); } else { reference.setState(MODIFIED); indirectReference = reference; indirectReference.setRefersTo(this); } setState(FORBID_RELEASE); clearState(MUST_BE_INDIRECT); return this; }  abstract byte getType(); final void flush(); final void flush(boolean canBeInObjStm); PdfIndirectReference getIndirectReference(); boolean isIndirect(); PdfObject makeIndirect(PdfDocument document, PdfIndirectReference reference); PdfObject makeIndirect(PdfDocument document); boolean isFlushed(); boolean isModified(); @SuppressWarnings("CloneDoesntCallSuperClone") @Override PdfObject clone(); PdfObject copyTo(PdfDocument document); PdfObject copyTo(PdfDocument document, boolean allowDuplicating); PdfObject setModified(); boolean isReleaseForbidden(); void release(); boolean isNull(); boolean isBoolean(); boolean isNumber(); boolean isString(); boolean isName(); boolean isArray(); boolean isDictionary(); boolean isStream(); boolean isIndirectReference(); boolean isLiteral(); static final byte ARRAY; static final byte BOOLEAN; static final byte DICTIONARY; static final byte LITERAL; static final byte INDIRECT_REFERENCE; static final byte NAME; static final byte NULL; static final byte NUMBER; static final byte STREAM; static final byte STRING; }
@Test public void pdtIndirectReferenceLateInitializing1() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument document = new PdfDocument(new PdfWriter(baos)); document.addNewPage(); PdfDictionary catalog = document.getCatalog().getPdfObject(); PdfIndirectReference indRef = document.createNextIndirectReference(); catalog.put(new PdfName("Smth"), indRef); PdfDictionary dictionary = new PdfDictionary(); dictionary.put(new PdfName("A"), new PdfString("a")); dictionary.makeIndirect(document, indRef); document.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); document = new PdfDocument(new PdfReader(bais)); PdfObject object = document.getCatalog().getPdfObject().get(new PdfName("Smth")); Assert.assertTrue(object instanceof PdfDictionary); dictionary = (PdfDictionary) object; PdfString a = (PdfString) dictionary.get(new PdfName("A")); Assert.assertTrue(a.getValue().equals("a")); document.close(); }
@Test @LogMessages(messages = { @LogMessage(messageTemplate = LogMessageConstant.FLUSHED_OBJECT_CONTAINS_REFERENCE_WHICH_NOT_REFER_TO_ANY_OBJECT), @LogMessage(messageTemplate = LogMessageConstant.INDIRECT_REFERENCE_USED_IN_FLUSHED_OBJECT_MADE_FREE), @LogMessage(messageTemplate = LogMessageConstant.XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT) }) public void pdtIndirectReferenceLateInitializing2() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument document = new PdfDocument(new PdfWriter(baos)); document.addNewPage(); PdfDictionary catalog = document.getCatalog().getPdfObject(); PdfIndirectReference indRef1 = document.createNextIndirectReference(); PdfIndirectReference indRef2 = document.createNextIndirectReference(); catalog.put(new PdfName("Smth1"), indRef1); catalog.put(new PdfName("Smth2"), indRef2); PdfArray array = new PdfArray(); array.add(new PdfString("array string")); array.makeIndirect(document, indRef2); document.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); document = new PdfDocument(new PdfReader(bais)); PdfDictionary catalogDict = document.getCatalog().getPdfObject(); PdfObject object1 = catalogDict.get(new PdfName("Smth1")); PdfObject object2 = catalogDict.get(new PdfName("Smth2")); Assert.assertTrue(object1 instanceof PdfNull); Assert.assertTrue(object2 instanceof PdfArray); }