-
Bug
-
Resolution: Unresolved
-
P4
-
8, 11, 17, 20, 21
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Microsoft Windows [Version 10.0.19045.2965]
openjdk version "20.0.1" 2023-04-18
OpenJDK Runtime Environment Corretto-20.0.1.9.1 (build 20.0.1+9-FR)
OpenJDK 64-Bit Server VM Corretto-20.0.1.9.1 (build 20.0.1+9-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
A rotated code 128 barcode is changed when printing, thick stripes appear where there are none. This happens also on jdk8. It seems to be limited to Windows and Ubuntu, and doesn't happen on a Mac.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code, and choose "print to PDF" or "Print to XPS".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect the same barcode
ACTUAL -
Barcode is different, there are some thick stripes. It doesn't look like the same barcode at all. (Btw this is a code 128 barcode, so there are more than 2 thicknesses)
---------- BEGIN SOURCE ----------
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
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.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.print.PrintServiceLookup;
public class PDFBox5601BadPrint implements Printable
{
public static void main(String[] args) throws PrinterException
{
new PDFBox5601BadPrint().doStuff();
}
PDFBox5601BadPrint()
{
}
void doStuff() throws PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(PrintServiceLookup.lookupDefaultPrintService());
job.setPrintable(this);
if (job.printDialog())
{
job.print();
}
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int index)
{
if (index == 0)
{
Graphics2D g2d = (Graphics2D) graphics;
try
{
BufferedImage bim = ImageIO.read(new URL("PDFBOX-5601-original-barcode.png").openStream());
g2d.drawImage(bim, AffineTransform.getScaleInstance(2, 2), null);
g2d.transform(new AffineTransform(1, 0, 0, -1, 0, 100));
g2d.scale(0.01, 0.001);
AffineTransform at = new AffineTransform(0,-1410,277.5,0,221.25,3036.25);
g2d.drawImage(bim, at, null);
}
catch (IOException ex)
{
ex.printStackTrace();
System.exit(-1);
}
return Printable.PAGE_EXISTS;
}
return Printable.NO_SUCH_PAGE;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
convert the image to a 4 byte ARGB by adding this after the ImageIO.read() line:
BufferedImage bim2 = new BufferedImage(bim.getWidth(), bim.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = bim2.getGraphics();
g.drawImage(bim, 0, 0, null);
g.dispose();
bim = bim2;
FREQUENCY : always
Microsoft Windows [Version 10.0.19045.2965]
openjdk version "20.0.1" 2023-04-18
OpenJDK Runtime Environment Corretto-20.0.1.9.1 (build 20.0.1+9-FR)
OpenJDK 64-Bit Server VM Corretto-20.0.1.9.1 (build 20.0.1+9-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
A rotated code 128 barcode is changed when printing, thick stripes appear where there are none. This happens also on jdk8. It seems to be limited to Windows and Ubuntu, and doesn't happen on a Mac.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code, and choose "print to PDF" or "Print to XPS".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect the same barcode
ACTUAL -
Barcode is different, there are some thick stripes. It doesn't look like the same barcode at all. (Btw this is a code 128 barcode, so there are more than 2 thicknesses)
---------- BEGIN SOURCE ----------
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
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.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.print.PrintServiceLookup;
public class PDFBox5601BadPrint implements Printable
{
public static void main(String[] args) throws PrinterException
{
new PDFBox5601BadPrint().doStuff();
}
PDFBox5601BadPrint()
{
}
void doStuff() throws PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(PrintServiceLookup.lookupDefaultPrintService());
job.setPrintable(this);
if (job.printDialog())
{
job.print();
}
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int index)
{
if (index == 0)
{
Graphics2D g2d = (Graphics2D) graphics;
try
{
BufferedImage bim = ImageIO.read(new URL("PDFBOX-5601-original-barcode.png").openStream());
g2d.drawImage(bim, AffineTransform.getScaleInstance(2, 2), null);
g2d.transform(new AffineTransform(1, 0, 0, -1, 0, 100));
g2d.scale(0.01, 0.001);
AffineTransform at = new AffineTransform(0,-1410,277.5,0,221.25,3036.25);
g2d.drawImage(bim, at, null);
}
catch (IOException ex)
{
ex.printStackTrace();
System.exit(-1);
}
return Printable.PAGE_EXISTS;
}
return Printable.NO_SUCH_PAGE;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
convert the image to a 4 byte ARGB by adding this after the ImageIO.read() line:
BufferedImage bim2 = new BufferedImage(bim.getWidth(), bim.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = bim2.getGraphics();
g.drawImage(bim, 0, 0, null);
g.dispose();
bim = bim2;
FREQUENCY : always
- relates to
-
JDK-8191800 Rotated BufferedImage rendered blank only when printing
-
- Open
-