0

Background Info: I needed to convert PDF files to images and have full control over how this is done, and noticed that this functionality does exist in NuGet packages, but only in paid packages. Because I am a cheap bastard I refused to pay for this as I can easily do this in python for free.

I created a way to call a python script from c# that converts the PDF I want to a jpg in the exact way I want, and used this for a while. Now I want to build on this project and thought about creating this into a class library that I can use in multiple projects.

The problem I am now facing is that for this python script to work I need a specific resource, a couple of files in a folder. When I add the existing project (the pdf to img converter) to another project it just adds the DLL, and ignores everything else. The files I need are still in a folder inside the class library.

When I try to access the necessary files the current path is inside the new project, and there those files don't exist.

Directory.GetCurrentDirectory(); tells me that the current path is inside the new project.

Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); tells me where the DLL is located, but the files I need aren't there.

I have tried searching for a way to access files inside the class library but I came up with nothing useful.

The question: Is there a way to access files inside of a project that you are referencing? or is there a way to ensure the files I need are brought over too, instead of just the DLL?

Just for completion, I intend to make this into my own private Nuget package, and Im sure I can get the files I need in the .nupkg, but the same problem will persist, How do I access those files.

If anyone has any experience with this kind of problem, I would be happy to hear from you. Thank you in advance.

  • If the file is in the project, go to its properties and select "Copy to Output Directory: Copy Always" or "Copy if newer." – Scott Hannen Dec 15 '21 at 15:44
  • Your options are 1) Configure your project so the class library and the application using it are built into the same folder: then all your files are there. 2) Reference those files from the application. 3) Add the files to the class library as "Embedded Resources" (under properties). This embeds them inside the DLL. Access them using e.g. `typeof(SomeTypeInTheClassLibrary).Assembly.GetManifestResourceStream(...)`, which gives you a `Stream` containing the file contents – canton7 Dec 15 '21 at 15:45

1 Answers1

-1

I would try to use a c# solution in this case to convert pdf to jpeg. May be something like this: Convert pdf to jpeg using a free c# solution

or optimal solution: a nuget package, which you can define as dependency in your nuget package

but there are many other solutions instead a phyton script.

Reason:

  1. If you like to provide a nuget package (even if its company intern) the library should not have dependencies that are not transparent. In your case ist the dependency to an available phyton installation in the envirement, where the package will be used.

  2. The software that uses the package must have the rights to execute a phyton script

  3. In additional, you will resolve the issue, that you must be able to store and execute a script, if you use a c# solution

Nobody
  • 149
  • 5
  • Thank you for contributing, but this is not what I am asking for. I **have** tried the solution above and it is not what I need. I am asking a specific question, you are answering another one. – Wessel Ottevanger Dec 15 '21 at 16:56