C# 获取PDF的原始大小
我希望获得与使用Adobe Acrobat将pdf导出为png相同的图像质量 但不知怎么的,这对我不起作用。如果我在Adobe Acrobat工具的帮助下将pdf导出为png,我得到的尺寸是: 宽度:11264像素 高度:15940像素 正如您可能看到的,我为您提供了阅读pdf和创建每页图像的方法。我有可能使用.Render方法,它需要一个int page(index)float dpiX、float dpiY、bool进行打印 但是有些人怎么会对保存的图像没有影响呢C# 获取PDF的原始大小,c#,pdf,pdfium,C#,Pdf,Pdfium,我希望获得与使用Adobe Acrobat将pdf导出为png相同的图像质量 但不知怎么的,这对我不起作用。如果我在Adobe Acrobat工具的帮助下将pdf导出为png,我得到的尺寸是: 宽度:11264像素 高度:15940像素 正如您可能看到的,我为您提供了阅读pdf和创建每页图像的方法。我有可能使用.Render方法,它需要一个int page(index)float dpiX、float dpiY、bool进行打印 但是有些人怎么会对保存的图像没有影响呢 using (var do
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");
}
}
使用(var document=PdfiumViewer.PdfDocument.Load(file))
{
//此int用于获取每个文档的页数
int pagecount=document.pagecount;
//使用int pagecount,我们可以创建尽可能多的屏幕截图,因为文档中有页面
对于(int index=0;index
这可能是一个更好的例子:
使用System.Drawing.Imaging;
字符串Desktop=Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//这张是Spire.Pdf的
无效PDF_到_图像(字符串PDF)
{
var doc=new Spire.Pdf.PdfDocument();
doc.LoadFromFile(pdf);
//此int用于获取每个文档的页数
int pagecount=doc.Pages.Count;
//使用int pagecount,我们可以创建尽可能多的屏幕截图,就像文档中的页面一样
对于(int index=0;index
使用PDFSharp和Migradocs
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create a font
XFont font = new XFont("Times", 25, XFontStyle.Bold);
PageSize[] pageSizes = (PageSize[])Enum.GetValues(typeof(PageSize));
foreach (PageSize pageSize in pageSizes)
{
if (pageSize == PageSize.Undefined)
continue;
// One page in Portrait...
PdfPage page = document.AddPage();
page.Size = pageSize;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString(pageSize.ToString(), font, XBrushes.DarkRed,
new XRect(0, 0, page.Width, page.Height),
XStringFormat.Center);
// ... and one in Landscape orientation.
page = document.AddPage();
page.Size = pageSize;
page.Orientation = PageOrientation.Landscape;
gfx = XGraphics.FromPdfPage(page);
gfx.DrawString(pageSize.ToString() + " (landscape)", font,
XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),
XStringFormat.Center);
}
// Save the document...
string filename = "PageSizes.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
试试看
{
使用(var document=PdfiumViewer.PdfDocument.Load(@“C:\Users\ohernandez\Pictures\img\descarga.pdf”))
{
for(int index=0;index
这还不错,质量仍然不如原始的好,我们可以改进吗?错误参数无效。有没有一个试用版,我没有这个奇怪的标题?我的代码运行得很好,但我正在寻找一个没有标题的更好的解决方案。这应该给你一些选择,关于如何将pdf页面转换为图像,但是Pdf不是一种完全免费的格式,因此在转换时您将失去一些质量。库文件将在几天内被删除,因此任何需要它的人都可以进行更改以获取它们。您想在这里做什么??您知道pdfsharp无法将pdfpage转换为图像吗??它只能在pdfpage上绘制..是的,当您创建pdf文件时会绘制,但当您需要将pdf文件转换为图像时,则不会。。这就是问题所在。非常感谢,工作完美==>PdfRenderFlags.CorrectFromDpi
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create a font
XFont font = new XFont("Times", 25, XFontStyle.Bold);
PageSize[] pageSizes = (PageSize[])Enum.GetValues(typeof(PageSize));
foreach (PageSize pageSize in pageSizes)
{
if (pageSize == PageSize.Undefined)
continue;
// One page in Portrait...
PdfPage page = document.AddPage();
page.Size = pageSize;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawString(pageSize.ToString(), font, XBrushes.DarkRed,
new XRect(0, 0, page.Width, page.Height),
XStringFormat.Center);
// ... and one in Landscape orientation.
page = document.AddPage();
page.Size = pageSize;
page.Orientation = PageOrientation.Landscape;
gfx = XGraphics.FromPdfPage(page);
gfx.DrawString(pageSize.ToString() + " (landscape)", font,
XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),
XStringFormat.Center);
}
// Save the document...
string filename = "PageSizes.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
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);
}
// var image = document.Render(0, 300, 300, true);
// image.Save(@"C:\Users\ohernandez\Pictures\img\output.png", ImageFormat.Png);
}
}
catch (Exception ex)
{
// handle exception here;
}