0

I am unable to put stamp using itext7 using Java language on only skia generated pdf (skia is pdf library used by google; if someone has worked on google docs-> Clicks on Print -> Save as Pdf ). It Stamps incorrectly; if I stamp at top left position of pdf page then it would stamp at bottom left and show (inverted mirror) image and (inverted mirror) text. For all other pdfs it gives correct stamping. It seems pdf generated by skia has missing meta -data.

Sameer
  • 1
  • 2
  • 1
    Show us your code. Not all PDF's have their origin at coordinate `( x = 0; y = 0 )`. Maybe you're not taking that into account. Also: as the stamp is inverted, it looks like some transformation is in place. – Bruno Lowagie Jul 05 '18 at 06:52
  • ... and please also share a sample document. The result of following your instructions to produce a PDF may depend on stuff like one's locale and other account settings... – mkl Jul 05 '18 at 13:04
  • The page size, the page orientation, the transformation matrix: none of that is related to metadata (not to the Info dictionary nor to the XMP metadata). Hence your comment "It seems pdf generated by skia has missing meta -data" is very odd. – Bruno Lowagie Jul 05 '18 at 13:57

1 Answers1

0

Since you didn't share any code, nor any document, I created a PDF document from Google docs, and I used the code I wrote in answer to the Itextsharp 7 - Scaled and Centered Image as watermark question to add a Watermark in the center.

The result looked like this:

enter image description here

As you can see in the Document Properties, the original document was created using Skia/PDF m67; modified using iText® 7.1.3.

You need a Watermark in the top left, so I adapted the code like this:

public void createPdf(String src, String dest) throws IOException {
    PdfDocument pdfDoc = new PdfDocument(
            new PdfReader(src), new PdfWriter(dest));
    Document document = new Document(pdfDoc);
    PdfCanvas over;
    PdfExtGState gs1 = new PdfExtGState();
    gs1.setFillOpacity(0.5f);
    int n = pdfDoc.getNumberOfPages();
    Rectangle pagesize;
    ImageData img = ImageDataFactory.create(IMG);
    float iW = img.getWidth();
    float iH = img.getHeight();
    float x, y;

    for (int i = 1; i <= n; i++)
    {
        PdfPage pdfPage = pdfDoc.getPage(i);
        pagesize = pdfPage.getPageSize();

        x = pagesize.getLeft();
        y = pagesize.getTop() - iH;

        over = new PdfCanvas(pdfDoc.getPage(i));

        over.saveState();
        over.setExtGState(gs1);

        over.addImage(img, iW, 0, 0, iH, x, y);

        over.restoreState();
    }
    document.close();
    pdfDoc.close();
}

The result looks like this:

enter image description here

The image isn't mirrored; it's at the top-left position of the page. In short: there doesn't seem to be any problem with PDF's created with Skia/PDF m67.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • I would recommend using the blend mode **Darken** instead of `FillOpacity` combined with an already brightened bitmap; that would prevent the washed out appearance of the text under the image. – mkl Jul 05 '18 at 13:58
  • I was lazy. I recycled the code from an answer I gave earlier today. – Bruno Lowagie Jul 05 '18 at 14:00
  • Ah, very environmentally sound... ;) – mkl Jul 05 '18 at 14:01