Я пытаюсь использовать Ghostscript.net для преобразования PDF в изображение на macOS. Вот мой код: < /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>
Проблемы, с которыми я сталкиваюсь:
platformnotsupportedException При запуске кода: < /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>
Кажется, Ghostscript.net пытается получить доступ к реестру Windows, который недоступен в MacOS. < /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>
Я хочу, чтобы мое решение работало кроссплатформенным (macos и linux). < /p>
Вопросы:
Как сделать Ghostscript.net Работать над MacOS, не сталкиваясь с проблемами реестра?>
Подробнее здесь: https://stackoverflow.com/questions/794 ... g-on-macos
Ghostscript PDF в преобразование изображений не работает на macOS ⇐ C#
Место общения программистов C#
-
Anonymous
1739039366
Anonymous
Я пытаюсь использовать Ghostscript.net для преобразования PDF в изображение на macOS. Вот мой код: < /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>
Проблемы, с которыми я сталкиваюсь:
platformnotsupportedException При запуске кода: < /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>
Кажется, Ghostscript.net пытается получить доступ к реестру Windows, который недоступен в MacOS. < /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>
Я хочу, чтобы мое решение работало кроссплатформенным (macos и linux). < /p>
Вопросы:
Как сделать Ghostscript.net Работать над MacOS, не сталкиваясь с проблемами реестра?>
Подробнее здесь: [url]https://stackoverflow.com/questions/79420822/ghostscript-pdf-to-image-conversion-not-working-on-macos[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия