使用spire.pdf将pdf转换为高质量的wpf图像 [英] Convert pdf to image with high quality in wpf using spire.pdf

查看:1638
本文介绍了使用spire.pdf将pdf转换为高质量的wpf图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi i'm using spire.pdf for .net to convert my pdf document to image with  wpf but i faced one problem when converting pdf document to bitmapsource image the c# error is " can't implicitly convert system.drawing.imaging to system.windows.media.bitmapsource " 

我的代码是



my code is

private void button1_Click(object sender, RoutedEventArgs e)
      {
          PdfDocument pdf = new PdfDocument();
          pdf.LoadFromFile("sample.pdf");

          BitmapSource source;
          Bitmap bmp;

          for (int i = 1; i < pdf.Pages.Count+1; i++)
          {
              source =  pdf.SaveAsImage(i);
              bmp = SourceToBitmap(source);
              bmp.Save(string.Format("result-{0}.jpeg", i), ImageFormat.Jpeg);
          }
      }







<pre lang="text"> error in the line of " source = pdf.saveasimage(i); " please help me how to solve this problem 

推荐答案

PdfDocument pdf = new PdfDocument();

pdf.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory +" Resources // PDF.pdf");



// BitmapSource src;

//位图bmp;



for(int i = 1; i< pdf.Pages.Count + 1; i ++)

{

var src = pdf.SaveAsImage(i-1);

// bmp = SourceToBitmap(source) ;

src.Save(string.Format(" results- {0} .png",i),ImageFormat.Jpeg);



}
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory + "Resources//PDF.pdf");

// BitmapSource src;
//Bitmap bmp;

for (int i = 1; i < pdf.Pages.Count + 1; i++)
{
var src = pdf.SaveAsImage(i-1);
//bmp = SourceToBitmap(source);
src.Save(string.Format("results-{0}.png", i), ImageFormat.Jpeg);

}


在大多数编程语言中,数组索引从0开始,所以你的循环标题应如下所示。

In most programming languages, array indexes start from 0 so your loop header should look like this.
for (int i = 0; i < pdf.Pages.Count; i++)



等......


and so on...


这篇关于使用spire.pdf将pdf转换为高质量的wpf图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