Ghostscript PDF zur Bildumwandlung funktioniert nicht auf macOSC#

Ein Treffpunkt für C#-Programmierer
Guest
 Ghostscript PDF zur Bildumwandlung funktioniert nicht auf macOS

Post by Guest »

Ich versuche, Ghostscript.net zu verwenden, um ein PDF in ein Bild auf MacOS zu konvertieren. Hier ist mein Code: < /p>
using System;
using System.IO;
using Ghostscript.NET.Rasterizer;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Png;

public class PdfToImageConverter
{
public static void ConvertPdfToThumbnail(string pdfPath, string outputImagePath, int pageNumber = 1, int dpi = 100)
{
using (var rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(pdfPath);

using (var img = rasterizer.GetPage(dpi, pageNumber))
{
using (var memoryStream = new MemoryStream())
{
img.Save(outputImagePath, System.Drawing.Imaging.ImageFormat.Png);
memoryStream.Seek(0, SeekOrigin.Begin);

using (var image = SixLabors.ImageSharp.Image.Load(memoryStream))
{
image.Save(outputImagePath, new PngEncoder());
}
}
}
}
}

public static void Main()
{
string pdfPath = @"/Users/Downloads/testfile.pdf";
string outputPath = @"/Users/Downloads/output.png";

ConvertPdfToThumbnail(pdfPath, outputPath);
Console.WriteLine("Thumbnail generated successfully!");
}
}
< /code>
Probleme, mit denen ich ausgesetzt bin:
PlatformNOTSUPPORTEDException beim Ausführen des Code: < /p>
System.PlatformNotSupportedException: Registry is not supported on this platform.
at Microsoft.Win32.RegistryKey.OpenBaseKey(RegistryHive hKey, RegistryView view)
at Ghostscript.NET.GhostscriptVersionInfo.GetInstalledVersions(GhostscriptLicense licenseType)
at Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense licenseType, GhostscriptLicense licensePriority)
at Ghostscript.NET.Rasterizer.GhostscriptRasterizer.Open(String path)
< /code>
Es scheint, dass Ghostscript.net versucht, auf die Windows -Registrierung zuzugreifen, die auf macOS nicht verfügbar ist. < /p>
'Image.Save(string, ImageFormat)' is only supported on: 'windows' 6.1 and later.
'ImageFormat.Png' is only supported on: 'windows' 6.1 and later.
< /code>
Ich möchte, dass meine Lösung plattformübergreifend funktioniert (MacOS und Linux). Arbeit an macOS arbeiten, ohne auf Registrierungsfragen zu stoßen?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post