"Invalid pdf format:pdf head signature is not found!" performing a simple merge

Hello –

I’m having trouble doing a very simple merge. Is something wrong with the templates or am I doing the technique wrong? I’ve attached 2 different templates, both of which yield the same error.

Here’s my code:

AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = userDirectory + “\” + templateFileName;
autoFiller.OutputStream = Response.OutputStream;

autoFiller.ImportDataTable(dt);
autoFiller.Save();

Where InputFileName = "C:\Documents and Settings\admin\My Documents\Visual Studio 2005\WebSites\MyApp\App_Data\UserTemplates\00550000000wI63AAE\Quote Template.pdf"

Thanks!
Mike

Here’s the other file…

Hi,

Can you please post your complete project, including the data table structure so that we can more accurately determine the cause of the problem.

Thanks.

Hello –

I have simplified my project to the following chunk of code.

DataTable testDT = new DataTable();
testDT.Columns.Add(new DataColumn(“CONTACT_LASTNAME”, Type.GetType(“System.String”)));
DataRow dr = testDT.NewRow();
dr[“CONTACT_LASTNAME”] = “Jones”;
testDT.Rows.Add(dr);


AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = “PDF_Form_Test.pdf”;
autoFiller.OutputStream = Response.OutputStream;

autoFiller.ImportDataTable(testDT);
autoFiller.Save();
Even with this simple example, I’m getting the same error.

I created the PDF Form using Nitro PDF Professional. Could that be the source of the problem?

What am I doing wrong? Thanks!

Hi,

I have been able to reproduce the error. I have logged this as PDFKITNET-3802. Our developers will try their best to resolve this issue as soon as possible.

Thanks.

Hi Adeel,

As long as I’m asking about some other questions, I wanted to check to see how this topic is coming along too. It concerns me that with such a simple example I ran into problems with PDF.Kit. Is this product fairly new? Would you recommend I wait a while before trying to implement it in a production environment?

All the same, it’s an ambitious product and has so much usefulness and value. I’m greatly looking forward to more progress on this.

Mike

Dear Mike,

Sorry for the inconvenience. Our developers are hard at work constantly trying to improve the quality of our products. Some times bugs are present in the component as a result of minor mistakes but still take some time to pin point. I will contact the developer working on this issue and ask him to give you further information about its progress.

Thanks.

Dear Mike,

This bug was fixed. A hotfix will be released to solve your problem within the next week.

Best regards.

Hi Luke –

It looks like the error message I originally was experiencing has been fixed. But now a new issue:

Everything looks like it’s going to work, but when I execute the autoFiller.Save() method, Internet Explorer errors (“Internet Explorer cannot display the webpage”) and FireFox returns what appears to be a bunch of binary data.

Here’s my code again:

protected void Button1_Click(object sender, EventArgs e)
{
DataTable testDT = new DataTable();
testDT.Columns.Add(new DataColumn(“CONTACT_LASTNAME”, Type.GetType(“System.String”)));
DataRow dr = testDT.NewRow();
dr[“CONTACT_LASTNAME”] = “Jones”;
testDT.Rows.Add(dr);


AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = Server.MapPath(“App_Data\PDF_Form_Test.pdf”);
// autoFiller.OutputFileName = Server.MapPath(“App_Data\output.pdf”);
autoFiller.OutputStream = Response.OutputStream;

autoFiller.ImportDataTable(testDT);
autoFiller.Save();
}

Am I doing something wrong? Are the Response headers not getting set properly?

