Where to copy gsdll32.dll to make PDF to image converter work in my WPF application?
Asked Answered
B

3

7

My PROJECT gives error..

*Unable to find an entry point named 'gsapi_new_instance' in DLL 'gsdll32.dll'.*

when trying to convert .pdf to image format using Ghost-script Interpreter dll 'gsdll32.dll'

Even if I tried copying this dll to all desired places as told in many forums like in

Win\System32 or in The project's directory..The error remains the same..:(

I have used The PDFConvert.cs class given by Ghost-script and written the following code on my Convert Button click:

private void btnConvert_Click(object sender, RoutedEventArgs e)
{
  //First We Check whether the Dll is present

    if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\gsdll32.dll"))
    {
        MessageBox.Show("The library 'gsdll32.dll' required to run this program is not present! download GhostScript and copy \"gsdll32.dll\" to this program directory");
        return;
    }
    if (string.IsNullOrEmpty(txtSingleFile.Text))
    {
        MessageBox.Show("Enter the File name");
        txtSingleFile.Focus();
        return;
    }
    else if (!File.Exists(txtSingleFile.Text))
    {
        MessageBox.Show("The File Does not exists");
        txtSingleFile.Focus();
    }

    else
        ConvertPdfToImage(txtSingleFile.Text);
}

and My ConvertPdfToImage Method is as like:

//The Ghost-Script Class Object Creation:
PdfToImage.PDFConvert converter = new PdfToImage.PDFConvert();
public void ConvertPdfToImage(string filename)
{
    //bool converted = false;
    System.IO.FileInfo input = new FileInfo(filename);
    string outPut = string.Format("{0}\\{1}{2}", input.DirectoryName, input.Name, txtExtensionName.Text);

    converter.OutputFormat = txtExtensionName.Text;

    outPut = outPut.Replace(txtExtensionName.Text, string.Format("{1}{0}", txtExtensionName.Text, DateTime.Now.Ticks));
    converter.Convert(input.FullName, outPut);
    lblConvertingResult.Content = string.Format("{0}:File Converted..!!", DateTime.Now.ToShortTimeString());
}

i believe This error comes because of the Misplacement of gsdll32.dll library because the same code runs well with the sample demo Provided By the Ghost-Script Interpreter API.. Please Suggest The exact Location where I shuld Keep the dll-gsdll32.dll.!!

Bearwood answered 17/8, 2012 at 13:34 Comment(2)
take a look: #653678Peacemaker
@Peacemaker Thanks for the reply..But I couldn't find much on this page for my case..Please be some more specific..Where all can we add this ghost-script dll to make the project working.Because This dll is not getting added as Reference in my BIN Folder.Bearwood
P
9

I know this question is a little old, but if someone has this problem, i solve it in this way: downloading and install GhostScriptSharp package from Visual Studio http://www.nuget.org/packages/GhostScriptSharp/

Protestation answered 21/11, 2013 at 17:54 Comment(1)
oh thanks zurita..I had almost completely lost hope to get a proper solution to this problem..:(Bearwood
B
0

Try with complete path of dll instead of only name.
Like if your dll kept at D:\TestApplication\bin\gsdll32.dll then,

[DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")] 

Above statement will be

[DllImport("D:\\TestApplication\\bin\\gsdll32.dll", EntryPoint="gsapi_new_instance")]
Broadsword answered 20/7, 2015 at 7:43 Comment(0)
C
-1

I finally figured it out. I downloaded the latest DLL, changed the code to look for the updated dll, and it worked.

Curculio answered 31/7, 2019 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.