Table in DOCX document loses cell spacing converting to PDF

Hello everyone,
I have a problem with converting a Word document to PDF.
The document contains a table.
When I convert it to PDF (_document.Save(_tempFileName, Aspose.Words.SaveFormat.Pdf)), I lose the spacing between the cells.
How can I do this?
Thank you,
N.Enea

@n.enea

To maintain cell spacing when converting a DOCX document containing a table to PDF using Aspose.Words, you need to ensure that the cell spacing is enabled in your table settings. You can achieve this by setting the AllowCellSpacing property to true and specifying the desired CellSpacing value.

Here’s a code example demonstrating how to set up a table with cell spacing before saving it as a PDF:

using Aspose.Words;
using Aspose.Words.Tables;

public class Program
{
    public static void Main()
    {
        // Create a new document
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        // Start a new table
        Table table = builder.StartTable();
        builder.InsertCell();
        builder.Write("Cell 1");
        builder.InsertCell();
        builder.Write("Cell 2");
        builder.EndRow();
        builder.InsertCell();
        builder.Write("Cell 3");
        builder.InsertCell();
        builder.Write("Cell 4");
        builder.EndTable();

        // Set cell spacing
        table.AllowCellSpacing = true;
        table.CellSpacing = 5; // Set the desired spacing in points

        // Save the document as PDF
        doc.Save("output.pdf", SaveFormat.Pdf);
    }
}

In this example, the AllowCellSpacing property is set to true, and the CellSpacing is set to 5 points. This configuration will ensure that the spacing between the cells is preserved when the document is converted to PDF.

Make sure to adjust the CellSpacing value according to your requirements. If you continue to experience issues with cell spacing after applying these settings, please check the specific formatting of your DOCX document, as certain styles or settings may override the cell spacing properties.

I load the DOCX from a file.
I have verified that the property AllowCellSpacing is set to true and CellSpacing is greater than 0.

@n.enea Could you please attach your problematic input and output documents here for testing? We will check the issue and provide you more information.

Thank you for your reply!

Here the original file and the conversion using Aspose (no cell margin) and Microsoft Word (correct).

original_document.docx (26,5 KB)

using _ms_word.pdf (45,7 KB)

using_aspose.pdf (19,7 KB)

@n.enea
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-28118

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.

Thank you again, I stand by waiting for news.

1 Like