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 Jan 31, 2024 11:33 am

Hello

The Topic is Self Explanatory

I've incorporated your Spire.PDF for VB.Net 2019

I tried incorporating the Code somehow it did not display/View the PDF File in PDF Viewer

Code: Select all
Imports Spire.Pdf
Imports Spire.Pdf.Text is blurred

Public Class PdfTrial

Private Sub PdfTrial_Load(sender as Object, e As EventArgs) Handles MyBase.Load

dim dirPath ="C:\PDF-Files\3.PDF"
'It Works with Following Syntax
PdfDocumentViewer1.LoadFromFile(dirpath)

'But as per your Link
'I changed the above to

dim dirPath ="C:\PDF-Files\3.PDF"

Dim pdfDoc as PdfDocument = New PdfDocument()
pdfDoc.LoadFromFile(dirpath)

'The above syntax probably not loading the File

End Sub


Please Help inorder to have correct syntax as used from your link
Thanks
SamD
1

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Thu Feb 01, 2024 3:16 am

Hello,

Thank you for your inquiry.
I have checked your code. Please note that to display PDF documents in the "PDF Viewer", the code "PdfDocumentViewer1.LoadFromFile(dirpath)" will take effect. However, your code "Dim pdfDoc as PdfDocument = New PdfDocument() pdfDoc.LoadFromFile(dirpath)" is used to manipulate PDF documents in the back-end, and it will not display the documents.
If you want to manipulate PDF documents through code, use the "PdfDocument" class to manipulate them, and then use "PdfDocumentViewer1.LoadFromFile(dirpath)" to load the saved documents and display them in the "PDF Viewer".

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Feb 01, 2024 4:17 am

Thank you Annika

How will one reference PDFDocument Class ? Any syntax or any link if you can share.

Although
"Dim pdfDoc as PdfDocument = New PdfDocument() pdfDoc.LoadFromFile(dirpath)" is used to manipulate PDF documents in the back-end"
and it will not display the documents.


Then When Using
PdfDocumentViewer1.LoadFromFile(dirpath)

How can i Extract Text from the above File into the Textbox1.Text

Will appreciate your great help and valuable input
Thanks
SamD

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Thu Feb 01, 2024 6:09 am

Hello,

Thank you for your feedback.
Please note that the Spire.PDFViewer project depends on the Spire.PdfViewer.dll and Spire.Pdf.dll, so the Spire.PDFViewer project can directly use the PdfDocument class. Please refer to the following example code to extract the text from the PDF document and display it in the Textbox.
Code: Select all
PdfDocumentViewer1.LoadFromFile(dirpath)

' Create a new PDF document object
Dim pdfDoc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument()

' Load the PDF file from the specified path into the PDF document object
pdfDoc.LoadFromFile(dirpath)

' Initialize a string variable to store the extracted text
Dim text As String = Nothing

' Iterate through each page in the PDF document
For Each page As Spire.Pdf.PdfPageBase In pdfDoc.Pages

     ' Create a PDF text extractor object to extract text from the current page
    Dim textExtractor As Spire.Pdf.Texts.PdfTextExtractor = New Spire.Pdf.Texts.PdfTextExtractor(page)

    ' Create an extraction options object and set the extraction options
    Dim extractOptions As Spire.Pdf.Texts.PdfTextExtractOptions = New Spire.Pdf.Texts.PdfTextExtractOptions
    extractOptions.IsExtractAllText = True

    ' Extract the text from the current page and append it to the text variable
    text += textExtractor.ExtractText(extractOptions)

Next page

' Display the extracted text in the TextBox control
TextBox1.Text = text

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Feb 01, 2024 9:05 am

Thanks Annika for your valuable input

I just copied the code as provided by you

I am afraid Nothing is Displayed in Textbox1.Text

SamD
3

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Thu Feb 01, 2024 9:44 am

Hello,

