locked
Visual Basic Convert PDF to Other image format RRS feed

  • Question

  • Hi,

    Been looking for the ability to convert a PDF file to JPG or other image format.  All answers though are either many years old or are 3rd party software for a hefty price.  Has there been any progress in possibly adding the ability to .net or within the Visual Basic libraries?


    David Edwards

    Saturday, March 4, 2017 7:55 PM

Answers

  • Hi David,

    Without 3rd party libraries, I'm afraid that at present your only option is to write your own code to process pdf document, but its not an easy task. There are some free pdf libraries you can use such as this one: https://www.nuget.org/packages/FreeSpire.PDF/.



    • Edited by Shawn Sh Monday, March 6, 2017 4:02 AM
    • Marked as answer by De2164 Monday, March 6, 2017 8:42 AM
    Monday, March 6, 2017 4:01 AM

All replies

  • Hi David,

    Without 3rd party libraries, I'm afraid that at present your only option is to write your own code to process pdf document, but its not an easy task. There are some free pdf libraries you can use such as this one: https://www.nuget.org/packages/FreeSpire.PDF/.



    • Edited by Shawn Sh Monday, March 6, 2017 4:02 AM
    • Marked as answer by De2164 Monday, March 6, 2017 8:42 AM
    Monday, March 6, 2017 4:01 AM
  • Hi De2164,

    As far as I know, The library pdfiumviewer might be helpful here. It is also available as nuget.

    1. Create a new winforms app. Add nuget "PdfiumViewer" to it.
    2. Try out the following code (change paths to suit your setup).

    Try
    	Using document = PdfiumViewer.PdfDocument.Load("input.pdf")
    		Dim image = document.Render(1, 300, 300, True)
    		image.Save("output.png", ImageFormat.Png)
    	End Using
    		' handle exception here;
    Catch ex As Exception
    End Try

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by De2164 Monday, March 6, 2017 8:42 AM
    • Unmarked as answer by De2164 Sunday, March 12, 2017 3:37 AM
    Monday, March 6, 2017 6:11 AM
  • Thanks, I will look these over. 

    David Edwards

    Monday, March 6, 2017 8:43 AM
  • I got the following error message.  The PDF file is valid.  I can open it as a PDF file.

    System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
       at PdfiumViewer.NativeMethods.Imports.FPDF_AddRef()
       at PdfiumViewer.NativeMethods.FPDF_AddRef()
       at PdfiumViewer.PdfLibrary.EnsureLoaded()
       at PdfiumViewer.PdfFile..ctor(Stream stream, String password)
       at PdfiumViewer.PdfDocument..ctor(Stream stream, String password)
       at PdfiumViewer.PdfDocument.Load(Stream stream, String password)
       at PdfiumViewer.PdfDocument.Load(String path, String password)
       at PdfiumViewer.PdfDocument.Load(String path)
       at FileViewer.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\deboo\Documents\Visual Studio 2015\Projects\FileViewer\FileViewer\Form1.vb:line 18


    David Edwards

    Sunday, March 12, 2017 3:52 AM