我想要获得与使用 Adobe Acrobat 中的将 pdf 导出为 png 相同的图像质量。
但不知怎的,这对我不起作用。如果我借助 Adobe Acrobat 工具将 pdf 导出为 png,得到的尺寸为: 宽度:11264 pix 高度:15940 pix
正如您所看到的,我为您提供了阅读 pdf 并在每页创建图像的方法。我的可能性是使用 .Render 方法,它需要int page(index) float dpiX, float dpiY, bool forPrinting
但有些怎么对保存的图像没有影响呢?
using (var document = PdfiumViewer.PdfDocument.Load(file))
{
//This int is used to get the page count for each document
int pagecount = document.PageCount;
//With the int pagecount we can create as may screenshots as there are pages in the document
for (int index = 0; index < pagecount; index++)
{
//render the image created
var image = document.Render(index,8448,11955, true);
//savde the created screenshot temporerlay as a png + number (count)
image.Save(@"C:\Users\chnikos\Desktop\Test\output" + index.ToString("000") + ".png",ImageFormat.Png);
application.Selection.InlineShapes.AddPicture(@"C:\Users\chnikos\Desktop\Test\output" + index.ToString("000") + ".png");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
try
{
using (var document = PdfiumViewer.PdfDocument.Load(@"C:\Users\ohernandez\Pictures\img\descarga.pdf"))
{
for (int index = 0; index < document.PageCount; index++)
{
var image = document.Render(index, 300, 300, PdfRenderFlags.CorrectFromDpi);
image.Save(@"C:\Users\ohernandez\Pictures\img\output.Jpeg" + index.ToString("000") + ".Jpeg", ImageFormat.Jpeg);
}
}
}
catch (Exception ex)
{
// handle exception here;
}
Run Code Online (Sandbox Code Playgroud)