Doc to PDF error on table column size

Good morning,
we have a document, we store it as Word document, then we store it also as PDF document.

We found a different column size in a table (where cells are added dynamically via C#)

See images below

PDF

Word

Is this behavior linke to some parameter we should set in conversion process ?

This is our svaing code:

// Save as DOCX, reload and save as PDF
DocumentStoreHelper.StoreToFilePath(document, outputFilePathDocx, new OoxmlSaveOptions());

var tempDocumentInfo = new DocumentLoaderFromFile(outputFilePathDocx).LoadDocument(loadOptions);

DocumentStoreHelper.StoreToFilePath(tempDocumentInfo.Document, outputFilePathPdf, new PdfSaveOptions());

Thanks a lot in advance
Jack

@Jackomino

Cause

The issue with different column sizes in the PDF compared to the Word document may stem from how the Aspose.Words library handles table layouts during the conversion process. The layout engine attempts to mimic Microsoft Word’s rendering, but discrepancies can arise, particularly with dynamically added cells.

Solution

To resolve this issue, you should adjust the PdfSaveOptions when saving the document as a PDF. Specifically, consider setting properties that influence the layout and rendering of tables. Here’s a recommended approach to ensure better consistency:

  1. Use PdfSaveOptions to set the OptimizeOutput property to true, which can help reduce layout discrepancies.
  2. Ensure that the table widths are explicitly defined in your Word document before conversion.

Code

Here’s an example of how to implement the PdfSaveOptions in your existing code:

// Save as DOCX, reload and save as PDF
DocumentStoreHelper.StoreToFilePath(document, outputFilePathDocx, new OoxmlSaveOptions());

var tempDocumentInfo = new DocumentLoaderFromFile(outputFilePathDocx).LoadDocument(loadOptions);

// Set PDF save options
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions
{
    OptimizeOutput = true // Optimize the PDF output
};

DocumentStoreHelper.StoreToFilePath(tempDocumentInfo.Document, outputFilePathPdf, pdfSaveOptions);

Next Steps

  1. Test the conversion using the provided code and verify if the column sizes in the PDF now match those in the Word document.
  2. If discrepancies persist, review the table properties in the Word document to ensure they are correctly set before conversion.
  3. Explore additional properties in PdfSaveOptions that could affect layout, such as Compliance or PageSize.

Please implement these changes and let me know the outcome!

Hi,
thanks for your suggestion,
unfortunately nor setting OptiomizeOutput property nor using Compliance (i.e. Compliance = PdfCompliance.PdfA1a) fixed the problem.

BTW cells are loaded dynamically only when Word doc is created, when we create PDF file, we load the docx (saved previously) and convert it into PDF format.

Do you have the problem loading my docx and save it as PDF ?

Thanks a lot
Jack

I’m checking the version we’re using to have the last one, as I saw something useful on Release Notes…

Thanks
Jack

Unfortunately the problem is present also using 25.6

Jack

@Jackomino The question has to do with the compatibility mode for the document you are using and the two figures. I answer it here Finding Node (no paragraph) page index - #36 by vyacheslav.deryushev.

Hi,
I’m sorry but the problem is present even with no shapes in document

I did the whole workflow removing shape management, in the attached files you can see that the problem is still present and it’s not linked to shapes

Best regards
Jack
37449.zip (123.2 KB)

@Jackomino I see a difference in the w:gridCol value for the first column between your results and the resaved MS Word document.

Since this document was created with Aspose.Words for .NET 23.12.0, could you also attach the files created with the latest version?

Hi,
thanks for your investigation.

Here attached the output done with 25.6 version

37458.zip (121.3 KB)

Hoping this can help in finding the problem

Best regards
Jack

@Jackomino The grid value remains the same, but could you try using table.AllowAutoFit = false; after creating the table and before working with the rendering document to add any shapes to the document.

@Jackomino
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28395

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks a lot for your time.

Have a nice day
Jack

1 Like

Good morning,
Will I receive a notification here on forum or somewhere else when the issue will be fixed ?

Or can I check somewhere its status ?

Thanks a lot again,
have a nice day
Jack

@Jackomino You can check the status in the “Issues Status” block. This issue is on hold for now due to the complexity of the issue and after the root of the problem will be fixed. When the issue will be fixed and published in a new release, you will be notified via the forum.

1 Like