Thank you for your feedback.
The code I provided to you worked when I tested it. Therefore, I have packaged a simple test project for you to download and test. The project includes input documents, etc., and can be directly opened and run using Visual Studio.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Feb 01, 2024 11:13 am

Dear Annika

Thank you for sending the File.

It worked.

Also I changed my other PDF file and it came as per your coding. Thank you so much

One observation the file previously which is still not loading / not displaying seems to be completely non editable. Even you can't select Text nor allows mouse to select it from that PDF file and copy it. But other Normal PDF file text was extracted.

Any Ideas for those .PDF files which just opens in MS-Edge Acrobat PDF etc but no OPTION to select any Text. How these PDF Files are created.
It seems in this file everything is having dull text display. (may be Generates as Scanned PDF). Not really sure. But Am afraid will not be able to this file as the data is Confidential.

Will also appreciate if any code is available to check these type of PDF files

Thanks
SamD
4

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Fri Feb 02, 2024 3:36 am

Hello,

Thank you for your feedback.
Regarding the scanned PDF file you mentioned, we do not support directly extracting text from it, but you can first convert the scanned PDF file to an image, and then use our Spire.OCR component to extract the text from the image, and then finally display the extracted text into the text box. For more information about the use of Spire.OCR, please refer to this tutorial.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Feb 02, 2024 5:32 am

Thank you Annika

Indeed your efforts are great showing step by step with minute details.

Before starting the new project as shown by you

Just would like to know instead of VB Console App(.NET Framework) Though as per tutorial you have showed C#

Can I begin the New Project with Windows Forms App(.Net Framework) [Visual Basic]

FYI the above Spire Codes you have sent has been already created with Windows Forms App(.Net Framework)

Thanks and Regards
SamD
5

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Fri Feb 02, 2024 7:11 am

Hi Annika

I installed Spire.OCR 1.8.0 But I am only interested if you could change the below code appropriately from C# to Vb.Net
I am only interested in getting the text from Image file only

Thanks

Code: Select all
using Spire.OCR;
using System.IO;
 
namespace ReadTextFromImage
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Specify the path of the input image file
            string imageFilePath = "Image.png";
            //Specify the path of the output text file
            string outputFilePath = "ScanImage.txt";
 
            //Call the ScanTextFromImage method to scan text from an image
            string scannedText = ScanTextFromImage(imageFilePath);
 
            //Write the text to the specified file
            File.WriteAllText(outputFilePath, scannedText);
        }
        public static string ScanTextFromImage(string imageFilePath)
        {
            //Instantiate an OcrScanner object
            using (OcrScanner ocrScanner = new OcrScanner())
            {
                //Scan text from the image
                ocrScanner.Scan(imageFilePath);
 
                //Get the recognized text from the OcrScanner object
                IOCRText text = ocrScanner.Text;
 
                //Return the text
                return text.ToString();
            }
        }
    }
}

SamD
6

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Fri Feb 02, 2024 7:46 am

Hello,

Thank you for your feedback.
Please note that Console App and Windows Forms App are just two different project types, but the code about our products in the program is the same.
Also, the tutorial I provided you with has sample code for VB.NET, which can be seen by clicking the VB.NET button next to C#. The VB code you mentioned to extract text from images using Spire.OCR, please refer to the following:
Code: Select all
Imports Spire.OCR
Imports System.IO

Namespace ReadTextFromImage
   
    Class Program
       
        Private Shared Sub Main(ByVal args() As String)
            'Specify the path of the input image file
            Dim imageFilePath As String = "Image.png"
            'Specify the path of the output text file
            Dim outputFilePath As String = "ScanImage.txt"
            'Call the ScanTextFromImage method to scan text from an image
            Dim scannedText As String = Program.ScanTextFromImage(imageFilePath)
            'Write the text to the specified file
            File.WriteAllText(outputFilePath, scannedText)
        End Sub
       
        Public Shared Function ScanTextFromImage(ByVal imageFilePath As String) As String
            'Instantiate an OcrScanner object
            Dim ocrScanner As OcrScanner = New OcrScanner
            'Scan text from the image
            ocrScanner.Scan(imageFilePath)
            'Get the recognized text from the OcrScanner object
            Dim text As IOCRText = ocrScanner.Text
            'Return the text
            Return text.ToString
        End Function
    End Class
