Save as PDF and ExtractPages - creation of a empty page in document

Good morning,

if I use the code mentioned below, when the document is divided into sections, a new blank page after page 98 will be created.
When I save this document as a PDF, another blank page appears after page 64

Document doc = new Document(@"C:\Temp\Test\0TS215pV01.docx");
Document DocClone = (Document)doc.Clone(false);
//docClone = (Document)doc.Clone(false);
DocClone.Sections.Clear();
doc.UpdatePageLayout();

ImportFormatOptions opt = new ImportFormatOptions() { KeepSourceNumbering = true };
for (int i = 0; i < doc.PageCount; i++)
{
    Document page = doc.ExtractPages(i, 1);
    DocClone.AppendDocument(page, ImportFormatMode.UseDestinationStyles, opt);
}

DocClone.Save(@"C:\Temp\Test\0TS215pV01_poroztrhani.docx");
DocClone.Save(@"C:\Temp\Test\0TS215pV01_poroztrhani.pdf", SaveFormat.Pdf);

You could take a look at it
Thank you in advance

0TS215pV01.docx (1.3 MB)

@benestom Could you please explain the goal of splitting document into page and rejoining it? Actually such processing does not guaranty to produce the same document layout as in the original document. The problem is that MS Word documents are flow documents by their nature and they do not have “page” concept. The classic example is the table that occupies several pages. If the table is split page page page it is mandatory to have a paragraph after each part the the table. Aspose.Words adds these paragraphs and this might push content down and broke the original document layout.

Yes, I divide the document into paragraphs, thereby simulating the division of documents into pages. Then I work on individual paragraphs.
Problem

  1. dividing the document and merging it again, for the table after page 98, one extra page is inserted there. (page with empty table 99page)

1ExtractPages add page with empty table

  1. If I save the folded document as a PDF, a page will be added below page 64 (empty page in pdf 65)

2page extension when generating pdf

@benestom As I have mentioned it is not always possible to preserve the original document layout after splitting the document into pages and rejoining the pages. Such manipulation changes the original document structure that expectedly will affect the document layout.

if i execute this code after saving the document should contain 1 page but it contains 2?

Document page = doc.ExtractPages(97, 1);

You can check this out

@benestom
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-27448

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.

Hello,

I have selected one page from this document, if I save this page as a PDF, it will be a PDF with two pages. The content will be expanded. Could you please check this.

Save this document as a PDF:
2TCD006_1-11LsSection63.docx (55.8 KB)

@benestom If you need to save a particular page to PDF you should use Document.Save method, not Document.ExtractPages:

Document doc = new Document("C:\\Temp\\in.docx");
doc.Save(@"C:\Temp\page.pdf", new PdfSaveOptions() { PageSet = new PageSet(0) });

thanks for the reply,
that’s not what I meant. I should have put it in another thread but it’s one document so I added it here. Try saving the document to PDF and see the result. I don’t want to do ExtractPages.

@benestom Thank you for additional information. When open your document in MS Word on my side there are two pages, so Aspose.Words also produces PDF with two pages, just like MS Word.

you are right, I prefer to send another file, it is the second page, which will be expanded in PDF to 2

0TS215pV01_poroztrhaniNově.docx (76.4 KB)

@benestom
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-27522

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.

The issues you have found earlier (filed as WORDSNET-27448) have been fixed in this Aspose.Words for .NET 24.11 update also available on NuGet.