[
https://issues.apache.org/jira/browse/PDFBOX-1871?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14316720#comment-14316720
]
John Hewson edited comment on PDFBOX-1871 at 2/11/15 6:29 PM:
--------------------------------------------------------------
Here's a patch which alters the rendering of many PDF files by 1px by
performing a more accurate rounding. The insight is realising that rounding the
image buffer up causes it to have a white border:
In PDFRenderer#renderImage(), replace:
{code}
int widthPx = Math.round(widthPt * scale);
int heightPx = Math.round(heightPt * scale);
{code}
with:
{code}
int widthPx = (int)Math.floor(widthPt * scale);
int heightPx = (int)Math.floor(heightPt * scale);
{code}
Try this with EnviroNewsSummer2009.pdf from PDFBOX-1058 to see the effect.
was (Author: jahewson):
Here's a patch which alters the rendering of many PDF files by 1px by
performing a more accurate rounding. The insight is realising that rounding the
image buffer up causes it to have a white border:
In PDFRenderer#renderImage(), replace:
{code}
int widthPx = Math.round(widthPt * scale);
int heightPx = Math.round(heightPt * scale);
{code}
with:
{code}
int widthPx = (int)Math.floor(widthPt * scale);
int heightPx = (int)Math.floor(heightPt * scale);
{code}
Try this with EnviroNewsSummer2009.pdf to see the effect.
> Content appears a few px higher when rasterizing PDF
> ----------------------------------------------------
>
> Key: PDFBOX-1871
> URL: https://issues.apache.org/jira/browse/PDFBOX-1871
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 1.8.3
> Reporter: Jon Wu
> Fix For: 2.0.0
>
> Attachments: PDFBOX-1871_unc.pdf,
> test-text-alignment-textbox-PDF2IMG-300dpi.png,
> test-text-alignment-textbox-PDFBox-1.8.3-300dpi.png,
> test-text-alignment-textbox.pdf
>
>
> PDFBox seems to be off by a little bit vertically when you rasterize a PDF.
> This is in comparison to both Adobe's PDF library and many other PDF viewers
> such as Chrome's and the one in OS X.
> I've attached an example PDF where there's some text with a green rectangle
> around it. The rectangle is has about 2x as much space above it compared to
> below it, but in PDFBox's raster, the rectangle is closer to the top than is
> is to the bottom.
> This is obvious at 300 dpi but at 96 dpi it's hard to tell for sure.
> Anecdotally, I've noticed that when rendering text at about 74 dpi, PDFBox
> seems to be off by about 1px.
> I've attached both a PDFBox raster and one made with Adobe's PDF library for
> comparison.
> java -jar pdfbox-app-1.8.3.jar PDFToImage -imageType PNG -resolution 300
> -color rgba test-text-alignment-textbox.pdf
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]