gpt4 book ai didi

c# - 如何在 C# 中打印全尺寸图像

转载 作者:行者123 更新时间:2023-11-30 12:48:23 25 4
gpt4 key购买 nike

我正在尝试用 C# 打印图像。它是由 Adob​​e 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);
}
}

最佳答案

查看下面的代码以获得一个很好的示例,该代码来自下面的链接 Print Image in C#

        private void PrintImage()
{
PrintDocument pd = new PrintDocument();

pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
pd.OriginAtMargins = false;
pd.DefaultPageSettings.Landscape = true;

pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);


printPreviewDialog1.Document = pd;
printPreviewDialog1.ShowDialog();

//pd.Print();
}

void pd_PrintPage(object sender, PrintPageEventArgs e)
{
double cmToUnits = 100 / 2.54;
e.Graphics.DrawImage(bmIm, 100, 1000, (float)(15 * cmToUnits), (float)(10 * cmToUnits));
}

private void button5_Click(object sender, EventArgs e)
{
PrintImage();
}

关于c# - 如何在 C# 中打印全尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14270896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com