Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Mar 04, 2013 11:56 am

How to convert pdf to jpeg images using Spire.Pdf for .Net?

I couldn't find a solution in Program Guide

Is it possible?

VoimiX
 
Posts: 3
Joined: Mon Mar 04, 2013 9:14 am

Tue Mar 05, 2013 6:13 am

Dear VoimiX,

Thanks for your inquiry.
Spire.PDFViewer library support converting pdf to jpeg images. Please find the demo Export PDF Document to images from the link http://www.e-iceblue.com/Knowledgebase/Spire.PDFViewer/Demos.html.

Please download and test Spire.PDFViewer(http://www.e-iceblue.com/Download/download-pdf-viewer-for-net-now.html).
If you have any problem during the test, please feel free to contact us. And you can send your problem to support@e-iceblue.com.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Mar 05, 2013 7:56 am

Code: Select all
PdfDocumentViewer viewer = new PdfDocumentViewer();

            viewer.LoadFromFile(@"D:\DEV\tmp\percents.pdf");

            int currentPage = viewer.CurrentPageNumber;
            Bitmap[] images = viewer.SaveAsImage(0, currentPage - 1);
            for (int i = 0; i < images.Length; i++)
            {
                String fileName = Path.Combine(@"D:\DEV\tmp", String.Format("PDFViewer-{0}.png", i));
                images[i].Save(fileName);
            }


I get FormatException on the line Bitmap[] images = viewer.SaveAsImage(0, currentPage - 1);

StackTrace

в System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
в System.Single.Parse(String s)
в ᢽ.ᜀ(String[] A_0)
в ᢽ.ᜒ()
в Spire.PdfViewer.Forms.PdfDocumentViewer.SaveAsImage(Int32 startIndex, Int32 endIndex)
в DocToPngConverter.Program.Main(String[] args) в c:\Users\vsitnikov\Documents\Visual Studio 2012\Projects\DocToPngConverter\DocToPngConverter\Program.cs:строка 35


There is my pdf file in the attachment

VoimiX
 
Posts: 3
Joined: Mon Mar 04, 2013 9:14 am

Wed Mar 06, 2013 7:07 am

Dear VoimiX,

Thanks for your inquiry.
We used Spire.Pdf.dll 2.6.100.6040, Spire.PdfViewer.Forms.dll 1.6.34.6340 and Spire.License.dll 1.3.2.40 in spire.pdfviewer_1.6.34\ BIN\ NET4.0 to do the test with your pdf file and code, but we didn't reproduce the issue you met.
Please kindly note that the code viewer.CurrentPageNumber will get current display page number.
And we provide you our test code below and attached the exported images.
Code: Select all
using Spire.PdfViewer;
using Spire.Pdf;
using Spire.PdfViewer.Forms;
using System.Drawing;
namespace _1260
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocumentViewer pdfViewer = new PdfDocumentViewer();
            pdfViewer.LoadFromFile(@"..\..\percents.pdf");
            for (int i = 0; i < pdfViewer.PageCount; i++)
            {
                Image image = pdfViewer.SaveAsImage(i);
                image.Save(String.Format(@"..\..\images\image-{0}.jpg", i), System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
    }
}


Please try to test spire.pdfviewer_1.6.34(http://www.e-iceblue.com/Download/download-pdf-viewer-for-net-now.html) with your pdf file. If you still have the issue, please tell us.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Mar 06, 2013 9:59 am

I forgot to metion that I use windows 7 with RUSSIAN LOCALE

May be internally pdfviewer converts string to number.
"3.56" and "3,56" are different.

That's why you can not reproduce the bug

Your last code also doesnt work (same exception)

VoimiX
 
Posts: 3
Joined: Mon Mar 04, 2013 9:14 am

Thu Mar 07, 2013 2:40 am

Dear VoimiX,

Thanks for your feedback.
We are sorry that our previous code didn't work on your side. We think the error may be caused by the decimal separator of your local culture. Please try the new code below on your side. If you still have the problem, please tell us.

Code: Select all
           CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            PdfDocumentViewer pdfViewer = new PdfDocumentViewer();
            pdfViewer.LoadFromFile(@"..\..\percents.pdf");
            for (int i = 0; i < pdfViewer.PageCount; i++)
            {
                Image image = pdfViewer.SaveAsImage(i);

               Thread.CurrentThread.CurrentCulture = cc;
                image.Save(String.Format(@"..\..\images\image-{0}.jpg", i), System.Drawing.Imaging.ImageFormat.Jpeg);
            }


Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Mar 14, 2013 8:50 am

Dear VoimiX,

Does the new solution solve your problem?
If you still have this issue or have other any issue, please tell us.
Have a nice day!

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF