We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word to PDF - issue with headers and margins

Word file has a header and footer but when converting to pdf the headers and footers are not present in PDF. To overcome this I used the DocumentBuilder but faced below problems:

  1. If the Header is multi line (using InsertHtml) then the content of the first page moves completely to the second page. (refer attached Issue.Png)

  2. I am providing margins to page set up and footer distance. If the footer also is multi line then the footer distance is not maintained. For 2 line footer I specified footer distance as 70 (for a 0.4 inch space between the footer and bottom of page) when 3 line specified footer distance as 50 for same 0.4 inch. This is confusing.

Hi there,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output PDF file that shows the undesired behavior.
  • Please attach the expected output PDF.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Attached is the source word and generated pdf document.

Also attached is the Expected PDF.

The StereamMulti.pdf that is generated also has a QR code image on 1st page which is fine, but the content of this page goes down to second page.

If I reduce the header to 2 lines the content comes to first page.

Hi there,

Thanks for your inquiry. Please note that in evaluation mode there are some limitations applied. E.g. Aspose.Words injects an evaluation watermark at the top of the document. The document’s contents are truncated after a certain number of paragraphs during import or export.

Please request for 30-days temporary license from here:

Get temporary license

Please refer to the following article about applying license.

Applying a License

Your input document is Html. Please share the complete html document along with images here for testing.

Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.

I am using the 30 day evaluation license. Attached is the console application code in .zip file. It has the source htm file and the generated pdf file. The pdf file will have header and footer and which will be different on first page and rest of pages. Currently the code generates a 2 page pdf. Path of files ‘Source\MultiPageBreak’

I am facing issue with the header and footer distance.

In code I have set below values. pageSetup.HeaderDistance = 86.4;

pageSetup.FooterDistance = 50;

The Header distance sometimes is maintained in all the pages of PDF but the footer distance is not maintained in all pages of PDF.

Please help.

Hi there,

Thanks for sharing the detail.

We have tested the scenario using latest version of Aspose.Words for .NET 17.3.0 and have not found the header and footer distance issue. Please check the attached document and image for detail.

Thanks for the update. Please check the \Source\MultiPageBreak folder in the zip file I shared. It has the generated PDF StreamMulti.pdf with 2 pages. If you open the PDF and view the Page 1 footer and Page 2 footer you will see the difference.

I have also attached the image for reference.

Hi there,

Thanks for sharing the detail. The PageSetup.FooterDistance property get or sets the distance (in points) between the footer and the bottom of the page. You are getting the expected behavior of Aspose.Words. There is one table row in first page’s footer and two rows in the second page’s footer.

In your case, we suggest you please insert one empty row in first page’s footer to get the same footer space on all pages. Hope this helps you.

In your code, you are not moving the cursor to the matched node. Please move it to the matched node in IReplacingCallback.Replacing.

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
    builder.MoveTo(e.MatchNode);
    builder.Write("Page ");
    builder.InsertField("PAGE", "");
    builder.Write(" of ");
    builder.InsertField("NUMPAGES", "");
    e.Replacement = "";
    return ReplaceAction.Replace;
}

Hi Tahir,

Thanks a lot for:

  1. suggestion to use empty line

  2. pointing out the issue of not moving to the matched node

I am now facing another issue when I have Chinese or Japanese characters in the htm file.

I am using the same console application. I am attaching the htm file, the doc file and the generated pdf file in MultiLangColumnIssue.zip. When these characters are present the generated pdf is not able to maintain the column width.

Hi there,

Thanks for your inquiry. We have tested the scenario and have not found the shared issue. We have attached the code, output PDF and DOC files with this post for your kind reference.

If you are using different code example, please share it here for further testing. We will investigate the issue and provide you more information on this.

Hi Tahir,

If you refer my attachment MultiLangColumnIssue.zip in my earlier post, and use the htm file in there to generate the .doc and .pdf through the program.cs you will see the difference in the streammulti.doc and streammulti.pdf

code lines

string path = ConfigurationManager.AppSettings["WordFilePath"] + "\StreamMulti.doc";
string pdfPath = ConfigurationManager.AppSettings["WordFilePath"] + "\StreamMulti.pdf";

The streammulti.doc is used to generate the streammulti.pdf.

I am attaching a screenshot to show the difference between streammulti.doc and streammulti.pdf.

Thanks.

Hi there,

Thanks for sharing the detail. Please note that Aspose.Words mimics the same behavior as MS Word does. If you open the “StreamMulti.doc” in MS Word and save it to DOC file format, you will get the same output.

Hi Tahir,

Thanks for the update. I am attaching below files:

StreamMulti.doc

StreamMulti.pdf

StreamMultiSavedFromWord.pdf

StreamMulti.doc is generated from the HTML using the code I shared. Then this doc file is converted to StreamMulti.pdf using Aspose Words through code. This PDF has an issue of not maintaining the column width.

I opened StreamMulti.doc in Word and saved it as PDF StreamMultiSavedFromWord.pdf. This PDF maintains the column width and has no issues.

So when Word can convert the Doc to PDF without issues, I am not able to figure out why the problem is coming when converting the Doc to PDF using Aspose Words.

Thanks

Hi there,

Thanks for your inquiry. The “StreamMulti.doc” is HTML document. Please open it in notepad to check HTML. Please save “StreamMulti.doc” to DOC/DOCX file format to check table’s column width. We have attached the MS Word output document with this post for your kind reference.

However, we have managed to reproduce this issue by using following code example. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15094. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Document doc = new Document(MyDir +@"StreamMulti.doc");
doc.Save(MyDir+"17.3.0.pdf");

Hi Tahir,

Thanks a lot for all your guidance and also logging the problem in issue tracking system.

Thanks