Using pdf2image.dll in an ASP.NET application

157 views
Skip to first unread message

Support

unread,
May 27, 2009, 6:16:24 PM5/27/09
to PDF2Image
Q: I am trying to include the pdf2image.dll in an asp.net application
and it is causing a webdev.webserver failure? How can I accomplish
this?

-----
A: My guess is that your application can't find PDF2Image.DLL in the
search path (to verify this you may want to copy 'PDF2Image.DLL' and
'pdfnet.res' into c:\Windows\System32 folder - which is included in
standard DLL search path).

You could then use pdf2image in your project as follows:

using System;
using System.Runtime.InteropServices;
using System.Collections;

class Class1 {
public delegate Int32 PDF2ImageCallback(int mode, string msg, IntPtr
user_data);

// The following lines import the PDF2Image functions from
pdf2image.dll (via PInvoke).
[DllImport("pdf2image.dll")]
public static extern int PDF2ImageInit(string user_name, string
company, string license_key, string res_path);

[DllImport("pdf2image.dll")]
public static extern int PDF2ImageRun(string command_str,
PDF2ImageCallback funct, IntPtr user_data);

static void Convert(string input_pdf_path) {
PDF2ImageInit("", "", "", null);
PDF2ImageRun("-f png -o " + input_pdf_path, null, new IntPtr(0)); }

Alternatively instead of PDF2Image you may want to use PDFNet SDK
(http://www.pdftron.com/pdfnet). PDFNet is a true .NET component and
like PDF2Image it can be used to convert PDF documents to images. To
integrate PDFNet in your ASP.NET project you can use these simple
steps:

a) Download PDFNet SDK for .NET (http://www.pdftron.com/pdfnet/
downloads.html
-> http://www.pdftron.com/downloads/PDFNet.zip)
b) Add a reference to PDFNet.DLL in you solution.
c) Call the following utility function.

using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;

public static void SimpleExport(string pdf) {
string jpg = System.IO.Path.ChangeExtension(pdf, ".jpg");
PDFNet.Initialize();
using (PDFDoc doc = new PDFDoc(pdf))
using (PDFDraw draw = new PDFDraw())
draw.Export(doc.GetPage(1), jpg, "JPEG", null); }

For a more extensive sample illustrating the use of PDFDraw class,
please take a look at PDFDraw sample project (http://www.pdftron.com/
pdfnet/samplecode.html#PDFDraw).
Reply all
Reply to author
Forward
0 new messages