sungaila / PDFtoImage

A .NET library to render PDF files into images.
https://www.sungaila.de/PDFtoImage/
MIT License
188 stars 24 forks source link

PDF image conversion error #78

Closed xizhengchao closed 6 months ago

xizhengchao commented 8 months ago

PDFtoImage version

4.0.1

OS

Windows

OS version

No response

Architecture

x64

Framework

.NET (Core)

App framework

No response

Detailed bug report

1.pdf PDF image conversion error. This PDF file is a bit large. How can this library solve the problem of converting images from such large files

sungaila commented 8 months ago

Hi @xizhengchao, thank you for opening this issue.

The dimensions of your PDF are extremely large. At default settings (300 DPI) this would result into an image size of 2,517,037 x 2,024,562 pixels.

You should specify either width or height so the resulting image won't be too large.

using var inputPdf = new FileStream("1.pdf", FileMode.Open);
using var outputImage = new MemoryStream();

SavePng(outputImage, inputPdf, options: new(Width: 2000, WithAspectRatio: true, UseTiling: true));

In above example the image will be 2,000 pixels in width, the height is scaled down with the correct aspect ratio. The option UseTiling helps if you want to go for a bigger size.

sungaila commented 6 months ago

Please reopen this issue if the code above did not help.