我有一个小应用程序,用于打印PDF文档。一切都很好,除了使用字体生成条形码的文件,页面上的这些部分看起来变形了(条形码中间的文本在条形码条中)。有人知道为什么会发生这种情况,有什么解决方法吗?
我的代码:
public static void PrindDocument(string filePath, PrinterSetting printerSetting, int copies)
{
SpirePdf.PdfDocument doc = new SpirePdf.PdfDocument();
doc.LoadFromFile(filePath);
PrintDialog dialogPrint = new PrintDialog();
dialogPrint.AllowPrintToFile = true;
dialogPrint.AllowSomePages = true;
dialogPrint.PrinterSettings.MinimumPage = 1;
dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
dialogPrint.PrinterSettings.FromPage = 1;
dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;
dialogPrint.PrinterSettings.Copies = (short)copies;
var paperSize = dialogPrint.PrinterSettings.PaperSizes.Cast<PaperSize>().FirstOrDefault(e => e.PaperName == printerSetting.Pageformat);
dialogPrint.PrinterSettings.DefaultPageSettings.PaperSize = paperSize;
doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
doc.PrinterName = printerSetting.Printer;
PrintDocument printDoc = doc.PrintDocument;
printDoc.DefaultPageSettings.PaperSize = paperSize;
printDoc.PrinterSettings.Copies = (short)copies;
dialogPrint.Document = printDoc;
printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();
printDoc.Print();
}
我尝试了另一种方法,但那个方法做的事情完全相同:
private void SendToPrinter()
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = @"c:\output.pdf";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = info;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(3000);
if (false == p.CloseMainWindow())
p.Kill();
}
这里可以找到PDF文件示例: https://www.dropbox.com/sh/7vhnyji10f4ekx3/AACI2XtG3PoiHzGzoJNbH_k7a?dl=0
另外我想提一下,当我通过正常方式打印这个文件,比如用谷歌浏览器打开并打印,它看起来还不错。
PdfDocument
是什么?是iText还是Windows? - Chris Haas