TXT手帳変換PDFファイル

2997 ワード

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