提问人:DeanEncoded 提问时间:11/6/2023 更新时间:11/6/2023 访问量:63
C# 将 PDF 打印到热敏打印机 (Star TSP100) 生成不清晰/模糊的收据
C# Printing PDF to thermal printer (Star TSP100) produces an unclear/fuzzy receipt
问:
我有一个 C# .NET Framework 控制台应用程序,可将 PDF 文档发送到指定的打印机。 我主要使用A4打印机和热敏打印机进行打印。
以下是打印过程的代码片段:
// PdfiumViewer
var pdfViewer = new PdfViewer
{
Document = PdfDocument.Load(filename)
};
// Create the printer settings for our printer
var printerSettings = new PrinterSettings
{
PrinterName = printer,
Copies = (short)1,
};
// Create our page settings with the paper size as the document size.
var pageSettings = new PageSettings(printerSettings)
{
Margins = new Margins(0, 0, 0, 0), // No margins
Color = false,
PaperSize = new PaperSize("Custom PDF Size", pdfViewer.Document.PageSizes[0].Width, pdfViewer.Document.PageSizes[0].Height)
};
// Proceed to print
// Now print the PDF document
using (var document = PdfDocument.Load(filename))
{
using (var printDocument = document.CreatePrintDocument())
{
printDocument.PrinterSettings = printerSettings;
printDocument.DefaultPageSettings = pageSettings;
printDocument.PrintController = new StandardPrintController();
// Print the document
printDocument.Print();
}
}
我只打印单页文档。打印到A4打印机工作正常。 打印到热敏打印机 (Star TSP100) 时,始终会产生不清晰/模糊的收据。您可以在下面看到文档和打印输出之间的区别。
PDF 文档的页面大小为 3.78 x 7.92 英寸。
将相同的 PDF 打印到 A4 打印机可生成非常清晰的文档。
我只是想知道为什么收据不清楚。是否有任何可能的解决方法?
我尝试将 PDF 转换为收据的位图,然后打印 - 结果更糟。输出更不清楚
答:
评论