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

Free Support Forum - aspose.com

Only first update exported on sequent saves to pdf format

Hi, I have flowing problem

I have doc file which I need to update and subsequently save to pdf. It can be reproduced.

public Document GetDoc()
{
    Run run = null;
    Document doc = new Document();
    Paragraph para = new Paragraph(doc);
    para.AppendChild(new Run(doc, "Clean"));
    Section sec = doc.Sections[0];
    sec.Body.AppendChild(para);
    return doc;
}

[Test]
public void EditAndSaveAsPdf()
{
    Document doc = GetDoc();
    var nodes = doc.GetChildNodes(NodeType.Run, true);
    Run firstRun = (Run) nodes[0];

    for (int i = 1; i <= 3; i++)
    {
        firstRun.Text = String.Format("Iteration no: {0}", i);
        doc.Save(String.Format("out{0}.pdf", i), SaveFormat.Pdf);
        doc.Save(String.Format("out{0}.doc", i), SaveFormat.Doc);
    }
}

Each of doc files has correct content - sequently
Iteration no: 1
Iteration no: 2
Iteration no: 3

but in each of pdf file content is “Iteration no: 1”

Currently I saving to doc stream first, create doc from that stream and then saving to pdf as workaround but its time and memory consuming.
Is there any other workaround for this?

Tested with Aspose.Words 10.4 and 10.8

Hi Jacek,
Thanks for your request. You should call Document.UpdatePageLayout before saving document to PDF to resolve the problem. Please see the following code:

doc.UpdatePageLayout();
doc.Save("C:\\Temp\\out.pdf");

The problem is caused because when you save the document to PDF first time, Aspose.Words automatically runs updating page layout and the layout is cached. So changes made after updating page layout does not appear in the output PDF. So you should simply rebuild document layout to resolve the problem.
Best regards,

Thx, Alexey it works this way.