logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mukesh  
#1 Posted : Friday, July 15, 2016 12:31:48 AM(UTC)
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
I can't seem to find code snippet in SDK to fill PDF fields by fieldnames with certain values and also to open a PDF form and read the values in the fields in them. Any help would be appreciated a lot.

I use C# and my app is WPF.

Thanks.
Paul Rayman  
#2 Posted : Sunday, July 17, 2016 4:40:21 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
The following code demonstrates how programmatically fill all editable forms in pdf document

Code:

private void btnTest_Click(object sender, RoutedEventArgs e)
{
	var doc = pdfViewer1.Document;
	var interactiveForms = doc.FormFill.InterForm;

	int i = 0;
	foreach(var field in interactiveForms.Fields)
	{
		if(field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
		{
			field.Value = "This is a field #" + (++i);
		}
	}
}


the same thing without using the viewer

Code:

private void btnTest_Click(object sender, RoutedEventArgs e)
{
	var forms = new PdfForms();
	var doc = PdfDocument.Load(@"c:\test.pdf", forms);
	//doc.FormFill is equal to forms and can be used to get access to acro forms as well;

	int i = 0;
	foreach(var field in forms.InterForm.Fields)
	{
		if(field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
		{
			field.Value = "This is a field #" + (++i);
		}
	}
}

Edited by user Monday, August 1, 2016 6:02:08 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Paul Rayman for this useful post.
mukesh on 7/25/2016(UTC)
mukesh  
#3 Posted : Monday, July 18, 2016 10:15:23 PM(UTC)
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
How can I attach my solution in this forum or in an email format to send it to you? I am experiencing Null Reference exception on the following line of code (eventhough it seems like the PDF file gets loaded)

var interactiveForms = doc.FormFill.InterForm;

Paul Rayman  
#4 Posted : Tuesday, July 19, 2016 6:46:03 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
I'm guessing you are using the Document property to set pdf into PdfViewer?
The recommended way is using the LoadDocument methods to do that.
https://pdfium.patagames...2d-1d3b-e162338c1382.htm

However you can still use the Document property. In this case you should load document in proper way. You need to create an instance of PdfForms object and pass it into PdfDocument.Load method
https://pdfium.patagames...81-f2cd-002185fa7a04.htm
After that you can get access to acro forms via this object.

Please find more detail how to create a PdfForms object in source code of PdfViewer.
Please look at row 1464 and rows 1615-1624 here: https://github.com/Patag...2fe46ddb340/PdfViewer.cs

Edited by user Tuesday, July 19, 2016 6:59:23 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.