是否可以用c#双面打印,如打印身份证或驾驶执照?
我有两个图像front.jpg和back.jpg。我想把它们前后印在同一页上,做成一张“卡片”。我遇到了“复式”物业,但不确定它在这方面如何帮助我 我试着使用双面打印。我正试图在printDocument1\u PrintPage事件中打印正面和背面的两幅图像是否可以用c#双面打印,如打印身份证或驾驶执照?,c#,webforms,C#,Webforms,我有两个图像front.jpg和back.jpg。我想把它们前后印在同一页上,做成一张“卡片”。我遇到了“复式”物业,但不确定它在这方面如何帮助我 我试着使用双面打印。我正试图在printDocument1\u PrintPage事件中打印正面和背面的两幅图像 private void button1_Click(object sender, EventArgs e) { PrintDocument pd = new PrintDocument(); pd.PrintPage +
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += printDocument1_PrintPage;
//here to select the printer attached to user PC
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = pd;
DialogResult result = printDialog1.ShowDialog();
pd.PrinterSettings.Duplex = Duplex.Horizontal;
if (result == DialogResult.OK)
{
pd.Print();//this will trigger the Print Event handeler PrintPage
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
#region Front
//Load the image from the file
System.Drawing.Image img = System.Drawing.Image.FromFile(@"E:\front.jpg");
//Adjust the size of the image to the page to print the full image without loosing any part of it
Rectangle m = e.MarginBounds;
if ((double)img.Width / (double)img.Height > (double)m.Width / (double)m.Height) // image is wider
{
m.Height = (int)((double)img.Height / (double)img.Width * (double)m.Width);
}
else
{
m.Width = (int)((double)img.Width / (double)img.Height * (double)m.Height);
}
e.Graphics.DrawImage(img, m);
#endregion
//Load the image from the file
System.Drawing.Image img1 = System.Drawing.Image.FromFile(@"E:\back.jpg");
//Adjust the size of the image to the page to print the full image without loosing any part of it
Rectangle m1 = e.MarginBounds;
if ((double)img1.Width / (double)img1.Height > (double)m.Width / (double)m.Height) // image is wider
{
m.Height = (int)((double)img1.Height / (double)img1.Width * (double)m.Width);
}
else
{
m.Width = (int)((double)img1.Width / (double)img1.Height * (double)m.Height);
}
e.Graphics.DrawImage(img1, m1);
}
catch (Exception)
{
}
}
我相信你的问题在于你不是在打印一张双面纸,而是在打印两页,一张纸的每一面都有一页。双面打印魔法发生在打印机/驱动程序中,而不是GDI中 我在这里只看到一页打印出来。 不要试图一次打印两幅图像
祝你好运 请包括任何现有的相关代码。我不认为这与普通双面打印不同。您只需确保每个正面与对应的背面对齐即可。