[ 
https://issues.apache.org/jira/browse/PDFBOX-2450?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14186502#comment-14186502
 ] 

John Hewson commented on PDFBOX-2450:
-------------------------------------

This really looks like a problem with your printer driver, ultimately the 
driver's Graphics2D is responsible for what 
{{RenderingHints.VALUE_ANTIALIAS_ON}} does.

If you're relying on Java's non-anti-aliased rendering to get the barcodes 
right then you're potentially in trouble, as there's no guarantee that the 
pixels will come out where they are needed (i.e. per-pixel accuracy is lost). 
Ultimately if the width of the thinnest lines in the barcode is smaller than 
the DPI of the printer then you will end up with barcodes that can never be 
printed correctly, even with anti-aliasing set to off.

PDFBox isn't able to offer pixel-level accuracy, due to differences between the 
PDF and Java 2D scan line algorithms, if you're generating the PDFs yourself 
then I'd recommend embedding the barcodes as images.

> RenderingHints of PageDrawer should be customizable
> ---------------------------------------------------
>
>                 Key: PDFBOX-2450
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2450
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Rendering
>    Affects Versions: 2.0.0
>            Reporter: Pei-Tang Huang
>            Priority: Minor
>              Labels: PageDrawer, RenderingHints,
>         Attachments: 300dpi_aa_8x.png, 300dpi_noaa_8x.png, 
> dot_matrix_output.jpg, test.pdf
>
>
> RenderingHints defaults are hard-coded in 
> [PageDrawer|https://github.com/apache/pdfbox/blob/54037862e4c55ab45eb8aecc44b79afbfbcd8dd9/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java#L143-L151]
>  now.
> However, the defaults are not always valid for every situation. For example, 
> I have a PDF file containing barcodes, which will be printed out using a low 
> resolution dot matrix printer. The {{RenderingHints.VALUE_ANTIALIAS_ON}}  
> default confuses all of our barcode reader!
> A dirty workaround I had is to extend {{PDFPrinter}}, use reflection to set 
> the {{protected}} but {{final}} {{super.renderer}} field with following 
> extension:
> {code:java}
> @Override
> public void renderPageToGraphics(int pageIndex, Graphics2D graphics, float 
> scale) throws IOException {
>     // proxy graphics, applying hints immediately, suppress all subsequent 
> setRenderingHint request
>     Graphics2D hintsAppliedGraphics = new HintsAppliedGraphics2D(graphics, 
> hints);
>     super.renderPageToGraphics(pageIndex, hintsAppliedGraphics, scale);
> }
> {code}
> It will be nice if there exist a more elegant way to specify {{RenderHint}} s.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to