Skip to content

Commit 94b04d9

Browse files
authored
Merge pull request #1482 from syncfusion-content/pdftoimageconverter
UG Content for PdfToImageConverter
2 parents 27c400f + 47d69a4 commit 94b04d9

7 files changed

+114
-35
lines changed

File-Formats-toc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@
678678
<li>
679679
PDF to Image
680680
<ul>
681-
<li>Getting Started
681+
<li><a href="/file-formats/pdf-to-image/Convert-PDF-to-Image">Getting Started</a>
682682
<ul>
683683
<li><a href="/file-formats/pdf-to-image/Convert-PDF-file-to-Image-in-ASP-NET-Core">ASP.NET Core</a></li>
684684
<li><a href="/file-formats/pdf-to-image/Convert-PDF-file-to-Image-in-ASP-NET-MVC">ASP.NET MVC</a></li>

File-Formats/PDF-to-image/Convert-PDF-file-to-Image-in-ASP-NET-MVC.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
5858
imageConverter.Load(inputStream);
5959
//Convert PDF to Image.
6060
Stream outputStream = imageConverter.Convert(0, false, false);
61-
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");
61+
MemoryStream stream = outputStream as MemoryStream;
62+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");
6263

6364
{% endhighlight %}
6465

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Convert PDF to Image| Syncfusion
3+
description: Learn how to convert a PDF to Image with easy steps using PDFToImageConverter library.
4+
platform: file-formats
5+
control: PDF to image
6+
documentation: UG
7+
keywords: Assemblies
8+
---
9+
10+
# Convert PDF to Image
11+
12+
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.
13+
14+
<b>NuGet</b>
15+
16+
<table>
17+
<tr>
18+
<thead>
19+
<th><b>Platform(s)</b></th>
20+
<th><b>NuGet Package</b></th>
21+
</thead>
22+
</tr>
23+
<tr>
24+
<td>
25+
Windows Forms
26+
</td>
27+
<td>
28+
{{'[Syncfusion.PdfToImageConverter.WinForms.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.WinForms/)'| markdownify }}
29+
</td>
30+
</tr>
31+
<tr>
32+
<td>
33+
WPF
34+
</td>
35+
<td>
36+
{{'[Syncfusion.PdfToImageConverter.WPF.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.WPF/)'| markdownify }}
37+
</td>
38+
</tr>
39+
<tr>
40+
<td>
41+
ASP.NET Core Windows
42+
</td>
43+
<td>
44+
{{'[Syncfusion.PdfToImageConverter.Net.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.Net/)'| markdownify }}
45+
</td>
46+
</tr>
47+
<tr>
48+
<td>
49+
ASP.NET MVC Windows
50+
</td>
51+
<td>
52+
{{'[Syncfusion.PdfToImageConverter.AspNet.Mvc4.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.AspNet.Mvc4/)'| markdownify }}<br/>
53+
{{'[Syncfusion.PdfToImageConverter.AspNet.Mvc5.nupkg](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.AspNet.Mvc5/)'| markdownify }}
54+
</td>
55+
</tr>
56+
</table>
57+
58+
N> The above mentioned NuGet packages are available in [nuget.org](https://www.nuget.org/).
59+
60+
The following code snippet illustrates how to convert PDF page into image using Convert method in PdfToImageConverter.
61+
62+
{% tabs %}
63+
{% highlight c# tabtitle="C# [Cross-platform]" %}
64+
65+
//Initialize PDF to Image converter.
66+
PdfToImageConverter imageConverter = new PdfToImageConverter();
67+
//Load the PDF document as a stream
68+
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);
69+
imageConverter.Load(inputStream);
70+
//Convert PDF to Image.
71+
Stream outputStream = imageConverter.Convert(0, false, false);
72+
MemoryStream stream = outputStream as MemoryStream;
73+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");
74+
75+
{% endhighlight %}
76+
77+
{% highlight c# tabtitle="C# [Windows-specific]" %}
78+
79+
//Initialize PDF to Image converter.
80+
PdfToImageConverter imageConverter = new PdfToImageConverter();
81+
//Load the PDF document as a stream
82+
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);
83+
imageConverter.Load(inputStream);
84+
//Convert PDF to Image.
85+
Stream outputStream = imageConverter.Convert(0, false, false);
86+
Bitmap image = new Bitmap(outputStream);
87+
image.Save("sample.png");
88+
89+
90+
{% endhighlight %}
91+
{% highlight vb tabtitle="VB.NET [Windows-specific]" %}
92+
93+
'Initialize PDF to Image converter.
94+
Dim imageConverter As PdfToImageConverter = New PdfToImageConverter()
95+
'Load the PDF document as a stream
96+
Dim inputStream As FileStream = New FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite)
97+
imageConverter.Load(inputStream)
98+
'Convert PDF to Image.
99+
Dim outputStream As Stream = imageConverter.Convert(0, False, False)
100+
Dim image As Bitmap = New Bitmap(outputStream)
101+
image.Save("sample.png")
102+
103+
{% endhighlight %}
104+
105+
{% endtabs %}
106+
107+
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/WPF-PDFViewer-Examples/tree/master/PDF-to-image).
108+
109+
N> To know more about PdfToImageConverter and features it provides, please refer to [PdfToImageConverter](https://help.syncfusion.com/file-formats/pdf-to-image)

File-Formats/PDF-to-image/Converting-PDF-pages-into-Images-in-ASP-NET-Core.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
2424
imageConverter.Load(inputStream);
2525
//Convert PDF to Image.
2626
Stream outputStream = imageConverter.Convert(0, false, false);
27-
Bitmap image = new Bitmap(outputStream);
28-
image.Save("sample.png");
2927

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

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

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

10393
{% endhighlight %}
10494
{% endtabs %}

File-Formats/PDF-to-image/Converting-PDF-pages-into-Images-in-ASP-NET-MVC.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
2424
imageConverter.Load(inputStream);
2525
//Convert PDF to Image.
2626
Stream outputStream = imageConverter.Convert(0, false, false);
27-
Bitmap image = new Bitmap(outputStream);
28-
image.Save("sample.png");
2927

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

5649
{% endhighlight %}
5750
{% endtabs %}
@@ -97,11 +90,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
9790
imageConverter.Load(inputStream);
9891
//Convert PDF to Image.
9992
Stream[] outputStream = imageConverter.Convert(startPageIndex, endPageIndex, dpiX, dpiY, false, false);
100-
for(int i=0; i < outputStream.Length; i++)
101-
{
102-
Bitmap image = new Bitmap(outputStream[i]);
103-
image.Save("sample-"+i+".png");
104-
}
10593

10694
{% endhighlight %}
10795
{% endtabs %}

File-Formats/PDF-to-image/Converting-PDF-pages-into-Images-in-Blazor.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
2424
imageConverter.Load(inputStream);
2525
//Convert PDF to Image.
2626
Stream outputStream = imageConverter.Convert(0, false, false);
27-
Bitmap image = new Bitmap(outputStream);
28-
image.Save("sample.png");
2927

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

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

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

10393
{% endhighlight %}
10494
{% endtabs %}

File-Formats/PDF/Working-with-Document-Conversions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,8 @@ FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.R
12271227
imageConverter.Load(inputStream);
12281228
//Convert PDF to Image.
12291229
Stream outputStream = imageConverter.Convert(0, false, false);
1230-
return File(outputStream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Png, "sample.png");
1230+
MemoryStream stream = outputStream as MemoryStream;
1231+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");
12311232

12321233
{% endhighlight %}
12331234

0 commit comments

Comments
 (0)