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

Free Support Forum - aspose.com

Avoid Vertical Spacing to Retain Number of Pages during Word to PDF Conversion using C# .NET

Vasu: Hi, I got a temporary license for Aspose.words on friday. But when I use the latest dll, it still shows the Aspose watermark on the document
Vasu: Hi, I bought a paid version of Aspose.word last friday. I applied the lic file and rebuild the program, I am still getting the trial version of document as the output. Please help me with this issuew
Vasu: hi
Assistant: Hello, thank you for reaching out to us. May I know your name please?
Vasu: Vasu
Assistant: Please provide your email address, this will help our team to reach back.
Vasu: vasudevan.ananthakrishnan@nara.gov
Assistant: Thank you for providing your details. You can always type “forget me” to remove these details.
Assistant: Welcome to Aspose, Vasu!
Assistant: How may I help you today?
Vasu: I am using Aspose dll to process word documents. One of the document got failed to process when this method was called --> at Aspose.Words.Document.(Stream , String , SaveOptions )
We are trying to save this document as a pdf.
Assistant: Thanks for asking question. I’ll be forwarding your query to our technical support department.
Assistant: Vasu, one last thing before I move forward. Please provide an appropriate subject line for your support ticket.
Vasu: Document processing failure while trying to save it as a pdf
Assistant: One moment please, generating support ticket.

@vasudevan,

Regarding the licensing issue, please refer to Licensing and Subscription section of documentation.

Please ZIP and upload your input Word document you’re getting this problem with here for testing. We will then investigate the issue on our end and provide you more information.

failed documents.zip (1.1 MB)
I have zipped two documents and attached them here. The smaller-sized word file is a portion of the large file that also fails to process giving me the same error.

@vasudevan,

After an initial test with the licensed latest (21.6) version of Aspose.Words for .NET, we were unable to reproduce any exceptions on our end. See following output PDF files:

So, we suggest you to please upgrade to the latest (21.6) version of Aspose.Words for .NET.

Thanks for replying. I noticed the pdf that you attached are having different formats than what I sent in the original file. Lets take the smaller file-“portion”. The word file that I sent has 17 pages, and the pdf you sent has 27 pages. If you compare then page-by-page, you will notices so many blank spaces are added in the pdf version. Could you please explain what is the reason for this?
Also, the version of aspose that I am using right now is 20.10. Is there a way for you to test this document in the same version to see if it fails for you too?

@vasudevan,

I tested both of your Word DOCX documents with old 20.10 version of Aspose.Words for .NET and was still unable to reproduce any exception on my end during converting to PDF. Can you share the stack trace of the exception you are observing on your end?

You’re right; similarly, MS Word 2019 reports 882 pages in COVID-19 Healthcare ETS 6.8.21 1030pm clean.docx while we observe 1,272 pages in Aspose.Words 21.6 generated PDF. For the sake of corrections, we have logged WORDSNET-22380 (related to portion.docx) and WORDSNET-22381 (related to COVID-19 Healthcare ETS 6.8.21 1030pm clean.docx) in our issue tracking system. We will further look into the details of these problems and will keep you updated on the status of these issues. We apologize for your inconvenience.

@vasudevan,

Upon further investigation, we have noticed that the number of pages and the layout of the document have changed in MS Word on saving to PDF. The number of pages was 17 before saving and it becomes 27 after saving. It happens because MS Word updates some fields automatically when saving to PDF.

The document has a number of REF fields. The bookmark range defined by the fields sometimes includes paragraphs with a section break (next page) and it causes those breaks to be inserted into field results on updating the fields.

Aspose.Words imitates this behavior by default. Apparently, you wish to get the layout before field update. In order to avoid updating the fields automatically, PdfSaveOptions.UpdateFeilds should be set to false in your code.

Document doc = new Document("C:\\Temp\\portion.docx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.UpdateFields = false;
doc.Save("C:\\Temp\\21.6 UpdateFields false.pdf", pdfSaveOptions);

Output produced by above code is:

@vasudevan,

Regarding WORDSNET-22381, the document layout changes on saving to PDF (in MS Word as well) because fields are updated automatically on saving. Please see my previous post that describes the analysis details of WORDSNET-22380. So, we can suggest you to set PdfSaveOptinos.UpdateFeilds to false in order to avoid field update on saving to PDF. With this setting, Aspose.Words outputs 881 pages in PDF on our end (see 22381.AW.NoFieldUpdate.pdf (2.3 MB)).

In case you are still concerned about the layout differences with UpdateFields set to false, then please identify them (with the help of screenshots highlighting the problematic areas) and also provide MS Word generated PDF output as it may be needed to analyze differences caused by font substitution.

Hi,
Regarding the document saving failure, I have attached exception details as well as the screenshot (exceptiondetails.docx (162.2 KB)
in a word file since it was not allowing me to upload screenshots) where I am getting the error while trying to save the document using Aspose. Please have a look and let me know if you need further details.

@vasudevan,

Please compress the following resources into ZIP format and attach the .zip file here for testing:

  • Source Word document you are getting this System.NullReferenceException
  • Please also create a standalone simplified Console Application (source code without compilation errors) that helps us to reproduce this problem on our end and attach it here for testing. Please do not include DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will then start further investigation into this particular issue and provide you more information.