pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matteo Gamboz <gam...@medialab.sissa.it>
Subject Re: resize inline images
Date Fri, 22 Feb 2019 08:41:06 GMT
Hi Tilman,

> Did you understand them?
sort of...
(please be patient, I think I'm making some confusion :-)

following your suggestion, I was able to create and add another Inline
Image with the desired resolution into my pdf (I check with "pdfimages
-list" from poppler-utils):

PDImageXObject helper_img = LosslessFactory.createFromImage(document, scaledImage);
InputStream img_data_stream = helper_img.createInputStream();
byte [] img_data = IOUtils.toByteArray(img_data_stream);
PDInlineImage replacement_img = new PDInlineImage(operator.getImageParameters(),

I'm not sure about the "filters" you mentioned...
I used the same parameters as the original (operator.getImageParameters()).

Then I appended my new image to the page stream but this way I get two
inline images... (if I use Appended.OVERWRITE I end up removing all
other operators from the stream)

PDPageContentStream pageContentStream = new PDPageContentStream(document,
pageContentStream.drawImage(replacement_img, 0, 0);

I tried other approaches:
. (right after creating my replacement_img)
  take the content stream of the current page,
  parse it, get a list of tokens
  run through the list of tokens
  and build a new list
  omitting "BI" operator & co.
  create a new stream from the tokens
  and set it to the page
  (BUT: I have an error about some not-closed stream when saving)

. adapt example RemoveAllText.java
  similar to the above: run through the tokens and modify those
  related to images
  (BUT: I'm not sure how to get to the image XObject from the token)

. extend GraphicsOperatorProcessor
  (copying from operator.graphics.BeginInlineImage)
  i.e. create a StreamEngine to process my adapted "BeginInlineImage" operator
  (BUT: I get a ClassCastException on the StreamEngine I use)

I think some of the problems are because I've used java ~15 years ago
and forgot about it until now :-)

Since I think I don't really get the hang of the library,
I have a different (exploratory) proposition.

Let's say that I generally want to
"change resolution of raster images"
would you (or anyone else) be interested in writing the appropriate
code under compensation?
I think that the code could be added to the examples in the source.
At the moment I do not have any budget, but if we can come up with a
sum I could try and ask my boss...

I like this kind of approach because I would be able to:
. get what I want in the short term,
. learn the best way to do it (so that next time I can do it myself),
. contribute materially to pdfbox
. and add valuable piece of "documentation" (the example) to the library.
. (bonus) have someone else maintain that code
(I just hope my boss will feel the same :-)

If you (or anyone else) feel this proposal is inappropriate, please
let me know it and just forget about this.


On Thu, 21 Feb 2019 18:49:16 +0100,
Tilman Hausherr wrote:
> Hi, did you try the two things I mentioned on stackoverflow? (Did you
> understand them?) Did you create a PDF file with it? If yes, please
> share it, I might be able to tell what is missing.
> Tilman
> Am 21.02.2019 um 09:59 schrieb Matteo Gamboz:
> > Hi all,
> > 
> > I must resize (change the resolution) of some Inline Images in a PDF.
> > 
> > I'm a bit stuck on how best to proceed.
> > 
> > I've tried by extending PDFStreamEngine and overriding method
> > processOperator (https://stackoverflow.com/q/54744038/1581629) but
> > without good results.
> > 
> > Since I want to modify a stream (I think), I would like to ask if the
> > approach is correct or if there are better methods (e.g. extend
> > GraphicsOperatorProcessor or something...)

To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message