コード例 #1
0
        //对于无法转换为图片的电子原件,生成一个文件属性页
        //在空白页的中间,显示原件的描述
        public static void MakeErrorImageDocument(string sTitle, string outFileName)
        {
            #region 对于无法转换为图片的电子原件,生成一个文件属性页
            iTextSharp.text.Document document = new iTextSharp.text.Document();

            string   fontDir = System.IO.Directory.GetParent(System.Environment.SystemDirectory) + "\\fonts\\SIMSUN.TTC,1";
            BaseFont bfSun   = BaseFont.createFont(@fontDir, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font     font    = new Font(bfSun, 16, 0);
            try
            {
                PdfWriter writer = PdfWriter.getInstance(document, new FileStream(outFileName, FileMode.Create));
                document.Open();
                document.setPageSize(PageSize.A4);
                document.setMargins(72, 0, 72, 0);

                Table table = new Table(1);
                table.BorderWidth = 0;

                Cell cell = new Cell();
                cell.Leading     = 300;
                cell.BorderWidth = 0;
                table.addCell(cell);

                cell = new Cell();
                cell.Add(new Paragraph(sTitle, setFont("楷体", 24, false)));
                cell.Add(new Paragraph("(不支持此文件类型或者文件已损坏)", setFont("楷体", 24, false)));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BorderWidth         = 0;
                table.addCell(cell);

                document.Add(table);
            }
            finally
            {
                document.Close();
            }
            #endregion
        }