Regards, Sheo Narayan http://www.dotnetfunda.com
using Spire.Pdf;using System.IO;using Spire.Pdf.Graphics;using System.Drawing;namespace TexttoPDF{ class Program { static void Main(string[] args) { string text = File.ReadAllText("TestDocument.txt"); PdfDocument doc = new PdfDocument(); PdfSection section = doc.Sections.Add(); PdfPageBase page = section.Pages.Add(); PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11); PdfStringFormat format = new PdfStringFormat(); format.LineSpacing = 20f; PdfBrush brush = PdfBrushes.Black; PdfTextWidget textWidget = new PdfTextWidget(text, font, brush); float y = 0; PdfTextLayout textLayout = new PdfTextLayout(); textLayout.Break = PdfLayoutBreakType.FitPage; textLayout.Layout = PdfLayoutType.Paginate; RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize); textWidget.StringFormat = format; textWidget.Draw(page, bounds, textLayout); doc.SaveToFile("TxtToPDf.pdf", FileFormat.PDF); } }
Login to post response