Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create PDF to image using ghostscript. It looks good in my local site. Now I set my website to the IIS using App Application for Default site, and accessing it from other PC using LAN connection my site is looks good but ghostscript is not generating Pdf to Image. Is there anything that I was missing out?

I am using gsdll32.dll file

What I have tried:

GhostscriptWrapper.GenerateOutput(sourcePdfFilePath, destinationPngFilePath,
new GhostscriptSettings
{
Device = GhostscriptDevices.pngalpha,
Page = new GhostscriptPages
{
Start = 1,
End = 1,
AllPages = false
},
Resolution = new Size
{
Height = 72,
Width = 72
},
Size = new GhostscriptPageSize
{
Native = GhostscriptPageSizes.a4
}
}
);
Posted
Updated 30-Sep-16 6:33am

You didn't post an error message but one common issue i've had with ghostscript and the gsdll32.dll is that it needs to be located in your deployed projects /bin directory (Ex: c:\inetpub\wwwroot\yourprojectname\bin). I believe the gsdll32.dll cannot be included as a reference in your project so it will not be automatically picked up on publish when deploying your app.
 
Share this answer
 
Comments
Member 10268466 29-Sep-16 22:57pm    
Yes, may be you are right.But my question is not for that. Will you please read the question again? My concern is something different.
David_Wimbley 30-Sep-16 0:49am    
My answer remains the same. Check that your deployed app contains said dll. Also it would be helpful for you to post an error message as guessing at what your code is doing will get you no where.

If it is working locally but not when deployed it likely isn't a code problem....but again you haven't shared a whole lot of information for anyone to provide more meaningful help with.
I had just done this for a batching OCR application and found that using Ghostscript.NET (see here)worked great and was reliable. The biggest issue I found was that just because the development station has Ghostscript installed, does not mean the system running the routine does. In this case, its best to provide a means to initialize Ghostscript in memory using a specified gsdll32.dll file path. This is slightly modified version of my working code. The only difference is that we do not provide and input path, we provide an object that has that data in it.

C#
using Ghostscript.NET;

static GhostscriptVersionInfo GetVersionInfo(string dllPath)
        {
            GhostscriptVersionInfo gsVersion = null;

            try { gsVersion = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL); }
            catch { }

            if (gsVersion == null)
            {
                try { gsVersion = new GhostscriptVersionInfo(new Version(0, 0, 0), dllPath, string.Empty, GhostscriptLicense.GPL); }
                catch { }
            }

            return gsVersion;
        }


        static void ExtractPagesAsPngs(GhostscriptVersionInfo gsVersion, string scrFilePath, string destFilePath, int[] sheetsToExtract, int[] allowedDpiValues)
        {
            if ((allowedDpiValues == null) || (allowedDpiValues.Length < 1)) { allowedDpiValues = new int[] {300, 256, 150, 128, 96, 72, 64, 32, 16, 8}; }
            
            // Set up the GhostscriptPngDevice object.
            var gsDev = new GhostscriptPngDevice(GhostscriptPngDeviceType.Png256);
            gsDev.GraphicsAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
            gsDev.TextAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
            gsDev.CustomSwitches.Add("-dDOINTERPOLATE");
            
            // Iterate thought the sheets to extract, and extract them.
            for (var i = 0; i < sheetsToExtract.Length; i++)
            {
                // Specify the PDF and sheet number.
                gsDev.InputFiles.Add(scrFilePath);
                gsDev.Pdf.FirstPage = sheetsToExtract[i];
                gsDev.Pdf.LastPage = sheetsToExtract[i];

                // Set the output file path (if multiple sheets, place sheet number in parenthsies.
                if (sheetsToExtract.Length == 1) { gsDev.OutputPath = destFilePath; }
                else { gsDev.OutputPath = destFilePath.Replace(".png", " (" + sheetsToExtract[i].ToString() + ").png"); }

                // Prevent zero (0) or negative DPI values.
                for (var j = 0; j < allowedDpiValues.Length; j++)
                {
                    if (allowedDpiValues[j] < 1) { allowedDpiValues[j] = 1; }
                }

                // Remove duplicate allowed DPI values.
                var dpiToTry = allowedDpiValues.Distinct().OrderBy(x => x).ToArray();

                // Attempt to extect the image at highest allowed DPI, and decrementing by using the next approved DPI
                // specified until successfull or no more allowed DPI values exsist.
                int dpiIdx = 0;
                bool extracted = false;
                while (!extracted && (dpiIdx < dpiToTry.Length))
                {
                    // Set the resolution.
                    gsDev.ResolutionXY = new GhostscriptImageDeviceResolution(dpiToTry[dpiIdx], dpiToTry[dpiIdx]);

                    // Try to extract the image.
                    try { gsDev.Process(gsVersion, true, null); }
                    catch { }

                    // Check if successful.
                    if (File.Exists(gsDev.OutputPath)) { extracted = true; }
                    else { dpiIdx++; }
                }
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900