[ 
https://issues.apache.org/jira/browse/PDFBOX-4010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253826#comment-16253826
 ] 

Tilman Hausherr commented on PDFBOX-4010:
-----------------------------------------

I've submitted a bug report to oracle, and this is the code that reproduces the 
bug:
{code}
import java.awt.Color;
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.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 * @author Tilman Hausherr
 */
public class PDFBox4010 implements Printable
{
    public static void main(String[] args) throws IOException, PrinterException
    {
        new PDFBox4010().doStuff();
    }

    /**
     * Does the same graphics operations on the graphics device of an image and 
of a printer.
     * Both should have the same output but only the image is OK, i.e. shows a 
barcode-line
     * image within a border. The printer output only shows the border.
     * 
     * @throws IOException
     * @throws PrinterException 
     */
    void doStuff() throws IOException, PrinterException
    {
        PrinterJob job = PrinterJob.getPrinterJob();
        int width = (int) job.defaultPage().getWidth();
        int height = (int) job.defaultPage().getHeight();

        BufferedImage targetImage = new BufferedImage(width, height, 
BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) targetImage.getGraphics();

        renderStuff(g, targetImage.getWidth(), targetImage.getHeight());

        g.dispose();

        ImageIO.write(targetImage, "png", new File("output.png"));

        job.setPrintable(this);
        if (job.printDialog())
        {
            // this will call renderStuff() again
            job.print();
        }
    }

    /**
     * Draws a rotated one-line image into a graphics device.
     * @param g
     * @param width
     * @param height 
     */
    public void renderStuff(Graphics2D g, int width, int height)
    {
        // background
        g.setBackground(Color.white);
        g.clearRect(0, 0, width, height);

        BufferedImage img = new BufferedImage(303, 1, 
BufferedImage.TYPE_BYTE_BINARY);

        // barcode-like pattern on single pixel line
        for (int i = 0; i < img.getWidth(); ++i)
        {
            img.setRGB(i, 0, (i / 2 % 3) == 0 ? 0 : 0xFFFFFF);
        }

        AffineTransform at = new AffineTransform(0, -0.36, -63, 0, 163, 300);

        // draw our "barcode"
        g.drawImage(img, at, null);

        // draw rectangle around "barcode"
        g.setColor(Color.red);
        g.drawRect(100, 191, 63, 109);
    }

    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) 
throws PrinterException
    {
        if (pageIndex != 0)
        {
            return NO_SUCH_PAGE;
        }
        renderStuff((Graphics2D) graphics, (int) pageFormat.getWidth(), (int) 
pageFormat.getHeight());
        return PAGE_EXISTS;
    }
}
{code}
nternal review ID : 9051585.

> A (rotated) barcode is missing from a pdf when printed
> ------------------------------------------------------
>
>                 Key: PDFBOX-4010
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4010
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.4, 2.0.8
>         Environment: windows 7 tested with Zebra GK420d Printer / HP Laserjet 
> MFP  M277n 
>            Reporter: Stephen Threlfall-Rogers
>              Labels: print, printing
>         Attachments: PARCELFORCE_FTN0000892136.PDF, 
> PDFBOX-4010-noprint-reduced.pdf, label via adobe.jpg, label via pdfbox.jpg
>
>
> A label provided to us as a PDF is failing to print properly when printed by 
> a java program using pdfbox 2.0.4 - I upgraded to 2.0.8 same issue - I have 
> also tried using the command line utility to test to check that it wasn;t 
> something that I had coded incorrectly.. 
> The attached image with missing barcode is from the output of {{*java -jar 
> pdfbox-app-2.0.8.jar PrintPDF c:\tmp\PARCELFORCE_FTN0000892136.PDF*}}. 
> The image with the barcode OK is from acrobat reader. The PDF is as sent to 
> us.
> The original PDF is also attached/
> Any suggestions / fixes quite welcome :)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to