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.

Mon Jul 04, 2022 8:53 am

Hi,
When I use Spire.pdf library and try to save page as image, the image has extra white area on top of the image.
Attached is example of pdf file and saved image, pdf file text is much closer to the top of the page while the text on the image is centered.
This happens on multiple pdf files I tried, every image has white area on top, and bottom of pdf file does not appear on image.
Can you take a look?

This is the code I am using:
Code: Select all
 PdfDocument pdfDocument = new PdfDocument(@"C:\New folder\1.pdf");
                            string outputFile = @"C:\New folder\1.jpg";
                            Stream imageStream = pdfDocument.SaveAsImage(0);
                            using (var fileStream = File.Create(outputFile))
                            {
                                imageStream.Seek(0, SeekOrigin.Begin);
                                imageStream.CopyTo(fileStream);
                            }


Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Mon Jul 04, 2022 10:12 am

Hi Filip,

I tested this case and do not reproduce the issue.
I noticed in your code that pdfDocument.SaveAsImage(0) returns a stream. I guess this is the cause of the problem.
From previous questions I knew that your project is .NET CORE 2.1. I guess you are referencing the dlls under the netstandard2.0 folder (see screenshot below).
FA66EFC7-B5E1-4a75-9972-1791B2EEB702.png

But actually you should use the dlls from netcoreapp2.0 and change the code:

Code: Select all
            PdfDocument pdfDocument = new PdfDocument(@"1.pdf");
            string outputFile = @"1.jpg";
            pdfDocument.SaveAsImage(0).Save(outputFile,System.Drawing.Imaging.ImageFormat.Jpeg);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Jul 04, 2022 12:29 pm

Thanks, it works.

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Jul 05, 2022 8:15 am

You are welcome!
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Jul 22, 2022 8:57 am

Hi,
I have changed nuget package to Spire.Officefor.NETStandard (latest version) from nuget
because you have written me that to resolve issue in thread extracting-text-from-pdf-does-not-work-on-ubuntu-t11365.html.

After changing nuget package saving pdf page to image does not work correctly on Windows 10 machine.

This is the code I am using:
CODE: SELECT ALL
PdfDocument pdfDocument = new PdfDocument(@"C:\New folder\1.pdf");
string outputFile = @"C:\New folder\1.jpg";
Stream imageStream = pdfDocument.SaveAsImage(0);
using (var fileStream = File.Create(outputFile))
{
imageStream.Seek(0, SeekOrigin.Begin);
imageStream.CopyTo(fileStream);
}

I will send you the pdf file to support@e-iceblue.com.

The method "Save" you wrote me to use:
pdfDocument.SaveAsImage(0).Save(outputFile,System.Drawing.Imaging.ImageFormat.Jpeg);
does not exist when I use Spire.Officefor.NETStandard nuget package.

Can you help?

Thanks,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Fri Jul 22, 2022 10:35 am

Hi Filip,

For Spire.Officefor.NETStandard, you should use the following code to convert pdf to images.
Code: Select all
                            Stream imageStream = pdfDocument.SaveAsImage(0);
                            using (var fileStream = File.Create(outputFile))
                            {
                                imageStream.Seek(0, SeekOrigin.Begin);
                                imageStream.CopyTo(fileStream);
                            }

But for Spire.Office(when you refer the dlls from "netcoreapp2.0" folder), you should use the following code to convert pdf to images.
Code: Select all
            PdfDocument pdfDocument = new PdfDocument(@"1.pdf");
            string outputFile = @"1.jpg";
            pdfDocument.SaveAsImage(0).Save(outputFile,System.Drawing.Imaging.ImageFormat.Jpeg);


When you use .netcore project under windows platform, you better use the dlls from "netcoreapp2.0" folder under Spire.Office package. And when you use .netcore project under non-windows platform, you can use dlls from "netstandard2.0" folder under Spire.Office package or install Spire.Officefor.NETStandard package directly from Nuget.

The processing of the image are different in these two cases, so the corresponding code are also different.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Jul 25, 2022 9:00 am

Hi,
I have changed nuget package to Spire.Officefor.NETStandard (latest version) and I am using the code you wrote me:

Code: Select all
Stream imageStream = pdfDocument.SaveAsImage(0);
                            using (var fileStream = File.Create(outputFile))
                            {
                                imageStream.Seek(0, SeekOrigin.Begin);
                                imageStream.CopyTo(fileStream);
                            }


But the result when converting pdf page to image is not good.
I have sent you the pdf file and image result to support@e-iceblue.com on Fri 22-Jul-2022 11:00 AM.

Can you take a look?

Thanks,
Filip

Thanks,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Mon Jul 25, 2022 9:26 am

Hi Filip,

Thanks for your response.

Sorry, I didn't pay much attention to that picture at the time. The pictures I converted are also the same as you provided. There is a lot of content missing. I have logged this issue in our bug tracking system with the ticket SPIREPDF-5376. Apologize for the inconvenience again.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Aug 04, 2022 12:34 pm

Hi,

Do you have some information from your developer team, is this possible to fix
or do you have some estimate on when we can expect a new version of spire.pdf where this is fixed?

Thanks,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Fri Aug 05, 2022 10:21 am

Hi Filip,

Our developers have completed preliminary fixes. This issue is about to enter into testing. After passing the test, we will provide you with the fixed version in time.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Aug 17, 2022 10:48 am

Hi Filip,

Thanks for your patience!

Glad to inform you that we just released Spire.Office Version:7.8.4 which fixes your issue SPIREPDF-5376.

Please download the fix version from the following links to test.
Website link:
https://www.e-iceblue.com/Download/down ... t-now.html
Nuget:
https://www.nuget.org/packages/Spire.Office/7.8.4
https://www.nuget.org/packages/Spire.Of ... dard/7.8.4
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Aug 29, 2022 1:40 pm

Thanks, it works with new version of Spire.Officefor.NETStandard nuget package!

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Sep 20, 2022 6:31 am

Hello,

Thanks for your feedback.
We're glad to hear that it solved your issue.

Please feel free to contact us if you have any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF