Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion File-Formats-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@
<li>
PDF to Image
<ul>
<li>Getting Started
<li><a href="/file-formats/pdf-to-image/Convert-PDF-to-Image">Getting Started</a>
<ul>
<li><a href="/file-formats/pdf-to-image/Convert-PDF-file-to-Image-in-ASP-NET-Core">ASP.NET Core</a></li>
<li><a href="/file-formats/pdf-to-image/Convert-PDF-file-to-Image-in-ASP-NET-MVC">ASP.NET MVC</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");
MemoryStream stream = outputStream as MemoryStream;
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");

{% endhighlight %}

Expand Down
109 changes: 109 additions & 0 deletions File-Formats/PDF-to-image/Convert-PDF-to-Image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: Convert PDF to Image| Syncfusion
description: Learn how to convert a PDF to Image with easy steps using PDFToImageConverter library.
platform: file-formats
control: PDF to image
documentation: UG
keywords: Assemblies
---

# Convert PDF to Image

This PDF to image converter library allows converting PDF documents to images without opening the document in the PDF Viewer control. It allows you to selectively export pages as a stream by utilizing the 'Convert' method, facilitating the transformation of PDF files into images.

<b>NuGet</b>

<table>
<tr>
<thead>
<th><b>Platform(s)</b></th>
<th><b>NuGet Package</b></th>
</thead>
</tr>
<tr>
<td>
Windows Forms
</td>
<td>
{{'[Syncfusion.PdfToImageConverter.WinForms.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.WinForms/)'| markdownify }}
</td>
</tr>
<tr>
<td>
WPF
</td>
<td>
{{'[Syncfusion.PdfToImageConverter.WPF.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.WPF/)'| markdownify }}
</td>
</tr>
<tr>
<td>
ASP.NET Core Windows
</td>
<td>
{{'[Syncfusion.PdfToImageConverter.Net.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.Net/)'| markdownify }}
</td>
</tr>
<tr>
<td>
ASP.NET MVC Windows
</td>
<td>
{{'[Syncfusion.PdfToImageConverter.AspNet.Mvc4.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.AspNet.Mvc4/)'| markdownify }}<br/>
{{'[Syncfusion.PdfToImageConverter.AspNet.Mvc5.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.AspNet.Mvc5/)'| markdownify }}
</td>
</tr>
</table>

N> The above mentioned NuGet packages are available in [nuget.org](https://www.nuget.org/).

The following code snippet illustrates how to convert PDF page into image using Convert method in PdfToImageConverter.

{% tabs %}
{% highlight c# tabtitle="C# [Cross-platform]" %}

//Initialize PDF to Image converter.
PdfToImageConverter imageConverter = new PdfToImageConverter();
//Load the PDF document as a stream
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
MemoryStream stream = outputStream as MemoryStream;
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");

{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}

//Initialize PDF to Image converter.
PdfToImageConverter imageConverter = new PdfToImageConverter();
//Load the PDF document as a stream
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");


{% endhighlight %}
{% highlight vb tabtitle="VB.NET [Windows-specific]" %}

'Initialize PDF to Image converter.
Dim imageConverter As PdfToImageConverter = New PdfToImageConverter()
'Load the PDF document as a stream
Dim inputStream As FileStream = New FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite)
imageConverter.Load(inputStream)
'Convert PDF to Image.
Dim outputStream As Stream = imageConverter.Convert(0, False, False)
Dim image As Bitmap = New Bitmap(outputStream)
image.Save("sample.png")

{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/WPF-PDFViewer-Examples/tree/master/PDF-to-image).

N> To know more about PdfToImageConverter and features it provides, please refer to [PdfToImageConverter](https://help.syncfusion.com/file-formats/pdf-to-image)
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");

{% endhighlight %}
{% endtabs %}
Expand All @@ -47,11 +45,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount-1, false, false);
for(int i=0; i < outputStream.Length; i++)
{
Bitmap image = new Bitmap(outputStream[i]);
image.Save("sample-"+i+".png");
}

{% endhighlight %}
{% endtabs %}
Expand All @@ -70,8 +63,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, new SizeF(1836, 2372), false, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");

{% endhighlight %}
{% endtabs %}
Expand All @@ -98,7 +89,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, zoomFactor, tileXCount, tileYCount, tileX, tileY);
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");

{% endhighlight %}
{% endtabs %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");

{% endhighlight %}
{% endtabs %}
Expand All @@ -47,11 +45,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount-1, false, false);
for(int i=0; i < outputStream.Length; i++)
{
Bitmap image = new Bitmap(outputStream[i]);
image.Save("sample-"+i+".png");
}

{% endhighlight %}
{% endtabs %}
Expand Down Expand Up @@ -97,11 +90,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream[] outputStream = imageConverter.Convert(startPageIndex, endPageIndex, dpiX, dpiY, false, false);
for(int i=0; i < outputStream.Length; i++)
{
Bitmap image = new Bitmap(outputStream[i]);
image.Save("sample-"+i+".png");
}

{% endhighlight %}
{% endtabs %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");

{% endhighlight %}
{% endtabs %}
Expand All @@ -47,11 +45,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount-1, false, false);
for(int i=0; i < outputStream.Length; i++)
{
Bitmap image = new Bitmap(outputStream[i]);
image.Save("sample-"+i+".png");
}

{% endhighlight %}
{% endtabs %}
Expand All @@ -70,8 +63,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, new SizeF(1836, 2372), false, false, false);
Bitmap image = new Bitmap(outputStream);
image.Save("sample.png");

{% endhighlight %}
{% endtabs %}
Expand All @@ -98,7 +89,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, zoomFactor, tileXCount, tileYCount, tileX, tileY);
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");

{% endhighlight %}
{% endtabs %}
3 changes: 2 additions & 1 deletion File-Formats/PDF/Working-with-Document-Conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,8 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
imageConverter.Load(inputStream);
//Convert PDF to Image.
Stream outputStream = imageConverter.Convert(0, false, false);
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");
MemoryStream stream = outputStream as MemoryStream;
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");

{% endhighlight %}

Expand Down