Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.0.22
-
None
Description
I prepared a simple example for PDFBOX-4709 "PDFBox prints text poorly in comparison to Adobe, Chrome, other apps" which uses a custom PDF renderer and PageDrawer to draw a text using Graphics2D.drawString(...) method to print a low DPI text with good quality.
https://github.com/AlexanderScherbatiy/pdfbox/commit/b806d44f9514a7b5fededfa49c98ad2858b93a92
The sample is prepared for tag 2.0.22. It consists of org.apache.pdfbox.examples.strprinting.StringPrinting sample which sets a custom StringPDFPageable. StringPDFPageable just a copy of PDFPageable (PDFPageable is a final class, it is not possible to override it) where getPrintable(int i) method sets a custom StringPDFRenderer to PDFPrintable.
StringPDFRenderer just returns a custom StringPageDrawer which is subclass of PageDrawer.
The aim if StringPageDrawer is an illustration how Graphics2D.drawString(...) can be used.
Only two fonts PDType0Font and PDType1Font are handled by StringPageDrawer. The code for PDFont AwtFont handling just a copy from PDFBOX 1.8.
There are a few things which PDFBOX does not provide as a public API.
The current request is to provide a way to set a custom PDF renderer to PDFPrintable.
Here is patch which illustrate how it can look like:
https://github.com/AlexanderScherbatiy/pdfbox/commit/212a78b2b65ada117c0e9ae65c3ae6054ca5fa61
The other two things are private setClip() and getNonStrokingPaint() methods from PageDrawer. The idea of the sample was to draw a text in the same way as PDFBOX renderingMode.isFill() (the same transform, clip and paint) only changing graphics.fill(glyph) to graphics.drawString(str, 0, 0).
Is it possible to make setClip() and getNonStrokingPaint() public in some way or it is necessary just to copy them as is?
Attachments
Issue Links
- is related to
-
PDFBOX-5466 Print to PDF printer results in large PDF + text content is not selectable anymore
- Closed
- relates to
-
PDFBOX-4709 PDFBox prints text poorly in comparison to Adobe, Chrome, other apps
- Reopened