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.

Thu Mar 19, 2020 7:52 am

Hi everyone!
I have a problem in my project.
Code: Select all
            PdfDocument document = new PdfDocument();
            document.LoadFromFile(@"C:\Users\Test\OneDrive\Desktop\test.pdf");
            PdfDocument newPdf = new PdfDocument();
            newPdf.PageSettings.Margins.All = 0;
            document.PageSettings.Margins.All = 0;
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfPageBase page = document.Pages[0];
            double height = unitCvtr.ConvertUnits((float)page.Size.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
            double width = unitCvtr.ConvertUnits((float)page.Size.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
            PdfPageBase newPage = newPdf.Pages.Add(new SizeF((float)width * 10, (float)height * 10));
 loLayout.Layout = PdfLayoutType.OnePage;
            page.CreateTemplate().Draw(newPage, new PointF(0, 0), loLayout);
 Image bmp = newPdf.SaveAsImage(0);



This could resize the input pdf, debugging the code it works but when i call the function SaveAsImage, the output image is scaled regard to the original pdf, and i can't understand why?
Anyone could help me?

hakzi9898
 
Posts: 7
Joined: Wed Mar 18, 2020 7:59 pm

Thu Mar 19, 2020 9:17 am

Hello,

Thanks for your inquiry.
I tested your code with the latest Spire.PDF Pack(Hot Fix) Version:6.3.0, but the generated image is scaled regard to resized PDF file. If you are using an old version, please download the latest version and try again.
If the issue still occurs, please provide your input file and your environment information, such as OS information (E.g. Windows 7, 64bit) and Region setting (E.g. China, Chinese) for further investigation.

Besides, we provide a direct method to convert PDF to image with specified resolution. If you just want to convert PDF to high resolution images, you can refer to following code.
Code: Select all
    //public Image SaveAsImage(int pageIndex, int dpiX, int dpiY);
    Image bmp = document.SaveAsImage(0, 500, 500);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Mar 19, 2020 11:37 am

It is not. The pdf is 37833 x 3061 while the output image is 5044 x 408.
Pdf size is big

hakzi9898
 
Posts: 7
Joined: Wed Mar 18, 2020 7:59 pm

Fri Mar 20, 2020 8:15 am

Hello,

Thanks for your response.
I learned from our Dev team that if the page width or height is too large (>10,000 pixel), when using the method SaveAsImage to save the image, our product will appropriately compress the image size. You mentioned the size of your pdf file is 37833 x 3061, it exceeds 10,000, thus the output image size will be compressed.
If you want to get high resolution images, I'm afraid using the code I provided above is the better solution for you.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF