0

I write my letters in one program and export them in PDFs. I recently implemented a small console program, which should iterate over each page and set my special design for letters (containing my address and so on) as the background.

The problem is, that the text of my letters is written in Calibri. Before using the pdf stamper the original PDF looks great and after setting the background, the style of the (not modified text) looks just a little bit different.

See in the screenshot, what I mean.

Screenshot

I can't explain that to me, and therefore I think this could be a bug. Do you have any suggestions?

My code is here.

public static void main(String[] args) throws IOException, DocumentException {
    PdfBackgroundSetter.setBackgroundToPdf(args[0], args[1], args[2]);
}

public static void setBackgroundToPdf(String inputContentPdfPath, String outputPdfPath, String inputBackgroundPdfPath) throws IOException, DocumentException {
    PdfReader inputContentReader = new PdfReader(inputContentPdfPath);
    PdfStamper outputStamper = new PdfStamper(inputContentReader, new FileOutputStream(outputPdfPath));

    PdfReader inputBackgroundReader = new PdfReader(inputBackgroundPdfPath);
    PdfImportedPage backgroundPage = outputStamper.getImportedPage(inputBackgroundReader, 1);

    int numberOfPages = inputContentReader.getNumberOfPages();

    for (int i = 1; i <= numberOfPages; i++) {
        outputStamper.getUnderContent(i).addTemplate(backgroundPage, 0, 0);
    }
    outputStamper.close();
    inputContentReader.close();
    inputBackgroundReader.close();
}

The slightly modified (anonymized) PDF-files can be found here:

content.pdf

background.pdf

  • Can you provide the PDFs in question? – mkl Jul 13 '14 at 12:15
  • I can, yes, could you tell me, where I could upload them? – Chris Becker Jul 13 '14 at 12:42
  • You could share it using a publicly shared file on Google drive, Dropbox, or the file share of your choice. – mkl Jul 13 '14 at 14:07
  • I have added the requested files in my question. – Chris Becker Jul 14 '14 at 10:28
  • With your samples I too can see the difference in Adobe Acrobat when zoomed out however not when I zoom in or print. I think you're just seeing an artifact of Adobe trying to anti-alias fonts on screen. For one reason or another your background PDF is just kicking this option. – Chris Haas Jul 14 '14 at 13:48
  • Thank you very much for checking with my pdfs. background.pdf is created and exported with Adobe Illustrator CS6 so I don't think that there's something wrong with my background.pdf. But when you look at my screenshot, then you see, that there is a slight difference between the two PDFs, when you zoom in. You should open the image-URL directly, because stackoverflow scales it down a little, so that it fits in the window. When you open http://i.stack.imgur.com/dddwS.png you will see at the bottom a zoomed-in screenshot, where you can see, that there is really a difference between both pdfs. – Chris Becker Jul 14 '14 at 14:24

1 Answers1

0

As @Chris already said, this essentially is an artifact introduced by Adobe Reader / Acrobat. It especially depends on the Adobe Acrobat/Reader version in question and can be prevented by not using transparency groups in the background PDF.

Details

I could reproduce the problem only for certain Adobe software versions, Acrobat 9.5, not for the current, though, I cannot see the problem in Adobe Reader XI.

The plain content and the content merged with background in Acrobat 9.5:

Content in Acrobat 9.5Content with background in Acrobat 9.5

The plain content and the content merged with background in Reader XI:

Content in Reader XIContent with background in Reader XI

The artifact seems to be connected with the fact that transparency groups are used in the background file. Having removed all transparency groups in the background file I get this:

The plain content and the content merged with background without transparency groups in Acrobat 9.5:

Content in Acrobat 9.5Content with background without transparency groups in Acrobat 9.5

There actually have been numerous improvements in the handling of transparency groups in the recent versions of Adobe Acrobat and Reader. I've been mostly aware of such improvements related to actual transparency matters and knockout groups, but this seems to be another one.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • First, I thank you too, that you spend your time to reproduce my problem. Could you maybe explain me, how to remove the transparency groups out of the background.pdf? I'm a coder and not tooooo familiar with Adobe programs like Illustrator, so this would help me a lot. – Chris Becker Jul 16 '14 at 13:59
  • Actually i did it the hard way, using a hex editor, overwriting the **Group** entries of page and xobject dictionaries with spaces. – mkl Jul 16 '14 at 16:04