Word To PDF-Problem in footer Implementation causing page content missing in PDF document

Hi Alexey,

Conitnuing from the previous post already logged in following thread

If u go to above URL the issue #1 is further discuss in this post.

Still i will explain you the problem in detail here again.

I am facing a problem while converting a word document into PDF format.My word document is consist of 3 pages but my PDF document is consist of only 2 pages.

The third page contents are missing from PDF report

Please refer attached document as (Pdf_doc.pdf & Word_doc.doc)

I am currently using Aspose Word version 7.0.0.0.

I am using following API for converting word document into PDF format.

reportDocument.SaveToPdf(0, reportDocument.PageCount, elementDoc, null);
//Here elementdoc is memorystream .

As you told me in previous thread that you can’t replicate the problem at your end & you can generate the PDF document sucessfully.

I have more update on this issue.

This issue is caused because of implementation of footer code for displaying page nos. in document.

The sample code is as follows.

private void button16_Click(object sender, EventArgs e)
{
    string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
    //Initialize Aspose license.
    Aspose.Words.License lic = new Aspose.Words.License();
    lic.SetLicense(path + @"\Aspose.Total.lic");
    Aspose.Pdf.License lic1 = new Aspose.Pdf.License();
    lic1.SetLicense(path + @"\Aspose.Total.lic");
    Document doc = new Document();
    DocumentBuilder documentBuilder = new DocumentBuilder(doc);
    Section currentSection = documentBuilder.CurrentSection;
    PageSetup pageSetup = currentSection.PageSetup;
    //go to document end.
    documentBuilder.MoveToDocumentEnd();
    //set the page size.
    pageSetup.PaperSize = PaperSize.A4;
    //apply new page margin
    pageSetup.LeftMargin = 100;
    pageSetup.RightMargin = 100;
    pageSetup.TopMargin = 100;
    pageSetup.BottomMargin = 100;
    //set the header margin.
    pageSetup.HeaderDistance = 3;
    documentBuilder.MoveToDocumentEnd();
    //Implementation for footer.
    pageSetup.DifferentFirstPageHeaderFooter = false;
    currentSection.HeadersFooters.LinkToPrevious(false);
    documentBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
    //Print Page X of Y
    //print first text [Page]
    documentBuilder.InsertHtml("");
    //Insert Page Field
    documentBuilder.InsertField("PAGE", "");
    //print first text [Of]
    documentBuilder.Write(" of" + " ");
    //Insert Total Page Field
    documentBuilder.InsertField("NUMPAGES", doc.PageCount.ToString());
    //move to main document.
    documentBuilder.MoveToDocumentEnd();
    documentBuilder.StartTable();
    documentBuilder.InsertCell();
    documentBuilder.Writeln("This is a sample document");
    documentBuilder.EndRow();
    documentBuilder.EndTable();
    //Move to end of document
    documentBuilder.MoveToDocumentEnd();
    // StartWord("aa.doc");
    // doc.Save("aa.doc");
    doc.SaveToPdf("aa.pdf");
    StartPdf("aa.pdf");
}
}

The Sample document generated from above code is also attached with this post ( please refer attachment as sample.doc & Sample.pdf )

The lines which are causing the problem is highlighed in RED color. if you comment out these lines from above code then PDF document is also get generated sucessfully.

I think you can replicate the same problem at you end with this sample code.

If you can replicate the problem at your end then how much amount of time it will take to fix this issue?

Waiting for your reply.

I am also having some doubts which are as follows.

1> This issue( discussed above is not there in Aspose.Word 6.2.0.0 & Aspose.PDF version 3.9.0.0 with legacy method ( refer attachment as Old_Method_WordToPDF.txt) Is it a compatibility issue?

2> Is it advicable to use the old legacy way to convert word to pdf document?

3> your future version of aspose will be compitable with old method or new method for converting word document into pdf format

Please suggest us proper way so that we can solve our all issue as earliest.since we have major release in this month.

Please Send me more updates on same issue wheather your able to reproduce above problem at your end.

Thanks & Regards,

Dwarika

Hi Dwarika,

Thank you for additional information. I managed to reproduce the issue on my side. You will be notified as soon as it is resolved.

You can also resolve the issue by changing your code a bit. Please use the following snippet of code:

documentBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
documentBuilder.InsertField("PAGE", null);
documentBuilder.Write(" of ");
documentBuilder.InsertField("NUMPAGES", null); 
  1. As I mentioned in another your thread, new method and old methods are absolutely different modules. That is why legacy and direct method can give different results.

  2. and 3. You can use legacy method, but you should note that we will exclude legacy method of PDF conversion in one of our future versions. Also no new issues will be fixed in the legacy method.

Best regards.

Thanks very much for your reply and quick support.

The code snippet we are using is as follows,

//Set the primary footer
documentBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
//Insert Page Field
documentBuilder.InsertField("PAGE", "");
//print first text [Of]
documentBuilder.Write(" Of ");
//Insert Total Page Field
// This changes is apply to fix for displaying total page number correctly in header footer on first page (Page X Of Y, object)
documentBuilder.InsertField("NUMPAGES", reportDocument.PageCount.ToString());

Let us know whether “” will work in place of null in documentBuilder.InsertField(“PAGE”, “”);

and reportDocument.PageCount.ToString() will work in place of null in documentBuilder.InsertField(“NUMPAGES”, reportDocument.PageCount.ToString()); methods.

Regards,

Dwarika

Hi Dwarika,

Thanks for your inquiry. Actually, you do not need to specify values of fields when you insert them. During converting to PDF Aspose.Words automatically updates values of fields. So please avoid inserting fields with values.

In your case the problem is caused by the following line of code:

documentBuilder.InsertField("NUMPAGES", reportDocument.PageCount.ToString());

But the problem disappears if replace the highlighted piece of code with null.

Best regards.

Hello,

we tried replacing the code with null and the output is attached…

kindly note that the on Page one in header the page number is appearing 1 of XXX in the right hand top most corner.

Here we want the page number to be 1 of 1.

Kindly suggest how would we achieve this.

documentBuilder.InsertField(“NUMPAGES”, reportDocument.PageCount.ToString()); is working fine with old version that is 6.2.0.0 where it is not coming properly after applying the code changes suggested by you.

Regards,

Dwarika

Hi Dwarika,

Thanks for your inquiry. You can just call Document.UpdatePageLayout() method before saving the document to update PAGE and NUMPAGES in the document.

Best regards.

The issues you have found earlier (filed as 11362) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.