I am using GhostScript to render PDF files to PNG images. However, I have discovered that some PDF's have form fields that contain data (in this case todays date) that I would not like to be present in the output image. Is it possible to disable rendering of field values in GhostScript?
I believe that by default Ghostscript won't render PDF form fields, see:
http://ghostscript.com/doc/current/Use.htm#PDF_switches
-dShowAcroForm
Show annotations referred from the Interactive Form Dictionary (AcroForm dictionary).
By default, AcroForm is not enumerated because Adobe Acrobat doesn't do this. This
option may be useful for debugging or recovery of incorrect PDF files that don't
associate all annotations with the page objects.
You may want to set the switch -dShowAcroForm=false to be sure.
If you're referring to annotations (which are shown by default), you may wish to also set the switch -dShowAnnots=false.
Related
I have several .pdf containing reoccuring transparent objects (text).
(It has non transparant objects (text and vectors) as well as images)
Not watermarks made by Acrobat or others. It is in the background as styling.
To removing them manualy these is impossible, since the content on the pdf pages is mixed with the text on the page (grouping).
Is there a way to alter the opacity of translucent objects to 0. Or even removing them completely from the pdf, with ghostscript?
Using adobe acrobat pre-flight, and moving them as images, removes all of the images in the pdf, instead of only the transparent objects.
How can this be achieved with the help of Ghostscript and the
appropriate PostScript code?
These Awnsers
https://stackoverflow.com/a/29657475/9921462
https://stackoverflow.com/a/37858893/9921462
Where helpful, to know how to get objects and images, but not filtering specifically for transparent objects.
Any ideas are appreciated as well.
I suspect that the reason you can't remove the objects using Acrobat is not because they are transparent. Its much more likely that they are described by a Form XObject. Those can't normally be edited by Acrobat.
You can use -dNOTRANSPARENCY and the pdfwrite device to produce a new PDF file with no transparency, but that will eliminate all the transparency in the output file.
Fundamentally there's no real way to do what you want, other than by manually editing the PDF file in an editor. You should go back to the original document and do the work there. PDF is not intended as an editable format.
We need to print a pdf document on the page which has predefined fields on it, a formular basically, which fields needs to be filled.
We are using iTextSharp to create pdfs and we use absoulte positioning for elements based on the formular fields positioning. For instance, if the field starts 20mm from left and 20 mm from top I will put data to start at 21mm from the left and 21 mm from top so it fits inside that field. And it works well on my printer.
But my question is, can different printers mess up positioning because of different margins, font sizes, etc... Maybe it will be the same, I am not aware of what differences can different printers bring.
Is it important that user chooses Actual size option when printing pdf?
I need to know what difficulties I can expect, better to know it now then waiting customers calling when this is in production.
The problem you anticipate, exist. It can be avoided by setting a viewer preference.
See How to prevent the resizing of pages in PDF?
You have to set the print scaling to none:
writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
That's the line you'll need if you are using iText 5 (writer is an instance of PdfWriter). If you are using iText 7, you can define the viewer preferences like this:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
PdfViewerPreferences preferences = new PdfViewerPreferences();
preferences.setPrintScaling(PdfViewerPreferencesConstants.NONE);
pdf.getCatalog().setViewerPreferences(preferences);
See Handling events; setting viewer preferences and printer properties.
Of course, end users can always overrule the print scaling in their PDF viewer, but that's their responsibility, not yours.
Here is what I need to do:
Merge several PDF documents (which may or may not be PDFA) into one PDFA1b.
Add a watermark (a simple text label) on each page of the resulting PDF.
It has to be with iText 5
I have looked at this official merging example: http://developers.itextpdf.com/examples/merging-pdf-documents/adding-cover-page-existing-pdf
But can this method be used to create a PDFA, and also add watermarks?
Or am I stuck with using this other method which he specifically says not to use: http://developers.itextpdf.com/examples/merging-pdf-documents-itext5/how-not-merge-documents
You can create files that conform to PDF/A-1b with just about any PDF library including iText. PDF/A, in general, is a subset of ISO 32000 (PDF) so it's really just a matter of using the tool to do what you need to with the files but not adding anything that is forbidden by PDF/A-1b (in your case).
The thing to be aware of is that iText or any of the other libraries that "support" PDF/A, will not prevent you from modifying PDF in a way that is forbidden by PDF/A... you just need to know what those things are.
So... before merging, you'll want to be sure that the input files don't have any annotations or form fields or any other interactive content.
After merging, add your watermark as page content and be sure your XMP metadata is conforming and you should be OK.
I want to fill out a dual AcroForm/XFA PDF form automatically. I included an XFA dataset packet and all values showed up in Adobe Reader. I set the V= key in AcroForms entries to the new value and all values showed up alternative PDF readers.
However, when I open the PDF with XFA and AcroForm V= entries in Adobe Reader, only the value of the text field that is currently selected is visible:
I cannot find any mention in the PDF specification of a special flag to set when AcroForms and XFA are present. I hypothesized that the order of the XFA and Field keys may be important, but that's not it either.
How can I change my PDF file so that the values are visible in Adobe Reader on startup, and in PDF readers which only support AcroForms and not XFA?
There are 2 questions to be answered:
Why is Adobe Reader only displaying the field value when the field is selected?
How to determine if the AcroForm or the XFA is used?
1. Displayed field values
In some cases Adobe Reader/Acrobat will display a form field differently depending on whether it's selected or not. This is typical for a field that has a defined appearance that is different from how Reader/Acrobat would render the field based on its value (and possibly some appearance settings).
When the field is not selected, the defined appearance will be shown. When the field is selected, a preview of how Reader/Acrobat would render it is shown.
Some background:
A form field consists of a logical part (field name, field value, ...), called the field dictionary, and a visualization part, called the widget annotation. The widget annotation can optionally contain an AP entry, containing the appearance streams that define its visualization. Cf. PDF Specification, 1.7, Table 8.15:
AP - dictionary - An appearance dictionary specifying how the annotation is presented visually on the page.
In the sample PDF there are no AP entries, i.e. blank visualizations. This is what's displayed for all the fields. When selecting a field, you see Reader/Acrobat's preview, based on the field value.
You can verify this by changing a field value manually with Reader/Acrobat. In that case, a new appearance will be generated and saved. That field will now be displayed in the same way, regardless of it being selected or not.
Two options to prevent these "blank" fields in Reader/Acrobat:
Generate appearance streams for all form fields. I have done this for one field (by simply re-setting its value using iText, which automatically generates an appearance stream).
The result:
Internal PDF structure:
Set the NeedAppearances entry in the AcroForm dictionary to true. Cf. PDF Specification, 1.7, Table 8.67:
NeedAppearances - boolean - A flag specifying whether to construct appearance streams and appearance dictionaries for all widget annotations in the document
This will trigger the viewer to generate all the appearances:
2. AcroForm or XFA?
In general, a XFA capable viewer will display the XFA form. A viewer without XFA support will use the AcroForm. You can verify this by setting different values for corresponding AcroForm and XFA fields. This is the result, Chrome's built-in PDF viewer on the left (no XFA support), Acrobat on the right:
Knowing that Reader/Acrobat is using the XFA form, why did we still see the blank fields (cf question 1)?
It seems that, when the values of an XFA field and its corresponding AcroForm field are the same, Reader/Acrobat also uses some information from the AcroForm, a.o. its appearance information. When the XFA value is different from the AcroForm value, the AcroForm field seems to be ignored completely.
TL;DR Set NeedAppearances to true to solve blank fields. XFA-incapable viewers will fall back to AcroForm automatically.
(My tests are based on Adobe Acrobat X.)
I'm creating a PDF using iTextSharp and it contains some fillable form fields. What I need, is to somehow set it up so that when those form fields are filled in and the resulting PDF is saved (in one of the commercially-available PDF readers like Adobe's Reader), I need those form fields to be fixed text (no longer editable).
Is there any way to do this?
As a comment suggests, this sounds like "flattening the document".
The issue with that process is that it is not available in (Adobe) Reader; it would require Acrobat, or server-side help.
On the other hand, some mobile PDF viewers do actually offer flattening when saving.
The workaround for Reader is to set the fields to read-only when saving the document. You would do this in the willSave Document Action by looping through the fields and setting them to readonly.
Simply Print your document as PDF. This will flatten the file.
For this
1. Install Adobe PDF Printer or CutePDF or some similar tool.
2. From your document. Select File -> Print.
3. Select Printer as the tool you installed in Step 1.
4. Your document will be a flattened, non-editable PDF now.