How to Analyze the First and Last Pages of a Document in DotNet 7

Praveen Patil 0 Reputation points
2023-10-31T00:39:10.8733333+00:00

Is there a way to analyze only the first and last pages of a document in my DotNet 7 program? Below is the code I'm currently using, but it is only analyzing the first page and ignoring the rest:

AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, modelId, fileUri, new AnalyzeDocumentOptions() { Pages = { "1", "-1" } });
Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,718 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,741 Reputation points
    2023-10-31T12:52:12.3333333+00:00

    Thanks for the question, One workaround could be to first determine the total number of pages in your document, and then use that number instead of -1.Here’s an example of how you can determine the number of pages in a PDF file using iTextSharp.

    using iTextSharp.text.pdf;

    PdfReader pdfReader = new PdfReader(pdfFilePath);

    int numberOfPages = pdfReader.NumberOfPages;

    Once you have the total number of pages, you can modify your AnalyzeDocumentOptions to analyze the first and last pages like this:

    AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, modelId, fileUri, new AnalyzeDocumentOptions() { Pages = { "1", numberOfPages.ToString() } });

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.