[
https://issues.apache.org/jira/browse/PDFBOX-4391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16707498#comment-16707498
]
Tilman Hausherr commented on PDFBOX-4391:
-----------------------------------------
I was also thinking about disabling antialiasing for horizontal/vertical lines
(because we already disable antialiasing for rectangles) when rendering in
color. But I decided against it because
- when using this logic for all widths, then it looks weird when a line is not
antialiased but the glyphs are (test file 1822-AGB.pdf, page 4)
- when using this logic for widths > 1, the lines in your barcode end up
having different lengths
I am including the now deleted code here just for documentation
{code:java}
public void strokePath() throws IOException
{
graphics.setComposite(getGraphicsState().getStrokingJavaComposite());
graphics.setPaint(getStrokingPaint());
BasicStroke stroke = getStroke();
graphics.setStroke(stroke);
boolean noAntiAlias = stroke.getEndCap() != BasicStroke.CAP_ROUND &&
stroke.getLineWidth() > 1 &&
isHorizontalOrVerticalLine(linePath);
if (noAntiAlias)
{
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
}
setClip();
//TODO bbox of shading pattern should be used here? (see fillPath)
graphics.draw(linePath);
linePath.reset();
if (noAntiAlias)
{
// JDK 1.7 has a bug where rendering hints are reset by the above
call to
// the setRenderingHint method, so we re-set all hints, see
PDFBOX-2302
setRenderingHints();
}
}
private boolean isHorizontalOrVerticalLine(GeneralPath path)
{
PathIterator iter = path.getPathIterator(null);
double[] coords = new double[6];
int count = 0;
double[] xs = new double[2];
double[] ys = new double[2];
while (!iter.isDone())
{
switch(iter.currentSegment(coords))
{
case PathIterator.SEG_MOVETO:
if (count == 0)
{
xs[count] = coords[0];
ys[count] = coords[1];
}
else
{
return false;
}
count++;
break;
case PathIterator.SEG_LINETO:
if (count == 1)
{
xs[count] = coords[0];
ys[count] = coords[1];
}
else
{
return false;
}
count++;
break;
case PathIterator.SEG_CUBICTO:
return false;
case PathIterator.SEG_CLOSE:
break;
}
iter.next();
}
if (count == 2)
{
return xs[0] == xs[1] || ys[0] == ys[1];
}
return false;
}
{code}
> Page to image rendering in pdfbox 2.0: Poor quality compared to 1.8
> -------------------------------------------------------------------
>
> Key: PDFBOX-4391
> URL: https://issues.apache.org/jira/browse/PDFBOX-4391
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 2.0.13
> Environment: Windows 10
> JDK 1.8.0_181
> JDK 1.8.0_192
> Reporter: Olivier Masseau
> Priority: Major
> Labels: antialias, barcode, image, quality
> Fix For: 2.0.14
>
> Attachments: barcode-128-BW-antialiasing-off.png, barcode-128.pdf,
> barcode-image-1.8.16.png, barcode-image-2.0.13.png, comparison.png
>
>
> I have a process that needs to convert pages of pdf files to images to be
> able to detect barcodes.
> Since I've upgrade to pdfbox 2.0 my barcodes are not correctly detected
> anymore.
> I noticed the cause was the result of the page to image rendering implemented
> in pdfbox 2.0.
> The quality of the image is really poor compared to pdfbox 1.8.
> See the attached image (comparison.png):
> On the left you have the image generated with pdfbox 2.0.13
> On the right you have the image generated with pdfbox 1.8.16
> We can clearly see the difference.
> Both images were generated using the same resolution (200 dpi here):
> For 2.0.13:
> {code:java}
> BufferedImage image = pdfRenderer.renderImageWithDPI(0, 200,
> ImageType.BINARY);{code}
> For 1.8.16:
> {code:java}
> PDPage page = (PDPage) pdfDocument.getDocumentCatalog().getAllPages().get(0);
> BufferedImage image = page.convertToImage(BufferedImage.TYPE_BYTE_BINARY,
> 200);{code}
> Buffered images were both written to files using:
> {code:java}
> ImageIO.write(image, "png", file); {code}
> I've attached the pdf file (barcode-128.pdf) and the generated images
> (barcode-image-2.0.13.png and barcode-image.1.8.16.png)
>
>
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]