pdf from string code example
Example: how to convert c# string to pdf
//Create a new PDF documentPdfDocument document = new PdfDocument();//Add a page to the documentPdfPage page = document.Pages.Add();//Create PDF graphics for the pagePdfGraphics graphics = page.Graphics;//set the standard fontPdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);//Read the text from the text fileStreamReader reader = new StreamReader("input.txt", Encoding.ASCII);string text = reader.ReadToEnd();reader.Close();//Set the formats for the textPdfStringFormat format = new PdfStringFormat();format.Alignment = PdfTextAlignment.Justify;format.LineAlignment = PdfVerticalAlignment.Top;format.ParagraphIndent = 15f;//Draw the textgraphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(new PointF(0,0), page.GetClientSize()), format);//Save the documentdocument.Save("OutputText.pdf");//Close the documentdocument.Close(true);//This will open the PDF file so, the result will be seen in default PDF viewerProcess.Start("OutputText.pdf");Copy