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

Free Support Forum - aspose.com

How do I convert heading numbering to plain text?

Good day,

I am turning to you for advice. I have a document that contains several numbered headings. I need to export, for example, page 7, where heading number 7 is located. If I convert it to a new document, it will become heading number 1.
How do I convert heading numbering to plain text?

@benestom unfortunately there is not easy way to convert calculated page numbers into plain text. HeaderFooter is shared across the Section, so the only way to achieve this is creating a Section by every page in the document.
A workaround for what you want could be set an starting page number for the new document, see the following example:

var indx = 6;
Document doc = new Document(@"C:\Temp\input.docx");
Document subDoc = doc.ExtractPages(indx, doc.PageCount - indx);

subDoc.FirstSection.PageSetup.PageStartingNumber = indx + 1;
subDoc.FirstSection.PageSetup.RestartPageNumbering = true;


input.docx (3.7 MB)
output.docx (1.4 MB)

@benestom I suppose you are talking about list numbering, not about page numbering. numbering start number is controlled by ListLevel.StartAt property. If you use Document.ExtractPages method to split your document into pages, Aspose.Words take care about the correct list item numbering, so it has the same numbering as in source document. For example see the following simple code:

Document doc = new Document(@"C:\Temp\in.docx");
// Extract 7th page
Document subDoc = doc.ExtractPages(6, 1);

in.docx (13.9 KB)
out.docx (11.1 KB)

As you can see in the output document Heading list numbering starts from seven.

If you actually need to convert list numbering into regular text, you can achieve this using code like the following:

Document doc = new Document(@"C:\Temp\in.docx");
// Update list labels.

// Get all paragraphs, which are list items
List<Paragraph> listItems = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>()
    .Where(p => p.IsListItem).ToList();

// Convert list items into regular paragraphs with leading text that imitates numbering.
foreach (Paragraph item in listItems )
    string label = item.ListLabel.LabelString + "\t";
    Run fakeListLabelRun = new Run(doc, label);


FYI @eduardo.canal

thank you for answer.
the heading number will be converted correctly. But there is a small difference.
offset from the number

If I want to convert a page 1:1. I would have to buy a PDF license. Save a document as a PDF and then extract the entire page with heading numbering? would it be like this?

@benestom If your goal is saving a particular page of the document to PDF, you can do this by specifying page set in the PdfSaveOptions:

Document doc = new Document("in.docx");
PdfSaveOptions opt = new PdfSaveOptions();
opt.PageSet = new PageSet(6);
doc.Save("seventh_page.pdf", opt);

The differences after conversion list numbering to plain text appears because difference in indents applied to list item and to regular paragraph. But this is the last resort option. I I sure, you can get the expected output either by using Document.ExtractPages method or by direct saving a particular page of the document to PDF, without additional document pre-processing.