C# 打印多页tif
注意点:
1.计算image对象总页数
image.GetFrameCount(FrameDimension.Page);
2.初始化当前页,并获取指定页内容
image.SelectActiveFrame(FrameDimension.Page, m_CurrentPage);
3.设置PrintPage时间PrintPageEventArgs参数值,判断是否有额外页打印(次数是打印多页关键)
e.HasMorePages = (m_CurrentPage < m_PageCount);
基本DEMO(转载)
private Image m_Image; private Int32 m_CurrentPage; private Int32 m_PageCount; private void Form1_Load(object sender, EventArgs e) { m_Image = Image.FromFile(".\\Test-2-Page-Image.tif"); m_PageCount = m_Image.GetFrameCount(FrameDimension.Page); } private void printDocument_BeginPrint(object sender, PrintEventArgs e) { m_CurrentPage = 0; m_PageCount = m_Image.GetFrameCount(FrameDimension.Page); } private void printDocument_PrintPage(object sender, PrintPageEventArgs e) { m_Image.SelectActiveFrame(FrameDimension.Page, m_CurrentPage); e.Graphics.DrawImage(m_Image, 0, 0); ++m_CurrentPage; e.HasMorePages = (m_CurrentPage < m_PageCount); } private void btnPrint_Click(object sender, EventArgs e) { printDocument.Print(); }