Giter VIP home page Giter VIP logo

ghostscriptsharp's Introduction

GhostscriptSharp

GhostscriptSharp is a simple C# wrapper for the Ghostscript library.

Using GhostscriptSharp

The GhostscriptWrapper class contains 3 static methods that can be used to generate jpg images from a PDF file.

Generate an Image for a Single Page

This method will generate a single thumbnail for a single page at the given output path

GeneratePageThumb(string inputPath, string outputPath, int page, int width, int height)

Parameters

  • inputPath a path to the PDF file
  • outputPath the path where you would like the output jpg
  • page the page number for the page you want to create an image from
  • width the width of the image
  • height the height of the image

Generate Multiple Images for Multiple Pages

This method generates a collection of thumbnail jpgs for the PDF at the input path, starting with firstPage and ending with lastPage. Put "%d" somewhere in the output path to have each of the pages numbered.

GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)

Parameters

  • inputPath a path to the PDF file
  • ouputPath the path where you would like the output jpgs to go (put '%d' somewhere in the path to have the jpgs numbered)
  • firstPage the first page to start generating the thumbnails from
  • lastPage the last page to end the thumbnail generator
  • width the width of the image
  • height the height of the image

Generate Output Based on Settings

This method generates Ghostscript output at the given output path based on a collection of GhostscriptSettings. (See the source for a list of possible settings)

GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)

Parameters

  • inputPath a path to the PDF file
  • outputPath the path where you would like the output jpg
  • settings a collection of settings for the output (see source for more details)

ghostscriptsharp's People

Contributors

dash avatar mephraim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghostscriptsharp's Issues

GeneratePageThumb crash on 64 bits

Hello,
i am using this function and Works fine in 32 bits application, but i need to run it on 64 bits.

Exception:
An unhandled exception of type 'System.BadImageFormatException' occurred in GhostscriptSharp.dll

Additional information: Se ha intentado cargar un programa con un formato incorrecto. (Excepción de HRESULT: 0x8007000B)

Could you help me?
Thanks

Callback

how can i do a callback after GenerateOutput is done processing?

gsdll32.dll isn't included when project is published (WebDeploy)

Hi, I'm using GhostScriptSharp v1.3.1.4 and I've run into an issue when publishing a ASP.NET project.

The post-build event script only works locally.

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "ls '$(SolutionDir)\packages\GhostScriptSharp.*\Tools\gsdll32.dll' | Sort -Descending | Select -First 1 | cp -Destination '$(TargetDir)'; exit 0"

