Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Dec 27, 2023 7:08 pm

Hi there

I would like to read pdf Invoices. With catchwords it‘s possible to get InvoiceNo, Date and Invoice total. Now i try to fetch the positions.
Did you have an tip how to realize it?

[email protected]
 
Posts: 16
Joined: Sun Jan 17, 2016 12:10 pm

Thu Dec 28, 2023 3:06 am

Hi,

Thank you for your inquiry.
I am pleased to inform you that the following code snippet will help you retrieve the key location information:
Code: Select all
 
// Create a new PdfDocument object
 PdfDocument pdf = new PdfDocument();

 // Load the PDF file from the specified path
 pdf.LoadFromFile(@"..\SpirePDF.pdf");

 // Iterate through each page in the PDF document
 foreach (PdfPageBase page in pdf.Pages)
 {
     // Create a new PdfTextFinder object for the current page
     PdfTextFinder finder = new PdfTextFinder(page);

     // Create a new PdfTextFindOptions object to specify search options
     PdfTextFindOptions options = new PdfTextFindOptions();

     // Set the search parameter to ignore case
     options.Parameter = TextFindParameter.IgnoreCase;

     // Set the search options for the finder
     finder.Options = options;

     // Search for the specified keyword "keywords" in the text of the current page
     var fragments = finder.Find("keywords");

     // Iterate through each found fragment
     foreach (PdfTextFragment fragment in fragments)
     {
         // Get the position of the first occurrence of the keyword in the fragment
         PointF found = fragment.Positions[0];

         // Print the position of the keyword to the console
         Console.WriteLine(found);
     }
 }

You can use this code to extract the key location information from your invoice data. Please let me know if you need any further assistance.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Sat Dec 30, 2023 4:01 pm

Thank you for Feedback.
Is it possible, that the "PdfTextFinder" Classes only available in the "spire.pdf" not in the "freespire.pdf"?

here is an example of my hard Pages...

Image


i have to find the "CusotmerNo", "InvoiceNo" and "InvoiceDate" in the header and the Article Position in the center of the Letter.
there are no "fixwords" to find.

Any tips for that Requirement?

[email protected]
 
Posts: 16
Joined: Sun Jan 17, 2016 12:10 pm

Tue Jan 02, 2024 6:35 am

Hi,

Thank you for your feedback.
For your first requirement, the 'PdfTextFinder' class can only be used in 'spire. pdf' and cannot be used in 'freespire. pdf',
If you want to find fixed words in the title, please download the latest commercial version of Spire.Pdf for .Net 9.12 through the following link.
For your second requirement, the following code snippet will help you locate the article at the center of the letter:
Code: Select all
 
            // Create a new PdfDocument object
            PdfDocument pdf = new PdfDocument();

            // Load the PDF file from the specified path
            pdf.LoadFromFile(@"..\SpirePDF.pdf");

            // Get the first page of the PDF document
            PdfPageBase page = pdf.Pages[0];

            // Get the actual size of the page
            var centerPosition = page.ActualSize;

            // Calculate the center position of the page
            double centerX = centerPosition.Width / 2;
            double centerY = centerPosition.Height / 2;

            // Print the center position to the console
            Console.WriteLine("Center position:({0}, {1})", centerX, centerY);

If above message doesn’t help you please offer your pdf file to help us do further investigation, you can attach here or send it to us via email ([email protected] ). Thank you in advance.

Download Link: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.PDF

cron