[英]How to print a full size image in c#
I am trying to print an image in C#. 我想用C#打印图像。 It is a full 8.5x11 size tiff created by Adobe Acrobat from a PDF. 它是由Adobe Acrobat从PDF创建的完整8.5x11大小的tiff。 When I print it with C# using the code below, it prints correct vertically, but not horizontally, where it is pushed over about a half inch. 当我使用下面的代码用C#打印时,它会垂直打印,但不能水平打印,它会被推过半英寸。 I set the origin of the image to 0,0. 我将图像的原点设置为0,0。 Am I missing something? 我错过了什么吗?
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);
}
}
look at the code from this below for a good example this code is from this link below Print Image in C# 看看下面的代码,这是一个很好的例子,这段代码来自下面这个链接在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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.