Libre Office Labels don't show up as "AcroFields" in iTextSharp? - pdf

so I've been trying to generate a report. I've tried quite a few things already but there always seems to be problems. I'm currently trying iTextSharp 4.1.6.
My current strategy is to use LibreOffice to create a document with editable pdf fields, or I guess they are called "AcroFields". I'm not sure since I can't find a definition. But anyways, I assume that all of these are "AcroFields":
But if I put all of those into a form and export as pdf only some of them show up as AcroFields:
var reader = new PdfReader(File.ReadAllBytes("abc.pdf"));
foreach(var field in reader.AcroFields.Fields)
{
Console.WriteLine(((DictionaryEntry)field).Key);
}
> Text Box 1
Check Box 1
Numeric Field 1
Formatted Field 1
Date Field 1
List Box 1
Combo Box 1
Push Button 1
Option Button 1
Notice how Label Field 1 is not present. If it were present then doing a text replace might be easy. Except it's not present so it's looking like even iText can't do a simple text replace in a pdf. Is this true? How would you replace text in a pdf document using iTextSharp?

Notice how Label Field 1 is not present.
As there is no AcroForm form field type "label", form labels usually are drawn as regular page content in PDF files.
If it were present then doing a text replace might be easy. Except it's not present so it's looking like even iText can't do a simple text replace in a pdf. Is this true?
Indeed, in general there is no simple text replacement in a PDF.
How would you replace text in a pdf document using iTextSharp?
I would determine the bounding box coordinates of the text to replace using the iText text extraction feature with some extension that returns text plus coordinates. Then I'd remove that text by redaction using iText's PdfCleanUp... classes. Finally I'd add the replacement text as new text in the bounding box determined at start.
Unfortunately for you, both good text extraction and redaction are not present in your version 4.1.6; for this approach you should update at least to 5.5.x.
Alternatively, though, as you've been trying to generate a report, I assume the template design is in your hands. In that case you can put your labels into read-only text fields which you can change (they are read-only only to GUI users).

Related

How can I keep Microsoft Word's PrintDate field code from becoming plain text when converting my document to a pdf?

In my Microsoft Word document, I have a field code to print the date the document was last printed ("PrintDate"). When I print my Word version of the document, every paper copy shows the date that copy came off the printer. However, when I convert my Word document to a pdf, the field code becomes static text with the date that I converted the document to a pdf. Any subsequent printing of the pdf copy will always just show the date the pdf version of the document was created, instead of the date the copy came off the printer.
I know I can create the pdf document without the PrintDate field code, insert a text field, and then use "JavaScript | Set Document Actions | Document Will Print" to make that text field operate like Word's PrintDate field code, but I'm using the Word document as a blank template for others to fill out and then they create pdf documents from it. It would be simpler to not have to leave instructions for everyone on how to insert the javascript and, instead, have it part of the blank Word template. I honestly don't understand why Adobe doesn't just convert the field code to javascript automatically, which brings me to my question...
Is there a way to convert the Word document to a pdf, but retain dynamic field codes, such as PrintDate and SaveDate?
You can't prevent field codes in Word being converted to their results in a PDF.

How to finalize edits in a PDF so that text is selectable?

I'm working on a pdf doc that includes input fields that have been edited. I'd like to be able to press select all and get all text from the document, but for some reason none of the input fields are included. Others have told me that if text isn't selectable, it must be an image, but in this case it's not - so is there a way to 'finalize' the edits and select the text? Maybe turn the doc into read only?
Edit: I've tried changing it to a read-only doc and it doesn't make the inputs selectable.

How do I fill out fillable PDF Form fields using 4gl?

I have a PDF form that I'm filling out with data using progress-4gl. To date, I've been only filling in text fields using the following syntax:
put stream stream1 unform
"^global CHX_SINGLE_CE_PLAN3" skip(0)
"X" skip
CHX_SINGLE_CE_PLAN3 is the field name...
This code works when dealing with text fields but I'm trying to check a box instead of fill in a text field. I cannot find any documentation on this. Is checking a box on a fillable pdf form even possible with 4gl?
As far as I remember PDF Include has support for filling fillable forms. Whilst it's probably a bit over the top in terms of what you want to achieve, it's an open source project and so you may well find the answer to your question within the code itself.
Here's a link to the project page: http://www.oehive.org/pdfinclude
I discovered the answer, which I thought I had already tried before asking this question. The answer is you need to pass the value "Yes" (with capital "Y") in order to check the checkbox. The correct code in this instance is:
put stream stream1 unform
"^global CHX_SINGLE_CE_PLAN3" skip(0)
"Yes" skip
I believe this is the case no matter which language you're using

Microsoft Word MacroButton - placeholder text visibility

I have a Microsoft Office 2013 Word template, in which I have some text-field elements, created by using Quick Parts -> Field -> MACROBUTTON noname [Type your text here].
If I fill only some of these fields (i.e. "[Name]", "[Address]") and I print or save as PDF, all the fields that I have not filled will display as [Insert your text here] in the printed paper or PDF. To be clear, the placeholder text must be manually removed (or replaced with the text you want).
I've readed somewhere, that you can create a macro, which will not display the placeholder text in the PFD- or printed version of the document, if there is no text written manually to that specific field (you leave it as it was). As this would be handy in cases, where you don't fill all the neccessery fields, my question is:
Q: Can this be achieved only by using Macro Button, and if not, what is needed to create text fields as described below that are not included in the printed or PDF saved version of the document?
This cannot be achieved without using actual macro code. Right now your solution contains no macro code, the fields simply function as "targets" and when the user types on the field it is deleted. Where the user does not type, the prompt remains. You'd need code to delete these fields from the document.
Given your requirement, the code would have to fire in the DocumentBeforeSave and the DocumentBeforePrint events. These events require a class and supporting code in a standard module. The basic information on how to set these up is in the Word object model language reference: https://msdn.microsoft.com/en-us/library/office/ff821218.aspx
An alternative to MacroButton fields would be to use ContentControls. But here, again, code and the same events would be required to remove/hide placeholder text.

Convert Crystal Reports Text Object/Text box to HTML?

I want to convert the text from Crystal reports to HTML and so far I have noticed that if I simply add a text field, I am able to change it to HTML by formatting text option and then under Paragraph tab there is an option to change the text interpretation. The problem is that I have entered text box to enter some hard coded information along with the database driven field, so I would like to know if there is a way I can convert the text box data into HTML. I am currently using crystal reports XI and want going forward want to upload these reports in a website using visual studio 2010. Thank you for your help.
It appears that the 'Text Interpretation' is ONLY a property of these fields:
Database
Formula
Parameter
Group Name
I wasn't able to get the Text Object to act as HTML.
However, you could create a formula with static HTML text:
"<strong>this is bold text</strong>"
Or a formula that combines text w/ data:
"<pre>" + {table.html_field} + "</pre>"
You could also use a string parameter to display user-supplied, HTML text.