pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Poupart <phil.poup...@gmail.com>
Subject Can't stamp newly created contents stream to Resources - XObjects
Date Wed, 29 Apr 2015 14:52:35 GMT
I'm wondering if anyone can point me in the right direction here. I have a
series of PDFs that have short content streams that just reference /Xf1 in
the PDF body. These were PDFs modified with iText. It is essentially a PDF
placed on a page of a PDF.

I'm extracting the nested contents stream just fine. I can modify that
contents stream, but am having difficulty stamping it back to the
Resources->XObjects dictionary.

Original content stream is a reference to /Xf1 object in pdf body.

1 0 0 1 0 0 cm /Xf1 Do Q

Below are some snippets of my code.

-----------get the nested content stream (this works)

String xDict = "Xf1" ;

Map<String,PDXObject> trimMap = resources.getXObjects();

PDXObject xObjects = trimMap.get(xDict);

PDStream nestedContentStream = xObjects.getPDStream();

  ... modify nestedContentStream ...

-----------stamp it back to resources (fails to create COSStream)

byte[] modContentBytes =

RandomAccessBuffer rab = new RandomAccessBuffer();

rab.write(modContentBytes, 0, modContentBytes.length);

COSStream cosStream  = new COSStream(rab); <------ cosStream length is 0
even though rab is 218727 bytes

PDXObject modifiedPdxObj =

trimMap.put(trimmedXDict, modifiedPdxObj);

resources.setXObjects(trimMap); <------ this blows up because my COSStream
length is 0 (I think)

Any help would be appreciated. Thanks,

Phil Poupart

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message