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

Free Support Forum - aspose.com

Saving word as PDF give wrong text alignment

Saving a docx as pdf give me bad formatting. The docs is created from a template, using mailmerge.
This happens both saving directry as pdf the merged doc, and saving before to docx (showing correct) and then reloading and saving as pdf.

Used aspose.words for .net v 22.2.0.

Attached the docx and output files (OK saved with word, KO saved with Aspose.NET).
bad_identation.zip (94.4 KB)

Code is very simple:

        Document doc = new Document("output.docx");
        doc.Save("output3.pdf");

Thanks and best regards,
Andrea Zanotto

@andrea.zanotto We are working on your request and will reply you soon.

@andrea.zanotto Could you please send us the input docx before MailMerge so that the fix could exactly meet your expectations?

template.docx (12.4 KB)

Here it is! And that’s the code I’ve used:

        string MyDir = @"./";
        
        Document document = new Document(Path.Combine(MyDir, "template.docx"));
        string[] values = {
            "000001",
            "MARIETTO CRESPI",
            "PSU Ufficio Personale e documenti persi - Mario Negri - Dortomindo",
            "20020 POPITTO LI",
            "000001"
        };
        string[] fields = new string[] { "NREC", "LINE1", "LINE2", "LINE3", "LINE4" };

        document.MailMerge.Execute(fields, values);

        document.Save(Path.Combine(MyDir,"output.docx"));

        document.Save(Path.Combine(MyDir, "output.pdf"));

        Document doc = new Document(MyDir + "output.docx");
        doc.Save(Path.Combine(MyDir, "output2.pdf"));

@andrea.zanotto Thank you for additional information. We have reproduced and logged the issue as WORDSNET-23423. We will keep you informed and let you know once it has been resolved. We apologize for your inconvenience.

@andrea.zanotto Unfortunately, after discussion, it has been decided to postpone the issue resolution at this point. Please consider the following code as a workaround.

Document doc = new Document("output.docx");
doc.FirstSection.Body.Tables[0].AutoFit(AutoFitBehavior.AutoFitToWindow);
doc.Save("output3.pdf");