[
https://issues.apache.org/jira/browse/PDFBOX-4942?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17185364#comment-17185364
]
Tilman Hausherr commented on PDFBOX-4942:
-----------------------------------------
This is a terrible file: it has an incredible lot of tiny ARGB images. Instead
of just painting these dots as a dotted line, or as a pattern. The JDK calls
{{PDFPrintable.print()}} for each tiny image with an appropriate clipping path.
So that PDF is rendered several hundred times.
See also here:
https://blog.idrsolutions.com/2012/05/avoid-transparency-when-printing-in-java/
So I tried the thing I did in PDFBOX-4583 again, and also some code in
{{drawBufferedImage}} to avoid drawing if outside the clipping path (despite
that something like this is also done in the jdk itself somewhere)
{code}
Rectangle2D rect = new Rectangle2D.Float(0, 0, width, height);
Area transformedRect = new Area(imageTransform.createTransformedShape(rect));
transformedRect.intersect(new Area(graphics.getClip()));
if (transformedRect.isEmpty())
return;
{code}
But this didn't speed up anything. The problem is still that the jdk calls
PDFPrintable.print() so often.
Another thing I tried is to add this code segment to
{{PageDrawer.drawBufferedImage()}} below the {{imageTransform.translate}} line:
{code}
if (width * height < 50 && image.getType() == BufferedImage.TYPE_INT_ARGB)
{
BufferedImage rgbImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = rgbImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
image = rgbImage;
}
{code}
This will work nicely for your file and most others. But not all. So if you
want, you should add this on the source code level and build your own. But this
is too risky for general production.
> Printing PDF hangs and document is never printed
> ------------------------------------------------
>
> Key: PDFBOX-4942
> URL: https://issues.apache.org/jira/browse/PDFBOX-4942
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.21
> Reporter: Jon Ominsky
> Priority: Critical
> Labels: print, printing
> Attachments: problem.pdf
>
>
> We have an integration that simply prints PDFs. The PDF attached never prints
> and clogs up the print queue - just ends up spooling for very long periods of
> time. Code in question that is in use with the latest version of PDFBox:
> {code:java}
> PrintService service = getPrintService(printerName);
> DocPrintJob printJob = service.createPrintJob();
> PrintRequestAttributeSet attrSet = new HashPrintRequestAttributeSet();
> attrSet.add(new JobName(fileName, null));
> attrSet.add(new Copies(1));
> try (PDDocument pdf = PDDocument.load(file)) {
> PDFPageable pageable = new PDFPageable(pdf);
> Doc doc = new SimpleDoc(pageable, DocFlavor.SERVICE_FORMATTED.PAGEABLE,
> null);
> printJob.print(doc, attrSet); return new
> PdfPrintResult(pdf.getNumberOfPages());
> } catch (IOException | PrintException e) {
> throw new ControlledPrintException("Unable to print file " + fileName +
> ".", e);
> }
> {code}
> This occurs trying to print to a physical printer as well as to a PDF
> Printer, e.g., PDFCreator. I am able to open the PDF in the PDFDebugger and
> view it, but cannot determine what is causing the issue.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]