Click here to Skip to main content
16,018,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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 
Posted
Updated 12-Nov-17 21:12pm

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);

}
 
Share this answer
 
v2
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...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900