ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

x and y dpi ignores the set value #75

Closed sarmad99 closed 3 years ago

sarmad99 commented 4 years ago

I am using the latest NuGet GhostScript and I am facing this issue:

             string outputFolder = @"C:\Users";
              string inputFile = @"C:\"
              var xDpi = 300; //set the x DPI
               var yDpi = 300; //set the y DPI
             var pageNumber = 1; // the pages in a PDF document
 (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
             {
         rasterizer.Open(inputFile); //opens the PDF file for rasterizing

               //set the output image(png's) complete path
          var outputPNGPath = Path.Combine(outputFolder, string.Format("0.png"));

            //converts the PDF pages to png's 
               var pdf2PNG = rasterizer.GetPage(xDpi, yDpi, pageNumber);

               //save the png's
          pdf2PNG.Save(outputPNGPath, ImageFormat.Png);

          Console.WriteLine("Saved " + outputPNGPath);

               }

pdf2png vertical and horizontal resolution always default to 96 or 120

ummerland commented 4 years ago

I guess this is because the parameters are private in GhostscriptViewer.cs

private int _zoom_xDpi = 96; private int _zoom_yDpi = 96;

Strange that there is no error thrown from the debugger

Edit: After some more digging i found that they are set via a property:

`

    public int Dpi
    {
        get { return ZoomXDpi; }
        set
        {
            ZoomXDpi = value;
            ZoomYDpi = value;
        }
    }

    #endregion

`

So the Value is not set via ZoomXDpi and ZoomYDpi, but Dpi

ummerland commented 4 years ago

So i made a PR for that, maybe someone can check and validate

sarmad99 commented 4 years ago

@ummerland thank you for the replay, late better than never. I made changes to the library a while back and now it is working as it should be I have been meaning to make a pull request to upload the fixed version but been busy. If you want I can email it to you. It works very good

ummerland commented 4 years ago

Thanks @sarmad99 for the reply Oh, that would be great!

After some more investigation i realized that HWResolution in GS is obsolete. So was that the change?

jhabjan commented 3 years ago

Fixed in today's v.1.2.2. release.