Temporarily Hide / Filter Pages in a Document

Discussions about document viewing.
Post Reply
cbingram
Posts: 4
Joined: Fri Oct 22, 2021 4:00 pm

Temporarily Hide / Filter Pages in a Document

Post by cbingram » Fri Dec 17, 2021 11:23 pm

When viewing a document, is it possible to temporarily hide pages of the document from view?

For example, if I want to show only pages that have images on them, and I know which pages those are, is there a way that I can programmatically hide the other pages from view so that I do not see them when scrolling through the document? I would like to do this without having to create a separate temporary document if at all possible.

Thank you!

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Temporarily Hide / Filter Pages in a Document

Post by Fabio » Thu Dec 23, 2021 5:00 pm

Hello there,

Technically it is possible by creating a GdPicture object of a document and modifying that object by deleting the pages without any image on them and loading it back to the viewer.
The real document will keep its integrity and you will be able to save the modified document after.
And if you want to modify the pages and save them back to the initial document, you'll just need to replace them according to the initial positions you saved in an array.

Something like this:

Code: Select all

GdPicturePDF oPDF = new GdPicturePDF();
GdPictureStatus status;

if (oPDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
{
                        
    int i = 1;
    int pageCount = oPDF.GetPageCount();
    if (pageCount > 0)
    {
        while (i <= pageCount)
        {
            oPDF.SelectPage(i);
                            
            int imageCount = oPDF.GetPageImageCount();
            status = oPDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (imageCount == 0)
                {
                    oPDF.DeletePage(i);
                }
            }
            i++;
        }
    }
    oPDF.SaveToFile("output.pdf");
    oPDF.Dispose();
}

Hope it helps!

With best,
Fabio

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest