Can not convert Word to PDF in .NET

Hello!
I have a problem creating a PDF file with Aspose.Words (v. 18.9.0) in .Net.

I have the following code:

                var streamOut = new MemoryStream();

                Aspose.Words.Document doc = new Document();
                DocumentBuilder builder = new DocumentBuilder(doc);

                Aspose.Words.Font font = builder.Font;
                font.Size = 16;
                font.Bold = true;
                font.Name = "Arial";

                ParagraphFormat paragraph = builder.ParagraphFormat;
                paragraph.Alignment = ParagraphAlignment.Left;
                paragraph.KeepTogether = true;

                builder.MoveTo(doc.FirstSection.Body.LastParagraph);

                // Shows how to move a cursor position to the beginning or end of a document.
                builder.MoveToDocumentStart();
                builder.Writeln("Title");

                font.Size = 12;
                font.Name = "Arial";
                font.Bold = false;

                builder.InsertBreak(BreakType.ParagraphBreak);
                builder.Writeln("Test line 1");
                builder.Writeln("Test line 2");

                builder.InsertBreak(BreakType.ParagraphBreak);

                font.Size = 14;
                font.Bold = true;

                builder.Writeln("Undertitle");
                builder.InsertBreak(BreakType.LineBreak);
                font.Size = 12;

                var counter = 1;
                foreach (var object in objects)
                {
                    if (object.Type != "pageBreak")
                    {
                        builder.Writeln(counter + ". " + object.Title);
                        builder.InsertBreak(BreakType.LineBreak);
                        counter++;

                        switch (object.Type)
                        {
                            case "checkBox":
                                foreach (var answer in object.Answers)
                                {
                                    builder.InsertCheckBox("", false, false, 0);
                                    builder.Writeln(answer.Description);
                                }

                                break;
                            case "radioButton":
                                foreach (var answer in object.Answers)
                                {
                                    builder.Writeln(answer.Description);
                                }

                                builder.InsertBreak(BreakType.LineBreak);
                                break;
                            case "dropDown":
                                foreach (var answer in object.Answers)
                                {
                                    builder.Writeln(answer.Description);
                                }

                                builder.InsertBreak(BreakType.LineBreak);
                                break;
                        }
                    }
                }
                
                doc.Save(streamOut, Aspose.Words.SaveFormat.Pdf);
                streamOut.Position = 0;
                return File(streamOut, "application/pdf", "Export.pdf");

When I save the file as Word, the content is present. If I save it as PDF, it is defective or empty.

I think I’ve considered everything in your documentation.

Can you help me?

@TarekA

Thanks for your inquiry. Please call Document.UpdatePageLayout method before saving document to PDF. Hope this helps you.

If you still face problem, please attach the following resources here for testing:

  • Please attach the output PDF file that shows the undesired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.