[
https://issues.apache.org/jira/browse/PDFBOX-4821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17097850#comment-17097850
]
Tilman Hausherr edited comment on PDFBOX-4821 at 5/2/20, 7:26 AM:
------------------------------------------------------------------
Oracle internal review ID : 9064856
Code that reproduces the issue:
{code:java}
package pdfbox4822clip;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.print.PrintServiceLookup;
public class PDFBox4822Clip implements Printable
{
public static void main(String[] args) throws PrinterException, IOException
{
PDFBox4822Clip main = new PDFBox4822Clip();
main.paintToImage(); // produces transparent image
main.paintToPrint(); // produces red page, but should produce
}
public PDFBox4822Clip()
{
System.out.println("Empty Area path empty? " + new
Area().getPathIterator(null).isDone());
System.out.println("Empty Rect path empty? " + new
Rectangle().getPathIterator(null).isDone());
}
public void paintToPrint() throws PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(PrintServiceLookup.lookupDefaultPrintService());
job.setPrintable(this);
if (job.printDialog()) // Choose PDF or XPS
{
job.print();
}
}
public void paintToImage() throws IOException
{
BufferedImage bim = new BufferedImage(596, 842,
BufferedImage.TYPE_INT_ARGB);
Graphics g2d = (Graphics2D) bim.getGraphics();
paint(g2d);
g2d.dispose();
ImageIO.write(bim, "png", new File("PDFBox4822Clip.png"));
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex == 0)
{
paint(graphics);
return PAGE_EXISTS;
}
return NO_SUCH_PAGE;
}
private void paint(Graphics g2d)
{
Rectangle2D r1 = new Rectangle(11, 74, 540, 750);
Rectangle2D r2 = new Rectangle(374, 22, 8, 16);
Area area = new Area(r1);
area.intersect(new Area(r2));
g2d.setClip(area); // area is empty
System.out.println("g2d: " + g2d);
System.out.println("clip empty? " +
g2d.getClip().getPathIterator(null).isDone());
System.out.println("clip bounds: " + g2d.getClip().getBounds2D());
g2d.setColor(Color.red);
g2d.fillRect(0, 0, 1000, 1000);
}
}
{code}
was (Author: tilman):
Oracle internal review ID : 9064856
> My PDF document is not printed correctly. Rendering it works.
> -------------------------------------------------------------
>
> Key: PDFBOX-4821
> URL: https://issues.apache.org/jira/browse/PDFBOX-4821
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 2.0.2, 2.0.15, 2.0.19, 2.0.20
> Environment: Windows 10, JDK 1.8.0_152, 14.0.1
> Reporter: Daniel Migowski
> Priority: Major
> Labels: print, printing
> Attachments: ArtefactWhilePrinting.png,
> DevconLetterPaperPrinter.java, DevconLetterPaperRenderer.java,
> LogoOnly_Letterpaper.pdf, PDFBOX-4821_reduced7.pdf, RenderingResult.png,
> image-2020-05-01-13-43-54-357.png
>
>
> I am printing PDF files with Apache PDFBox. The attached file shows a second
> turquise square on the top of the page (See attached file
> "ArtefactWhilePrinting.png").
> When I try to render the PDF with PDFBox the result looks nice (see attached
> file "RenderingResult.png")
> I have provided the code to render / print the letterpaper, and also the
> Input PDF ("LogoOnly_Letterpaper.pdf").
> The PDF is the output of an SVN file, exported by Inkscape, but AFAIK there
> isn't even an object at the location where the square appears in printing, so
> I cannot tell what bugs lets it appear there.
> Thanks for improving the PDF component to also handle this PDF in advance,
> you guys are great.
> -Update: I tried to give a DPI number to printing, so the pixelating is done
> within PDF Box, but there the artefact still appears. So rendering with DPI
> to Image works (also with 300 DPI images), but rendering even with DPI to
> paper leads to the strange artefact.- Not true, rendering in PDFBox doesn't
> show behaviour.
> Update 2: Checked with currently nightly, bug still appears.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]