End Namespace

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Feb 02, 2024 9:25 am

Annika

Thanks for the response
Annika's response
Also, the tutorial I provided you with has sample code for VB.NET, which can be seen by clicking the VB.NET button next to C#. The VB code you mentioned to extract text from images using Spire.OCR, please refer to the following:


I got from
https://www.e-iceblue.com/en/other/csharp-extract-text-from-images-and-scanned-pdfs.html#2

and There is no VB.net provision that is seen. for this reason i asked.

Also I got error as
spr[]: 'Error occurred during ocr.'

Inner Exception
BadImageFormatException: An attempt was made to load a program with an incorrect format.
(Exception from HRESULT:0x800700B)

Code: Select all
Private Sub PdfTrial_Load(sender as Object, e As EventArgs) Handles MyBase.Load
Dim imgPath As String ="C:\PDF-Files\Wo.png"
Dim scannedText As String = ScanTextFromImage(imgPath)
End Sub


Public Shared Function ScanTextFromImage(ByVal imageFilePath As String) As String
            'Instantiate an OcrScanner object
            Dim ocrScanner As Spire.OCR.OcrScanner = New Spire.OCR.OcrScanner
            'Scan text from the image
            ocrScanner.Scan(imageFilePath)    '<---GOT ERROR HERE
            'Get the recognized text from the OcrScanner object
            Dim text As IOCRText = ocrScanner.Text
            'Return the text
            Return text.ToString
        End Function
    End Class


SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Fri Feb 02, 2024 9:59 am

Hello,

Thanks for your feedback.
Is your project platform target set to "X64"? Our Spire.OCR only supports 64-bit projects. Also, have you imported the 6 dlls in the "Spire.OCR.1.8.0\runtimes\win-x64\native" directory into the Debug folder of your project? If these are correct, please provide us with your test images for further investigation. Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Feb 02, 2024 11:14 am

Thank you Annika

Your Steps have indeed helped. Text of the .Png/.jpg file is seen but with Evaluation Warning comes up. How can i avoid the warning ?

Annika's response
Also, have you imported the 6 dlls in the "Spire.OCR.1.8.0\runtimes\win-x64\native" directory into the Debug folder of your project?

Already the 6 dll file have been automatically created in the native folder. Why do i then deed to copy the files into debug folder

Any Spire.PDF tool to view the image file with its respective path

Regards
SamD
8

SamDsouza
 
Posts: 23
Joined: Wed Jan 31, 2024 11:05 am

Sun Feb 04, 2024 3:36 am

Hello,

Thank you for your feedback.
Firstly, regarding your inquiry about removing the evaluation warning from Spire.OCR, it requires a valid license for Spire.OCR. You can apply for a free temporary license valid for one month through this link [https://www.e-iceblue.com/TemLicense.html]. Once you have obtained the license, you can use it to remove the evaluation warning.

Secondly, the reason for copying the 6 DLL files to the Debug folder of your testing project is because these DLL files are essential external dependencies. By placing them in the Debug folder, you ensure that these dependencies are fully functional and accessible during the testing process.

Lastly, concerning your request for a tool to view image files with their respective paths, please note that Spire.PDF is primarily designed for backend operations on PDF files. It does not provide a built-in image viewer. However, if you are looking for a tool specifically for viewing PDF files, you can consider using Spire.PDFViewer, which is designed for this purpose. Please note that Spire.PDFViewer does not support the direct viewing of image files.

If you have any further questions or need assistance with any other aspect, please feel free to let us know.
Thank you for your understanding.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron