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 Mar 06, 2024 6:04 am

Hello,

I am using NET 7.0 and Spire.PDF (latest version 10.2.2).

I am trying to extract text from pdf.

The program works on a Windows machine, but when I publish it to a linux server on azur, the application crashes with error:

"The type initializer for 'Gdip' threw an exception"

I suppose it's because "System.Drawing" is not supported on Linux, but how can I configure spire to work correctly on linux?

Thanks,

odellenbach
 
Posts: 1
Joined: Fri Mar 01, 2024 11:25 am

Wed Mar 06, 2024 6:43 am

Hello,

Thanks for your enquiry.
Yes, the issue you mentioned is caused by Linux does not support System.Drawing. To run Spire.Pdf in Linux environment, please download the latest version of the zip file from the official website, after unzipping, please manually import the dll in the netstandard2.0 folder, and then install the following 5 external references through Nuget Manager:
SkiaSharp >= 1.68.0
System.Text.Encoding.CodePages >= 4.5.0
System.Memory >= 4.5.0
System.Buffers >= 4.5.0
System.Runtime.CompilerServices.Unsafe >= 4.5.0


Sincerely,
Annika
E-iceblue support team
User avatar

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

Wed Mar 13, 2024 11:19 am

Hi,

We have the same problem but when we applied your solution we don't know how to extract the images from PDF using the mentioned DLLs. Is it possible that you provide us an example of that?

Thank you and I'm wating news from you!

ManuRubio
 
Posts: 10
Joined: Wed Mar 13, 2024 11:16 am

Thu Mar 14, 2024 2:07 am

Hello,

Thanks for your inquiry.
Please refer to the following code to extract images from the PDF document. If you have any questions, please feel free to write to us at any time.
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
int i = 1;
foreach (PdfPageBase page in pdf.Pages)
{
    Stream[] streams = page.ExtractImages(false);
    foreach (Stream stream in streams) {
        SKBitmap sKBitmap = SKBitmap.Decode(stream);
        using (FileStream fs = new FileStream($"img{i}.png", FileMode.Create))
        {
            using (SKManagedWStream wStream = new SKManagedWStream(fs))
            {
                sKBitmap.Encode(wStream, SKEncodedImageFormat.Png, 100);
            }
        }
        i++;
    }
}


Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Thu Mar 14, 2024 7:56 am

William.Zhang wrote:Hello,

Thanks for your inquiry.
Please refer to the following code to extract images from the PDF document. If you have any questions, please feel free to write to us at any time.
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
int i = 1;
foreach (PdfPageBase page in pdf.Pages)
{
    Stream[] streams = page.ExtractImages(false);
    foreach (Stream stream in streams) {
        SKBitmap sKBitmap = SKBitmap.Decode(stream);
        using (FileStream fs = new FileStream($"img{i}.png", FileMode.Create))
        {
            using (SKManagedWStream wStream = new SKManagedWStream(fs))
            {
                sKBitmap.Encode(wStream, SKEncodedImageFormat.Png, 100);
            }
        }
        i++;
    }
}


Sincerely,
William
E-iceblue support team


Thank you so much! This example is very useful for useful for us.

Best regards!

ManuRubio
 
Posts: 10
Joined: Wed Mar 13, 2024 11:16 am

Thu Mar 14, 2024 8:25 am

Hello,

Thanks for your feedback.
Glad to hear that. If you have any further questions in the future, please feel free to write back.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Fri Mar 15, 2024 8:58 am

Iam using .NET core 8 and Spire.Pdf to fill a PDF form and Save as PDF

Getting this error in .NET core 8

The type initializer for 'Gdip' threw an exception.
please help me out.

shravanAriqt
 
Posts: 1
Joined: Fri Mar 15, 2024 8:54 am

Fri Mar 15, 2024 10:05 am

Hello,

Thanks for you inquiry.
Regarding the issue you mentioned, our previous colleagues have already provided a solution under this topic. Does it not take effect on your end? In addition to the previous solution, you can also install "Spire.Officefor.NETStandard" directly through Nuget to avoid the problems you mentioned.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Mon Mar 18, 2024 10:04 am

William.Zhang wrote:Hello,

Thanks for your inquiry.
Please refer to the following code to extract images from the PDF document. If you have any questions, please feel free to write to us at any time.
Code: Select all
...
    Stream[] streams = page.ExtractImages(false);
...

Sincerely,
William
E-iceblue support team


Hi William,

I have a question about the code line that I keep above from your code. The method "ExtractImages" returns a images array (Image[]) instead of srteam array (Stream[])... I don't know why... Is it possible that it's using another version? In our case, we are using FreeSpire.Pdf 8.6.0?

Thanks for your help! Kind regards!

ManuRubio
 
Posts: 10
Joined: Wed Mar 13, 2024 11:16 am

Tue Mar 19, 2024 1:49 am

Hello,

Thanks for your reply.
Kindly note that our free version does not support running on Net8, to avoid your issue, please install our latest Spire.Officefor.NETStandard 9.2.1 via Nuget.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Wed Mar 20, 2024 11:46 am

ManuRubio wrote:
Hi William,

I have a question about the code line that I keep above from your code. The method "ExtractImages" returns a images array (Image[]) instead of srteam array (Stream[])... I don't know why... Is it possible that it's using another version? In our case, we are using FreeSpire.Pdf 8.6.0?

Thanks for your help! Kind regards!


Hi William,

Can you help me with this issue? I'm trying to deploy my code over linux server but it doesn´t work...

Thanks and I'm waiting your answer!

ManuRubio
 
Posts: 10
Joined: Wed Mar 13, 2024 11:16 am

Thu Mar 21, 2024 4:08 am

Hello,

Thanks for your inquiry.
As previously explained, when your project platform is net6 or above, you need to install our Spire.Officefor.NETStandard 9.2.1. If there are still issues after installation, please provide us with the exception stack information in the project, and we will investigate further.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Mon Mar 25, 2024 12:10 pm

William.Zhang wrote:Hello,

Thanks for your inquiry.
As previously explained, when your project platform is net6 or above, you need to install our Spire.Officefor.NETStandard 9.2.1. If there are still issues after installation, please provide us with the exception stack information in the project, and we will investigate further.

Sincerely,
William
E-iceblue support team


Hello William,

Thanks! Your tips help me to fix my code but... I have new problem... I had a code as:
Code: Select all
/* Create Pdf document */
PdfDocument pdf = new PdfDocument(stream);

/* Extract text from Pdf */
var words = pdf.Pages[0].FindAllText().Finds;

/* Close document */
pdf.Close();


Now, this code doesn't work because the pdf.Pages[0] has not the method "FindAllText". I know that there is another option to extract the text but the advantage which this method ("FindAllText") was that with the word or part of the text had the position (X e Y), information very useful for my code goal...

How did I do this (with Spire.Officefor.NETStandard 9.2.1)?

Thank you !

ManuRubio
 
Posts: 10
Joined: Wed Mar 13, 2024 11:16 am

Tue Mar 26, 2024 2:48 am

Hello,

Thanks for your inquiry.
We have removed the method you mentioned in the new version. Please use the following code snippet to implement your requirements. If you have any further questions, please feel free to write to us at any time.
Code: Select all
PdfPageBase page = doc.Pages[0];
PdfTextFinder pdfTextFinder = new PdfTextFinder(page);
List<PdfTextFragment> pdfTextFragments = pdfTextFinder.FindAllText();
foreach (PdfTextFragment fragment in pdfTextFragments)
{
    RectangleF[] bounds = fragment.Bounds;
}

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF