You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Alberto Malvido <ma...@gmail.com> on 2021/06/10 21:38:17 UTC

Inserted image gets hidden by the existing content

Hi everyone,

I am editing existing PDFs created by unknown third applications. The
edition consists in inserting one image in all of the pages and it works
perfect for all the PDF documents but one. For this PDF, the image gets
under the existing content and it cannot be seen.

I would like to know the reason why this happens, and to find out a way to
insert the image always above the existing content.

For privacy reasons I cannot share the problematic PDF and I don't know how
to create a similar one.

The code for inserting the image in one of the pages is:

// Get the contentStream in append mode
   PDPageContentStream contentStream = new PDPageContentStream(
                        document,
                        document.getPage(numPage),
                        PDPageContentStream.AppendMode.APPEND,
                        true,
                        true))

// Create the PDImageXObject
PDImageXObject pdimage = JPEGFactory.createFromImage(document, buffImg,
0.9f, IMAGE_RESOLUTION);

// Draw the image
contentStream.drawImage(
        pdimage,
        Math.max((int) 0, imgCoordinates.getCoordinates().x),
        Math.max((int) 0, imgCoordinates.getCoordinates().y),
        (float) imgSize.getFinalWidth(),
        (float) imgSize.getFinalHeight());

// Close the contentStream
contentStream.close();

Thank you so much

Re: Inserted image gets hidden by the existing content

Posted by Alberto Malvido <ma...@gmail.com>.
Hi Tilman,

Thank you for your reply.

It seemed to be under the content because we can select a rectangle with
Adobe, just touching the piece of the inserted image that was visible.
However, reviewing the document and the whole inserting process, we
realized that the problem was that the BoundingBox and the CropBox
contained negative coordinates, so we solved the issue by translating the
image insertion coordinates accordingly.


El vie, 11 jun 2021 a las 5:17, Tilman Hausherr (<TH...@t-online.de>)
escribió:

> How do you know that the image is "under" the content if it can't be seen?
>
> Tilman
>
> Am 10.06.2021 um 23:38 schrieb Alberto Malvido:
> > Hi everyone,
> >
> > I am editing existing PDFs created by unknown third applications. The
> > edition consists in inserting one image in all of the pages and it works
> > perfect for all the PDF documents but one. For this PDF, the image gets
> > under the existing content and it cannot be seen.
> >
> > I would like to know the reason why this happens, and to find out a way
> to
> > insert the image always above the existing content.
> >
> > For privacy reasons I cannot share the problematic PDF and I don't know
> how
> > to create a similar one.
> >
> > The code for inserting the image in one of the pages is:
> >
> > // Get the contentStream in append mode
> >     PDPageContentStream contentStream = new PDPageContentStream(
> >                          document,
> >                          document.getPage(numPage),
> >                          PDPageContentStream.AppendMode.APPEND,
> >                          true,
> >                          true))
> >
> > // Create the PDImageXObject
> > PDImageXObject pdimage = JPEGFactory.createFromImage(document, buffImg,
> > 0.9f, IMAGE_RESOLUTION);
> >
> > // Draw the image
> > contentStream.drawImage(
> >          pdimage,
> >          Math.max((int) 0, imgCoordinates.getCoordinates().x),
> >          Math.max((int) 0, imgCoordinates.getCoordinates().y),
> >          (float) imgSize.getFinalWidth(),
> >          (float) imgSize.getFinalHeight());
> >
> > // Close the contentStream
> > contentStream.close();
> >
> > Thank you so much
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: Inserted image gets hidden by the existing content

Posted by Tilman Hausherr <TH...@t-online.de>.
How do you know that the image is "under" the content if it can't be seen?

Tilman

Am 10.06.2021 um 23:38 schrieb Alberto Malvido:
> Hi everyone,
>
> I am editing existing PDFs created by unknown third applications. The
> edition consists in inserting one image in all of the pages and it works
> perfect for all the PDF documents but one. For this PDF, the image gets
> under the existing content and it cannot be seen.
>
> I would like to know the reason why this happens, and to find out a way to
> insert the image always above the existing content.
>
> For privacy reasons I cannot share the problematic PDF and I don't know how
> to create a similar one.
>
> The code for inserting the image in one of the pages is:
>
> // Get the contentStream in append mode
>     PDPageContentStream contentStream = new PDPageContentStream(
>                          document,
>                          document.getPage(numPage),
>                          PDPageContentStream.AppendMode.APPEND,
>                          true,
>                          true))
>
> // Create the PDImageXObject
> PDImageXObject pdimage = JPEGFactory.createFromImage(document, buffImg,
> 0.9f, IMAGE_RESOLUTION);
>
> // Draw the image
> contentStream.drawImage(
>          pdimage,
>          Math.max((int) 0, imgCoordinates.getCoordinates().x),
>          Math.max((int) 0, imgCoordinates.getCoordinates().y),
>          (float) imgSize.getFinalWidth(),
>          (float) imgSize.getFinalHeight());
>
> // Close the contentStream
> contentStream.close();
>
> Thank you so much
>


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