合并不同的页面大小时如何使用iTextSharp.text.PageSize?

时间:2011-12-20 06:03:44

标签: itextsharp c#-to-vb.net

private void ConvertMultiTifToMultiPdf(string singlefile, string outputIndx, string NewImageName)
{
    // creation of the document with a certain size and certain margins  
    iTextSharp.text.Document document = new iTextSharp.text.Document(*iTextSharp.text.PageSize.A4*, 0, 0, 0, 0);

    using (PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(outputIndx + "\\" + NewImageName, System.IO.FileMode.Create)))
    {
        document.Open();           

        using (System.Drawing.Bitmap bm = new System.Drawing.Bitmap(singlefile))
        {
            int total = bm.GetFrameCount(FrameDimension.Page);

            iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

            for (int k = 0; k < total; ++k)
            {
                bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);

                // scale the image to fit in the page  
                img.ScalePercent(72f / img.DpiX * 100);
                img.SetAbsolutePosition(0, 0);
                cb.AddImage(img);
                document.NewPage();
            }
        }

        document.Close();
        writer.Close();
    }
}

0 个答案:

没有答案