So when the project is published the gsdll32.dll is missing on the server :(

However I found a solution. Inspired from https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-extra-files

You can add the following to the publish profile.

<Target Name="CustomCollectFiles">
    <ItemGroup>
      <_CustomFiles Include="..\packages\GhostScriptSharp.*\Tools\gsdll32.dll" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>

    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>

And now the gsdll32.dll file is published along the other files. 🎉

Not sure if this somehow can be improved upon so this manual edit isn't necessary.

Build 32-bit local but deploy with 64-bit

There are two symptoms of what I believe is the same issue.

I've installed GhostScriptSharp using Nuget and I'm running it locally on a 32-bit machine in the Azure Development Fabric. Everything is working wonderfully.

When I deploy to Azure, which is 64-bit, I'm getting the following error message.

Unable to load DLL 'gsdll32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

There are two issues here as I can tell

  • The project did not build with the 64-bit GhostScriptSharp.cs
  • Regardless of the build, the gsdll32.dll or gsdll64.dll is not being copied into the correct folder.
    Are there any recommendations to get this working on the Azure deployments?

I've posted the question to stackoverflow as well.

http://stackoverflow.com/questions/24519908/ghostscriptsharp-on-azure

Thanks in advance for the assistance

Extremely slow library

I've spent an entire day trying to make this to integrate into my app, I got FileNotFoundException on the gsdll32.dll, and when I copied it to C:\Windows\System32, or put it manually alongside the GhostScriptSharp.dll, it errored out with BadImage exception, then finally I thought of creating a simple console app and try it there, and it worked as both DLLs were under the bin folder alongside each other (surprisingly), but then the performance of this library is horrible!! It's slow and it generates huge files (in MBs vs. few KBs compared to other libs).

So, I don't believe anyone complained about this before so they wouldn't waste their time and try this library like I did, it sure would've helped me if I knew this was its result.

multi-threaded use

Looking to sit a web service on top of this library.
Would this work safely in a multithreaded environment?

InitAPI() throws -100 for >10 pages

Thanks for the great code!
I am trying to convert a multi page PDF into bunch of PNGs.
The same code works for all PDFs with page count <11 but InitAPI() blows up with error code -100 if page count is 11 or more. I wonder if there should be a different format for generating unique file name that GhostScript takes as part of sOutputFile argument instead of %d.jpg? Or is this related to something else?
Thanks in advance.

BadImageFormatException

Hi,

I downloaded ghostscriptsharp from NuGet and whenever I call: GhostscriptWrapper.GenerateOutput(pdfPath, pagePath, settings);

It gives me a BadImageFormatException "An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"

I tried building my project with AnyCPU, 32 and 64 bit architecture but always getting the same exception.

Licensing

I don't think you can license it under MIT if you're using Ghostscript library.

Problem with Calling GeneratePageThumbs

GeneratePageThumbs is throwing error and GeneratePageThumb working fine. When I dig into this GeneratePageThumb is actually calling GeneratePageThumbs internally. So GeneratePageThumbs expect outputPath which is a string and output files can be multiple. GeneratePageThumbs should get outputDirectoryPath instead of outputFilePath and output file name should be handled within the function.

File too big

First, good job on this wonderful library. I tried extensively with various pdf's and found out that if i use this settings below (jpg or png) to generate a thumbnail of an ebook (16.6mb), the result is a thumbnail of over 30mb even with a meager 198 * 262 pixel output dimension. Am I doing something wrong because a 72 dpi resolution produces the smallest file size posible with reasonable image quality as a thumbnail for me.

  GhostscriptWrapper.GenerateOutput(filepath, fullthumbnailfilepath, New GhostscriptSettings With {
                .Device = GhostscriptDevices.pngalpha,
                .Page = New GhostscriptPages With {.Start = 1, .End = 1, .AllPages = False},
                .Resolution = New Size With {.Height = 72, .Width = 72},
               .Size = New GhostscriptPageSize With {.Native = GhostscriptPageSizes.a4}
                })

Azure Issue

In dev it works fine, butit fails to create the image when it's live on Azure hosting, no error is thrown.
Edit: No error was thrown because of a async control used. Error output was the same
Unable to load DLL 'gsdll32.dll'

Does not build when checked out

Hi, I maintain the nuget package for GhostScriptSharp (by the way let me know if you want to take over that duty), and was asked to update it to version 1.1

Checking out the code...

I was able to only find an sln file in the test project and when I tried to compile I got an error from nunit not being referenced. Can you please include dependencies via nuget and enable auto package restore?

Also, its standard to have an sln at the project root so I would recommend moving it there.

.eps Correct dimensions

Hi mephraim,

Firstly want to thank you for the great work you have done in putting this ghostscript c# wrapper together not many of these out there. I have a slight problem with it though which I am not too sure how to go about fixing it. The project reads eps files but for some images they get cropped. I have slightly gotten around this by using the "ledger" page size (landscape). The problem is it adds unnecessary spaces both at the top of images and to the right of the images. How would I go about so that the actual dimensions of an image is obtained and then used in order to create the thumbnail image rather than using the pre-defined page sizes such as "ledger". This is the only issue I see with this, and once sorted this should be perfect. Any suggestion or ideas on how to go about achieving this...

Many Thanks

BTW dll is updatable

Just leaving a note. The dll in the nuget package can be swapped out with the latest version (9.07) I used.

This fixed some crashes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.