I need to update the FDF request Input Steam before saving it, programmatically on the server side. I am using the iTextSharp library. The FdfReader gets the data fine and I can move it to the writer but there is no AcroFields property on the FdfWriter. And the AcroFields property on the FdfReader is ReadOnly, so I can't do that before setting the fields.
I need to be able to set a field's property to hidden. Like this:
VB.Net
Dim Reader As FdfReader = New FdfReader(Request.InputStream)
Dim Writer As FdfWriter = New FdfWriter
Writer.SetFields(Reader)
Reader.Close()
Writer.AcroFields.SetFieldProperty("Key", "setflags", PdfFormField.FLAGS_HIDDEN, Nothing)
' (add Save to File here)
But Writer.AcroFields does not exits. How are field properties set with the FdfWriter?
How are field properties set with the FdfWriter?
They are not.
The object that allows you to retrieve and fill in fields throug code is the PdfStamper.
Have a look at this example: http://developers.itextpdf.com/question/how-save-xfdf-file-pdf-file
Related
Is there a way I can quickly mimic all the properties of a form into for a new form one without directly copying the object (Ctrl-C&V, etc)?
Edit: Looking to copy into an entirely different Access Database.
Open each form in design view, set them equal to an object variable, and then set the properties of the source form equal to the proeprties of the destination form. Use a funciton like this in a public module:
Public Sub UpdateForm(SourceForm as string, DestinationForm as string)
dim frm1 as new form
dim frm2 as new form
set frm1 = forms(SourceForm)
set frm2 = forms(DestinationForm}
'* List the properties you want to copy here:
With form2
.RecordSource = frm1.RecordSource
.Caption = frm1.Caption
.DataEntry = frm1.DataEntry
'* And so on for each property
End With
docmd.save acform, DestinationForm
End Sub
If it's not a one-off project, I'd include some code to check and open the forms if they weren't already open.
File > Options > Object Designers > Form/Report Design View > Form template.
Set the form template to the name of an existing form and that will be used for all new forms.
You can copy a form object using VBA in a slightly more simple way than what DataWriter suggests.
You can use the following statement in the immediate window:
DoCmd.TransferDatabase acExport, "Microsoft Access", CurrentProject.FullName, acForm, "Form1", "Form1_Copy"
Where "Form1" is the name of the source form, and "Form1_Copy" is the name of the destination form.
I've a form in MS access that holds a subform showing records from a table. I've got a textbox whichs content is based on the selected record form the subset. If i select a record with id 2 then the value of the textbox is set to 2.
I want to copy the value of the textbox to another textbox of the form each time the value is changed.
The onChange eventhandler on the textbox bound to the subform does not trigger, neither does any other event when i select a record in the subform.
I'd either write some vba code to copy the text or use a makro.
It probably is triggering if you change the field manually, e.g., this code works for me:
Private Sub Text0_Change()
Text2.Value = Text0.Text
End Sub
(note value and text, as what you see in the field while you are editing it is not that same as the value of the field)
but not if you update it through VBA
Setting the value of a control by using a macro or Visual Basic doesn't trigger this event for the control. You must type the data directly into the control, or set the control's Text property.
https://msdn.microsoft.com/en-us/library/office/ff821734.aspx
If the fields were named like in my example, I'd have whatever VB that updates Text0 also update Text2
I am using iTextSharp 5.5.3 i have a PDF with named fields i created with Adobe lifecycle I am able to fill the fields using iTextSharp but when i change the textcolor for a field it does not change. i really dont know why this is so. here is my code below
form.SetField("name", "Michael Okpara");
form.SetField("session", "2014/2015");
form.SetField("term", "1st Term");
form.SetFieldProperty("name", "textcolor", BaseColor.RED, null);
form.RegenerateField("name");
If your form is created using Adobe LifeCycle, then there are two options:
You have a pure XFA form. XFA stands for the XML Forms Architecture and your PDF is nothing more than a container of an XML stream. There is hardly any PDF syntax in the document and there are no AcroForm fields. I don't think this is the case, because you are still able to fill out the fields (which wouldn't work if you had a pure XFA form).
You have a hybrid form. In this case, the form is described twice inside the PDF file: once using an XML stream (XFA) and once using PDF syntax (AcroForm). iText will fill out the fields in both descriptions, but the XFA description gets preference when rendering the document. Changing the color of a field (or other properties) would require changing the XML and iText(Sharp) can not do that.
If I may make an educated guess, I would say that you have a hybrid form and that you are only changing the text color of the AcroForm field without changing the text color in the XFA field (which is really hard to achieve).
Please try adding this line:
form.RemoveXfa();
This will remove the XFA stream, resulting in a form that only keeps the AcroForm description.
I have written a small example named RemoveXFA using the form you shared to demonstrate this. This is the C#/iTextSharp version of that example:
public void ManipulatePdf(String src, String dest)
{
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
AcroFields form = stamper.AcroFields;
form.RemoveXfa();
IDictionary<String, AcroFields.Item> fields = form.Fields;
foreach (String name in fields.Keys)
{
if (name.IndexOf("Total") > 0)
form.SetFieldProperty(name, "textcolor", BaseColor.RED, null);
form.SetField(name, "X");
}
stamper.Close();
reader.Close();
}
In this example, I remove the XFA stream and I look over all the remaining AcroFields. I change the textcolor of all the fields with the word "Total" in their name, and I fill out every field with an "X".
The result looks like this: reportcard.pdf
All the fields show the letter "X", but the fields in the TOTAL column are written in red.
I finally found a way, guess the problem was coming from using Adobe LC, so i switched to Open Office it all worked but when i flatten the form everything disappears. I found a solution to that here ITextSharp PDFTemplate FormFlattening removes filled data
Thanks Mr Lowagie for your help
I'm working on being able to extract out some information from a filled out W9 tax document, specifically one that is signed via echo sign. When I open the file with the latest version of ITextSharp, all of the field values are blank. When I call IsEncrypted it returns true, but i didn't supply a password, nor do i need to to view the pdf in a browser/reader. Anyone have any ideas? I cant supply a copy of the final pdf since it has someones ssn in it
I googled a blank W9 tax form. The one I found (Rev. Aug 2013) is a hybrid XFA form: it contains AcroForm and XFA technology.
You say all the field values are blank. I assume you mean the AcroForm fields. So probably the data is contained in the XFA data. You can easily check this:
PdfReader reader = new PdfReader("w9.pdf");
XfaForm xfa = new XfaForm(reader);
XmlNode xfaNode = xfa.DatasetsNode;
reader.Close();
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
XmlWriter writer = XmlWriter.Create("xfadata.xml", settings);
xfaNode.WriteTo(writer);
writer.Close();
The xfadata.xml file will contain the XFA data. If the field values you want to extract are there, it's just a matter of parsing the XML structure.
I actually found the issue, it was on EchoSign's side. Basically when they send you a final pdf document, they remove all fields and replace them with actual text elements. If i simply PdfTextExtractor.GetTextFromPage(reader, 1); i can see the text im looking for in the results, now to write a regex to get it, thanks for the help!
I'm using iTextSharp to create pdf files on the fly for my users to save on their computers. Currently the way it works is that I had several pdf templates that iTextSharp opens, sets fields from the database and save on user computer.
I'm having real problems with adding rich content into the body field which the users enter using a Rich Text editor (NiceEdit). It contains really simple options such as bullets, bold, italic, font colors, sizes etc. which is all what they need. I tried all possible options out there but nothing seem to help.
PdfReader reader = new PdfReader(originalReport.ToString());
PdfStamper stamper = new PdfStamper(reader, new FileStream(report, FileMode.Create));
AcroFields fields = stamper.AcroFields;
fields.SetFieldProperty("body", "setfflags", PdfFormField.FF_RICHTEXT, null);
fields.SetFieldRichValue("body", bodyValue.ToString());
fields.GenerateAppearances = false;
I tried flattening the form but it doesn't display the field at all. If I didn't flatten the form then the field displays the content but with no format at all (even new lines are removed) and if I used the SetField option instead of the SetFieldRichValue I get a string of the html content
I also tried allowing the pdf template field to "Allow Rich Text" from acrobat pro but this gives an exception and halts the pdf :)
Also please note that since I'm using a template that depends on the type of the user, the SetField option is used, I don't create the document from scratch hence I don't use paragraphs which I can get if I used the HTMLWorker and simply add to a document
Any help please?