By the way, the online demo for using autoFiller doesn’t appear to work with Firefox, so it might be a related Response headers issue. (GitHub Repositories for Examples, Plugins and Showcases of Aspose APIs for .NET, Java, C++ and Android then choose #9, using FireFox.)

Many thanks,

Mike

Hi Mike,
Sorry for bring you so much troubles.
As for the new issue, I need your help to locate the bug. Please uncomment the code:
autoFiller.OutputFileName = Server.MapPath("App_Data\\output.pdf");
to generate output file on disk, then open it both with Adobe and firefox manully. If everything is ok, please check your browser configuration. An old issue could be of some help: <A href="</A>. If it does not work, please provide your infor as detail as possible, including browser configure and the full project code.<BR>Thanks & Best regards.</P></BLOCKQUOTE>

Hi Luke –

The other discussion you pointed me to helped a lot. I have it all working now correctly. Here’s the code I ended up using:

protected void Button1_Click(object sender, EventArgs e)
{
DataTable testDT = new DataTable();
testDT.Columns.Add(new DataColumn(“CONTACT_LASTNAME”, Type.GetType(“System.String”)));
DataRow dr = testDT.NewRow();
dr[“CONTACT_LASTNAME”] = “Jones”;
testDT.Rows.Add(dr);


AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = Server.MapPath(“App_Data\PDF_Form_Test.pdf”);
// autoFiller.OutputFileName = Server.MapPath(“App_Data\output.pdf”);

Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader(“content-disposition”, “inline; filename=” + “studentOut.pdf”);
Response.ContentType = “application/pdf”;
autoFiller.OutputStream = Response.OutputStream;
autoFiller.ImportDataTable(testDT);
autoFiller.Save();
Response.End();
}

Many thanks.

Mike

Hi Luke –

Now that the autoFiller is working for me, I thought I would make things a little more complicated to see what happens. In the code below, I have added another row of data (so there are 2 rows now). I expected that the autoFiller would create a PDF for each row (which it does), however the data from row 1 is repeated on the second page of the PDF.

Would you take a look at this? Thanks

Here is the modified code… I have attached the output.

protected void Button1_Click(object sender, EventArgs e)
{
DataTable testDT = new DataTable();
testDT.Columns.Add(new DataColumn(“CONTACT_LASTNAME”, Type.GetType(“System.String”)));
testDT.Columns.Add(new DataColumn(“CONTACT_FIRSTNAME”, Type.GetType(“System.String”)));
DataRow dr = testDT.NewRow();
dr[“CONTACT_LASTNAME”] = “Jones”;
dr[“CONTACT_FIRSTNAME”] = “Mike”;
testDT.Rows.Add(dr);
dr = testDT.NewRow();
dr[“CONTACT_LASTNAME”] = “Smith”;
dr[“CONTACT_FIRSTNAME”] = “Sally”;
testDT.Rows.Add(dr);

AutoFiller autoFiller = new AutoFiller();

autoFiller.InputFileName = Server.MapPath(“App_Data\PDF_Form_Test.pdf”);
// autoFiller.OutputFileName = Server.MapPath(“App_Data\output.pdf”);

Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader(“content-disposition”, “inline; filename=” + “studentOut.pdf”);
Response.ContentType = “application/pdf”;
autoFiller.OutputStream = Response.OutputStream;
autoFiller.ImportDataTable(testDT);
autoFiller.Save();
Response.End();
}

Dear Mike,

I’m glad to see that the first experiment has been solved.

As for your second experiment, I am not very clear about your saying: “the data from row 1 is repeated on the second page of the PDF”. In your attachment, “Smith” is on the second page, which is the right result. If you plan to generate two seperated small files, please referring to the following code:

AutoFiller autoFiller = new AutoFiller();
autoFiller.InputFileName = "App_Data\\PDF_Form_Test.pdf";
autoFiller.GeneratingPath = "App_Data\\";
autoFiller.BasicFileName = "output";
autoFiller.ImportDataTable(testDT );
autoFiller.Save();

It will produce two small file, each containing one page, namely output0.pdf and output1.pdf respectively.

You can also find this in our [online API](http://www.aspose.com/Products/Aspose.Pdf.Kit/Api/) (AutoFiller class, case two). Hope this would help you.

Best regards.

You must think I’m crazy, but when I open the PDF in my prior message (using Acrobat 8.1 Reader), I see “Jones” on both the first page and the second page.

That prompted me to open the PDF in Nitro PDF and it looks correct! Smith shows on the second page!

This looks more like a problem with Acrobat Reader 8.1, but it is very worrisome. You may want to view the file in AR 8.1, perhaps something isn’t getting set in the PDF to make it fully compatible with it.

I think I’m in good shape. Thanks again.

Dear Mike,

I reproduced your problem by installing Adobe Reader 8.1.0. A hotfix is expected to released in one week. BWT, if two seperated small files are outputed, this will not occur any more. Please try and affirm this.

Best regards.