question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PageSplitter not working as expected

See original GitHub issue

With Aspose.Words 19.7 trying to use DocumentPageSplitter from the samples in order to get each page from a specific document as a new document. The code used is:

static void Main(string[] args)
{
    try
    {
        const string fileName = "problematic_file.docx";

        var license = new License();
        license.SetLicense(...);
        
        ExtractDocumentToPages(fileName, 1, 1);
    }
    finally
    {
        Console.WriteLine("Done!");
        Console.ReadLine();
    }
}

public static void ExtractDocumentToPages(string docName, int fromPage, int pagesCount)
{           
    string folderName = Path.GetDirectoryName(docName);
    string fileName = Path.GetFileNameWithoutExtension(docName);
    string extensionName = Path.GetExtension(docName);
    string outFolder = Path.Combine(folderName, "_out");

    Console.WriteLine("Processing document: " + fileName + extensionName);

    Document doc = new Document(docName);

    // Split nodes in the document into separate pages.
    DocumentPageSplitter splitter = new DocumentPageSplitter(doc);

    Document pageDoc = splitter.GetDocumentOfPageRange(fromPage, fromPage+pagesCount-1); 
    pageDoc.Save(Path.Combine(outFolder, string.Format("{0} -  Out{1}", fileName, extensionName)));
}

The result file contains two pages instead of one. Please note that valid license is applied. The source and the result files are attached to the issue.

problematic_file.docx problematic_file - Out.docx

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
AlexNoskcommented, Oct 7, 2020

@nikola-yankov Page splitter mechanism is integrated into Aspose.Words 20.10. Now you can use Document.ExtractPages method. https://apireference.aspose.com/words/net/aspose.words/document/methods/extractpages I am closing the issue. Please feel free to report any further issue here or in the forum.

0reactions
amruthatscommented, Oct 17, 2020

Hi, I’m using aspose.words 20.10 and I’m trying to fetch the number of pages count for the uploaded document. But It returning very huge and wrong page count.Please help me on this.

private Int32 GetWordPageCount(byte[] docData) { Int32 pages = 1; try { using (MemoryStream dataStream = new MemoryStream(docData)) { StreamReader sr = new StreamReader(dataStream); asw.License lic = new asw.License(); lic.SetLicense(“Aspose.Words.lic”); asw.Document doc = new asw.Document();
asw.DocumentBuilder db = new asw.DocumentBuilder(doc); db.Writeln(sr.ReadToEnd()); sr.Dispose(); sr.Close(); pages = db.Document.PageCount;
} }

Read more comments on GitHub >

github_iconTop Results From Across the Web

PageSplitter Malfunction Aspose.Words.Net 17.3
I see the source code for PageSplitter.cs is built directly into our project. Is that normal? · Where can I get the latest...
Read more >
Page Splitter Redux - KHKonsulting LLC
Split PDF pages in half using either an Acrobat Action or a folder level JavaScript.
Read more >
Use of Splitter in pages with Master page.
Hi,. I am not able to get the splitter feature working in a page that contains master page. If I remove the master...
Read more >
Javascript not working on mobile but works on desktop
As expected, the screen goes blank on my desktop browser for both local and on heroku, but when I test on mobile, the...
Read more >
After adding <Splitter> menu, Back button is not showing ...
The Navigator's next page doesn't have the “Back” Button on top left of the Page (that is the expected behavior). What I noticed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found