Search code examples
pdfpdfboxdotted-line

PDFBox generate so blacked line when I zoom out


When I try to print lines using PDFBox, it creates line so blacked when I zoom out generated pdf file.

I'm creating a dashed pattern using content stream with line methods (moveTo, lineTo). For dash pattern and setting specific size I use methods (lineWidth, setLineDashPattern).

You can see code on my github repo (https://github.com/dmmax/pdfbox-dotted-pattern/blob/master/src/main/java/me/dmmax/pdfbox/dottedpattern/Main.java)

Below picture with opened two files: my result (left side) and example how it should look like (right side). Zoom of both files is 50%.

Compare my result with example Or you can check on your computer, just download two files:
1) My result: https://github.com/dmmax/pdfbox-dotted-pattern/blob/master/print.pdf
2) Example: https://github.com/dmmax/pdfbox-dotted-pattern/blob/master/informationyoushouldknow.pdf

Does anyone know how to fix blacked lines when I zoom out result pdf?


Solution

  • Thank a lot to @TilmanHausherr with his big help in this question. If you have so blacked line(-s) in zoom out of pdf then this happens because pdf render a lot of small objects but in zoom out size have the same (or close to it) size.

    For me resolve this problem is generate dot/dash pattern (with needed count of lines) in another pdf and after that I convert pdf to XObject and print on my current pdf.

    Yes it takes up more space, but there are no blackouts