How to Export PDF Page AS Image with C#/VB.NET

Actually, PDF becomes more and more popular at present. Because of its wonderful reading effect, many people use it to create e-books or magazines. Although PDF document is very convenient for reading, printing and sending, someone may want to convert PDF to other format for some special requirements or just convert some of pages in PDF as other format.

In this post, I want to introduce a method about how to export pages in PDF as image by using C#/VB.NET.

As is known, a PDF document may have several pages. The example I will show focuses on exporting one page in document as image. The image format can be set by own when saving image.

Also, a component, Spire.PDFViewer is used for realizing this function. So, I have added its dll file as reference in project.

Detailed Steps Shown as Following:           

Step 1, Create a Window Form Project and Design Form

Because I need to use Spire.PDFViewer controls, so I need to add them into VS Toolbar as following:

Then, design form. Add a PDFDocumentViewer and a button. Change button text as Export PDF Page AS Image.

Step 2, Double Click Button to Write Code

Step 3, Load PDF Document

Because PDF document content will be shown in PDFDocumentViewer control, so use this.pdfDocumentViewer1.LoadFromFile() method.


        private void Form1_Load(object sender, EventArgs e)
            this.pdfDocumentViewer1.LoadFromFile(@”E:\work\Documents\Troubleshooting Guide Template.pdf”);


        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            Me.pdfDocumentViewer1.LoadFromFile(“E:\work\Documents\Troubleshooting Guide Template.pdf”)
        End Sub

Step 4, Create Save Dialogue

Declare a new save dialog and define formats for filtering.


        private void button1_Click(object sender, EventArgs e)
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = “JPG Format(*.jpg)|*.jpg|BMP Format(*.bmp)|*.bmp|PNG Format(*.png)|*.png|GIF Format(*.gif)|*.gif”;
            DialogResult result = dialog.ShowDialog();


        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim dialog As New SaveFileDialog()
            dialog.Filter = “JPG Format(*.jpg)|*.jpg|BMP Format(*.bmp)|*.bmp|PNG Format(*.png)|*.png|GIF Format(*.gif)|*.gif”
            Dim result As DialogResult = dialog.ShowDialog()

Step 5, Export PDF Page AS Image

Declare a file name string and use if sentence to judge dialogue result. If result is OK, get current page and save this page as image. Finally, save this image.


            if (result == DialogResult.OK)
                int currentPage = this.pdfDocumentViewer1.CurrentPageNumber;
                Bitmap image = this.pdfDocumentViewer1.SaveAsImage(currentPage – 1);


            If result = DialogResult.OK Then
                Dim currentPage As Integer = Me.pdfDocumentViewer1.CurrentPageNumber
                Dim image As Bitmap = Me.pdfDocumentViewer1.SaveAsImage(currentPage – 1)
            End If

Result Shown as Following:


Click Here to LEARN MORE about Spire.PDFViewer

Click Here to DOWNLOAD Spire.PDFViewer

Spire.Office also can be used to realize this function.


3 thoughts on “How to Export PDF Page AS Image with C#/VB.NET

  1. vertical loading samsung aviator says:

    Hello to all, how is everything, I think every one is getting more from this website, and your views are fastidious in support of new people.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s