Код: Выделить всё
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);
}
}

Однако, когда я отправляю задание на печать, происходит сбой: Не удалось загрузить файл или сборку «System.Windows.Forms».
Я запускаю Основное приложение .net8 asp.net.
У кого-нибудь есть опыт работы с этим?
Подробнее здесь: https://stackoverflow.com/questions/790 ... windows-fo
Мобильная версия