6

I am drawing an image on one of the PDF page.. when I use PDPageContentStream stream = new PDPageContentStream(doc, page); to draw image, everything works fine.. see below image.

image

but when I use constructor PDPageContentStream(doc, page, true, true); to create PDPageContentStream and draw image, the newly added image gets inverted upside down..

image

not getting what's going wrong here..

PS. I am using library PdfBox-Android

Rupesh
  • 3,415
  • 2
  • 26
  • 30

1 Answers1

12

Use the constructor that has a fifth parameter, so to reset the graphic context.

public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent, 
                            boolean compress, boolean resetContext) throws IOException

alternatively, save and restore the graphics state in the first content stream by calling

saveGraphicsState();
// ...
restoreGraphicsState();
Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
  • 3
    @rabbitguy without the fifth parameter, the graphics state may not be in the same state as the beginning. In the example above, it is likely flipped. This is like coming into a bathroom where somebody hasn't flushed after being done with business. The fifth parameter takes care to save the graphics state at the start, and restore it just for you, so you'll have a clean bathroom. – Tilman Hausherr Oct 12 '16 at 16:40
  • @ShahidGhafoor Then please create a new question, with as much information as possible and the smallest possible code to reproduce the problem. – Tilman Hausherr Mar 17 '22 at 11:11