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

Free Support Forum - aspose.com

LayoutEnumerator Issue?

Hi, I am trying to create a new document from scratch using .NET. I am using the setup as below. I want to use a LayoutCollector/Enumerator when creating the document to calculate the position some things need to be.

However, once I have created a LayoutEnumerator it seems anything I add to the document after that line doesn’t appear when saving the document as a .PDF but will as a .DOCX.

If I then reload the .DOCX document I just saved (with the correct output), I can resave it as a .PDF and everything is there as it should be?

Not sure if I am missing something when using the LayoutEnumerator or there is something else going on?

Thanks!

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Paragraph para1 = builder.InsertParagraph();
para1.Runs.Add(new Run(doc, “This is a paragraph!”));
para1.Runs.Add(new Run(doc, “This is still the same paragraph, just a new run.”));

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

// Anything after here doesn’t get added to the document (for PDFs)

// This won’t be added to the .PDF but will appear in the .DOCX
Paragraph para2 = builder.InsertParagraph();
para2.Runs.Add(new Run(doc, “This is a new paragraph!”));
para2.Runs.Add(new Run(doc, “This is still the same new paragraph, just a new run.”));

builder.Document.Save(desktop + “Test.docx”); // Has all the content
builder.Document.Save(desktop + “Test.pdf”, SaveFormat.Pdf); // Only has para1

@WillR27

Please call Document.UpdatePageLayout method before saving document to PDF to get the desired output.

builder.Document.Save(MyDir + "Test.docx");
builder.Document.UpdatePageLayout();
builder.Document.Save(MyDir + "Test.pdf", SaveFormat.Pdf);

@tahir.manzoor Thank you, annoyingly simple solution!