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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - "Empty" fields in form.
  FAQ FAQ  Forum Search   Register Register  Login Login

"Empty" fields in form.

 Post Reply Post Reply
Author
Message
ClasG View Drop Down
Beginner
Beginner
Avatar

Joined: 21 May 13
Location: Sverige
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote ClasG Quote  Post ReplyReply Direct Link To This Post Topic: "Empty" fields in form.
    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 Shocked.

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
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (1) Thanks(1)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 23 May 13 at 5:47AM
Clas,

You should flatten the formfields backwards because FormFieldCount is decremented after a field is flattened.  You will find that your code will start to work a little better.

Andrew.
Back to Top
ClasG View Drop Down
Beginner
Beginner
Avatar

Joined: 21 May 13
Location: Sverige
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote ClasG Quote  Post ReplyReply Direct Link To This Post Posted: 23 May 13 at 7:22AM
Now that you say it, it's obvious... Embarrassed

Great, thanks Andrew.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store