0

It's about overlapped text problem when creating new pdf file with org.apache.pdfbox from java code, problem don't know how to fix on win7 workstation:

  1. Pdf file model:

" Melléklet a szállítólevélhez: x x x

Dátum: x x x

"

  1. Creating new pdf file replacing "x x x " with java code :

"

Melléklet a szállítólevélhez: 26201738

Dátum: 2019-05 -02 14:49:00

"

Except that "26201738" is displayed overlapped (can not put imaged here) also "2019-05 -02 14:49:00". The maximum length with overlapped characters are maximum 4 respectively 8.

On 2 different workstation with win7 with the same java_update version and the same workspace eclipse with the same eclipse and same java code, it is creating the pdf file with NO overlapping text.

I have tryed with the same Fonts copied to the bad workstation-negative result. Tryed to swich "Region and language" to Germany exactly the other station-no result. Tryed to update to Acrobat Reader DC-no result. It seems that workstation OS is missing something when creating new PDF with org.apache.pdfbox and can't figure it out what is it? It is excluded the java code problem since 2 other stations is working correctly in generating new PDF file.

Best regards, Laurentiu

  • Please share the result PDF files and mention what PDFBox version you are using and include minimal code to reproduce the problem. – Tilman Hausherr May 04 '19 at 05:39
  • You say you are *replacing "x x x "* - replacing text in pdfs is fickle, in particular if done like in some (meanwhile removed) older pdfbox example. As you don't show your code, we have to assume that you use that approach and, therefore, that you have to expect such issues on a regular basis. – mkl May 04 '19 at 06:14
  • Hi, i have added the java code which need only to be placed in eclipse and run. Pdfbox is pdfbox-1.8.8.jar. Upload MainClass.java at https://drive.google.com/file/d/1A073CVXlpBE6Qaljta0EnPu7GX2UrLB3/view?usp=sharing .PDF model with "x x x " : https://drive.google.com/file/d/1F0Bnph-MDcbFTF1zsF8B3qPIguiBD7ND/view?usp=sharing.Pdf file copied to "C:/temp/".New pdf after run java code:"C:/temp/2262122998_89834500.pdf".Pdf result with overlapped text: https://drive.google.com/file/d/1HhM1hyCqNZeCeyYCU_dwexI5mP9LtAPP/view?usp=sharing.Java code run on other workstation no overlapping text.Thank you! – Laurentiu Alexandru May 06 '19 at 07:43
  • Pdfbox-1.8.8.jar can be found also at : https://drive.google.com/file/d/1C3Of3m-RfqUii4Rg4zk5oiDVARjGgw3o/view?usp=sharing . And as a dependency org-apache-commons-logging.jar: https://drive.google.com/file/d/1-oxvsTznOo3UeM0i_Sk7EBmPknp7DKme/view?usp=sharing. – Laurentiu Alexandru May 06 '19 at 07:53

2 Answers2

1

Your source PDF has zero widths for "2", "3", "7" and "9". This can be seen by looking at Root/Pages/Kids/[0]/Resources/Font/F1/Widths with PDFDebugger. Root/Pages/Kids/[0]/Resources/Font/F1/FirstChar is 32, so "0" (code 48) can be found at position 16. Whoever/Whatever created the original PDF only set the width for the characters used. That is yet another of the many pitfalls with replacing text in existing PDFs, which is why the example was removed.

Instead of using "x x x", I'd recommend to use an acroform field or to put the date / client# at a predefined position.

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
0

Problem solved! It seems the pdf model which need to replace "x x x " and create a new one from him had something wrong inside. I have replaced PDF file model with a good file and everything is working now. Thank you and best regards!