Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
"Empty" fields in form. |
Post Reply |
Author | |
ClasG
Beginner Joined: 21 May 13 Location: Sverige Status: Offline Points: 7 |
Post Options
Thanks(0)
Posted: 21 May 13 at 3:22PM |
Hi.
I'm evaluating QuickPDF and some other libraries for my company. I'm trying to fill a form with data, but can't find a fully functioning way to go. This code snip has two ways of iterating the fields - with LoopXML defined, the source data is iterated and the value of the form field with the matching name is set. If LoopXML isn't defined, it iterates through the fields in the form and tries to find the matching name in the XML source, read it and set the value. int nMainDocID = -1; XmlDocument xml_doc = new XmlDocument(); xml_doc.LoadXml(sResponse); foreach ( XmlNode page in xml_doc.SelectNodes("//Report/Page")) { int ec = QP.LoadFromFile(sReportFilename + ".pdf", ""); if (ec != 1) { Response.Write("<br>Report can not be loaded!"); return; } int nCurrentDocID = QP.SelectedDocument(); #if LoopXML foreach (XmlNode n in page) { ec = QP.SetFormFieldValueByTitle(n.Name, n.InnerText); } int nFC = QP.FormFieldCount(); for (int i = 0; i < nFC; i++) { QP.UpdateAndFlattenFormField(i); } #else int nFailCount = 0; int nFC = QP.FormFieldCount(); for (int i = 0; i < nFC; i++) { string sField = QP.GetFormFieldTitle(i); if (sField == null || sField.Trim() == "") { QP.FlattenFormField(i); // "Remove" field nFailCount++; continue; } XmlNode n = page.SelectSingleNode("./" + sField); if (n != null) { QP.SetFormFieldValue(i, n.InnerText); QP.UpdateAndFlattenFormField(i); } else { QP.FlattenFormField(i); // "Remove" field } } #endif if (nMainDocID == -1) { nMainDocID = nCurrentDocID; } else { QP.SelectDocument(nMainDocID); QP.MergeDocument(nCurrentDocID); } } Response.ContentType = "application/pdf"; Response.AddHeader("Content-disposition", "attachment; filename=" + GetQueryParam("RPT") + ".pdf"); Response.BinaryWrite((byte [])QP.SaveToVariant()); Response.End(); Neither of these ways work all the way... The first one successfully sets all field data, but there's no way of flattening the fields. The loop after setting the data, that attempts to flatten the fields, fails. Probably for the same reason the second way fails; half way through the fields (110 of 218) the field names comes up as empty, and there's no name to find in the source data . The PDF with the form: Any ideas...? Another unrelated question is if there's a better way to duplicate the original document. This source document should be repeated for each Page-tag in the source. The only way I found to do that was to actually load the document from the file again, which seems unnecessary... This is also one of the reasons I need to flatten the fields (to avoid duplicates). Grateful for rapid replies.. Regards, Clas
Edited by ClasG - 21 May 13 at 3:25PM |
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(1)
|
Clas, Andrew.
|
|
ClasG
Beginner Joined: 21 May 13 Location: Sverige Status: Offline Points: 7 |
Post Options
Thanks(0)
|
Now that you say it, it's obvious...
Great, thanks Andrew.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions 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 |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store