3

Is there a way to place 2 instances of a bitmap in a PDF for a single image? One to display when it is viewed on the screen and another when it prints?

The problem we have is rendering a chart to a bitmap. If we do 300 dpi then axis lines, borders, etc. disappear. If we do 96 dpi, then printing it looks bad.

thanks - dave

5 Answers 5

5

You can use Optional Content to do this. Supplying the usage application dictionaries with a 'Print' event causes the content to be appropriate for printing. (Note, not all printing applications will honour this).

See The PDF Reference Manual, in my 1.7 edition section 4.10 'Optional Content' beginning on page 364.

1
  • +1; in the ISO 32000-1 specification section 8.11 deals with optional content.
    – mkl
    Feb 8, 2013 at 10:09
1

You can add an Alternate Image Dictionary (PDF Spec, section 8.9.5.4) which can specify an image to be used for printing.

0

Yes, there is a way, although I do not know it. We used it as a prank on a coworker, when printing a document, some totally other pictures appeared

0

You can also use 2 readonly textbox fields and draw the images on the field's appearance. Then for one field you set its visibility to VisibleNonPrintable and for the other HiddenButPrintable.

0

I implemented this (using iText). For anyone else who needs these here's the code. And you can download the source at my blog.

    static void Main(string[] args)
    {
        Document document = new Document(new Rectangle(0, 0, 8.5f * 72.0f, 11 * 72));
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.GetFullPath(@"..\..\test_dotnet.pdf"), FileMode.OpenOrCreate, FileAccess.ReadWrite));
        document.Open();

        document.Add(new Paragraph("Visibility test"));


        // not displayed on printer
        PdfLayer layer = new PdfLayer("screen", writer);
        layer.OnPanel = false;
        layer.SetPrint("Print", false);
        layer.View = true;

        PdfContentByte cb = writer.DirectContent;
        cb.BeginLayer(layer);

        Image img = Image.GetInstance(Path.GetFullPath(@"..\..\building_01.png"));
        img.SetAbsolutePosition(72, 72 * 7);
        cb.AddImage(img);

        cb.EndLayer();


        // not displayed on screen
        layer = new PdfLayer("print", writer);
        layer.OnPanel = false;
        layer.SetPrint("Print", true);
        layer.View = false;

        cb = writer.DirectContent;
        cb.BeginLayer(layer);

        img = Image.GetInstance(Path.GetFullPath(@"..\..\building_02.png"));
        img.SetAbsolutePosition(72, 72 * 3);
        cb.AddImage(img);

        cb.EndLayer();


        document.Close();

        Console.Out.WriteLine("all done");
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.