You are viewing limited content. For full access, please sign in.

Question

Question

SDK :How to check if document page is Empty ( has image or text ) ?

SDK
asked on August 29, 2023

Hello 

I am expiring a document  from Laserfiche using SDK , and I want to loop the document pages , incase the document has a page but empty the code crashes while getting the page thumbnail, it's get page image but with size 0 KB ( okay)

How to check if document page is empty before exporting ?

exporter.PageFormat = DocumentPageFormat.Tiff;
for (int x=1; x<=docInfo.PageCount;x++)
                        {
                            var pagePath = pagesFolder + $"\\{x}.tiff";
                            var thumPath= thumFolder+ $"\\{x}.tiff";
                           // exportpage as a tiff image 
                            using (FileStream Pfs = File.OpenWrite(pagePath))
                            {
                                exporter.ExportPage(docInfo, x, Pfs);
                                listPages.Add(pagePath);
                                
                            }
                            // Export thumbnail for page 
                            using (FileStream Tfs = File.OpenWrite(thumPath))
                            {
                               
                                exporter.ExportThumbnail(docInfo, x, Tfs);
                                listthums.Add(thumPath);

                            }

thanks 

0 0

Answer

SELECTED ANSWER
replied on August 29, 2023 Show version history

The PageInfo object has built-in boolean values for HasImage, HasText, and HasThumbnail.

Something worth noting is that Thumbnails are mostly for the UI side, so it is possible to have a valid page image with no thumbnail. For example, with Replicate Entry in Workflow you can copy an entry without thumbnails meaning they won't be generated until someone accesses the document.

I'm not sure if you're using a standard for loop because you need the index for something else, but you can use a foreach loop in combination with the GetPageInfos method of the DocumentInfo object, then you can check for pages/text inside the loop.

The benefit of this approach is that the PageInfo object is readily available for each iteration so you can easily access its methods and properties, like HasImage or PageNumber.

For example,

foreach (PageInfo page in docInfo.GetPageInfos()){
    if (page.HasImage) {
        // run your code here
    }
}

Instead of using an index to export pages, you can do it by referencing the page number of the current PageInfo object in the foreach loop.

exporter.ExportPage(docInfo, page.PageNumber, Pfs);

 

1 0
replied on August 29, 2023

Hi Jason ,

actually this is what I want ...

Thanks a ton

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.