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.
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: