Приложение .NET Function и pdfium; Не удалось загрузить файл или сборку «System.Windows.Forms».C#

Место общения программистов C#
Anonymous
Приложение .NET Function и pdfium; Не удалось загрузить файл или сборку «System.Windows.Forms».

Сообщение Anonymous »

Я пытаюсь получить строку base64 в формате PDF и распечатать ее.
У меня есть этот код:

Код: Выделить всё

public void PrintPdfFromBase64(string base64String, string printerName)
{
byte[] pdfBytes = Convert.FromBase64String(base64String);
string tempFilePath = Path.GetTempFileName() + ".pdf";
File.WriteAllBytes(tempFilePath, pdfBytes);

try
{
using (var pdfStream = new MemoryStream(pdfBytes))
{
using (var document = PdfiumViewer.PdfDocument.Load(pdfStream))
{
var printDocument = document.CreatePrintDocument();
printDocument.PrinterSettings = new PrinterSettings
{
PrinterName = printerName
};

printDocument.PrinterSettings.Copies = 1;
printDocument.DefaultPageSettings.Landscape = false;
printDocument.Print();
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred while printing: {ex.Message}");
}
finally
{
// Clean up the temporary file
File.Delete(tempFilePath);
}
}
Я установил пакет pdfium nuget вместе со следующими:
[img]https://i .sstatic.net/l7QlzS9F.png[/img]

Однако, когда я отправляю задание на печать, происходит сбой с:

Не удалось загрузить файл или сборку «System.Windows.Forms».

Я запускаю приложение ASP.NET Core 8.Кто-нибудь сталкивался с этим?

Подробнее здесь: https://stackoverflow.com/questions/790 ... windows-fo

Вернуться в «C#»