Can the same PDF print differently than on screen?

For example, you send a PDF document containing an invoice to the client, you want them to display their logo in color on the screen, but when printing you want your logo to be printed in black and white for printing, is this possible? Thanks.

+4
source share
3 answers

There are several ways to do this.

  • Only โ€œPrint Onlyโ€ or โ€œScreen Onlyโ€ can be set in the form fields. "Only icons" Key fields can have any appearance. Acrobat's user interface allows you to import any PDF page, and APIs that allow you to create fields will usually let you draw on your own.

  • Optional content groups (aka layers). OCG can have separate ON and OFF states for screen and printing. OCG is a relatively advanced feature supported only by more mature APIs.

I am a fan (and contributor) of iText, a Java library that is quite capable of both methods. It would be easier to create a button for icons only.

PushbuttonField iconButton = new PushbuttonField(myPdfWriter, rectangle, fieldName); iconButton.setLayout(PushbuttonField.LAYOUT_ICON_ONLY); iconButton.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS); iconButton.setVisibility(BaseField.HIDDEN_BUT_PRINTABLE); PdfImportedPage iconAppearance = myPdfWriter.getImportedPage(pdfReader, pageNum); iconButton.setTemplate(iconAppearance); myPdfWriter.addAnnotation(iconButton.getField()); 

This assumes that you know the rectangle that will be used to create the PDF, and have a PDF page with a black and white logo.

NOTE. iText is licensed under AGPL, which requires that anyone with access to the OUTPUT program also have access to the source. AKA: Commercially hostile. Or you can buy a commercial license. Previous versions were available in MPL or LGPL, but are no longer supported, stored in such places. Even then, the answer is increasingly "getting a newer version."

+3
source

You can use layers to set certain things when printing and others when viewing.

0
source

Yes, the PDF specification allows you to create such PDF files. But you should also use a tool that allows you to use this feature in the PDF specification.

0
source

Source: https://habr.com/ru/post/1346363/


All Articles