Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Mar 20, 2020 11:04 am

How to set text indent to the string in pdf?

ushanandhini_1297
 
Posts: 16
Joined: Mon Apr 20, 2015 11:34 am

Mon Mar 23, 2020 7:10 am

Hi,

Thanks for your post.
Please refer to the following code to set indent.
Code: Select all
 PdfDocument pdf = new PdfDocument();
  PdfPageBase page = pdf.Pages.Add();
            String text = "Spire.PDF for .NET is a professional PDF API applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core) application. Using this .NET PDF library, you can implement rich capabilities to create PDF files from scratch or process existing PDF documents entirely through C#/VB.NET without installing Adobe Acrobat.";
     
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();
            //Set indent
            format.ParagraphIndent = font.Size * 2;
            format.MeasureTrailingSpaces = true;
         
            PdfTextWidget textWidget = new PdfTextWidget(text, font, PdfBrushes.Black);
            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            RectangleF bounds = new RectangleF(new PointF(0, 10), page.Canvas.ClientSize);
            textWidget.StringFormat = format;
            textWidget.Draw(page, bounds, textLayout);
            String output = "C:/result.pdf";
            pdf.SaveToFile(output);


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF