我正在尝试用 C# 打印图像。它是由 Adobe Acrobat 从 PDF 创建的完整 8.5x11 大小的 tiff。当我使用下面的代码用 C# 打印它时,它垂直打印正确,但水平打印不正确,它被推过大约半英寸。我将图像的原点设置为 0,0。我错过了什么吗?
private FileInfo _sourceFile;
public void Print(FileInfo doc, string printer, int tray)
{
_sourceFile = doc;
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = printer;
pd.DocumentName = _sourceFile.FullName;
using (Image img = Image.FromFile(_sourceFile.FullName)) {
if (img.Width > img.Height) {
pd.DefaultPageSettings.Landscape = true;
}
}
pd.PrintPage += PrintPage;
foreach (PaperSource ps in pd.PrinterSettings.PaperSources) {
if (ps.RawKind == tray) {
pd.DefaultPageSettings.PaperSource = ps;
}
}
pd.Print();
}
private void PrintPage(object o, PrintPageEventArgs e)
{
using (System.Drawing.Image img = System.Drawing.Image.FromFile(_sourceFile.FullName)) {
Point loc = new Point(0, 0);
e.Graphics.DrawImage(img, loc);
}
}