首页 > 学院 > 开发设计 > 正文

TXT记事本转换PDF文件

2019-11-17 02:35:22
字体:
来源:转载
供稿:网友

TXT记事本转换PDF文件

使用的方式为,读取TXT记事本的内容,然后写入创建的PDF文件。

        static void Main(string[] args)        {            const string txtFile = "D://1.txt";            const string pdfFile = "D://1.pdf";            var document = new Document(PageSize.A4, 30f, 30f, 30f, 30f);            PdfWriter.getInstance(document, new FileStream(pdfFile, FileMode.Create));            document.Open();            var bfSun = BaseFont.createFont(@"C:/Windows/Fonts/simfang.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);            var font = new Font(bfSun, 12f);            var objReader = new StreamReader(txtFile, Encoding.GetEncoding("gb2312"));            var str = "";            while (str != null)            {                str = objReader.ReadLine();                if (str != null)                {                    document.Add(new Paragraph(str, font));                }            }            objReader.Close();            document.Close();        }

示例下载:txtTopdf.zip


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表