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.

Thu Nov 07, 2019 10:19 pm

Hello,

I have two long paragraph of text (wordwarp is necessary) with different font styles I want to write to a pdf file. I need them to be separated by specific amount of space. I can't find a way to do it in spire.pdf, can you help?

patrick551
 
Posts: 8
Joined: Mon Dec 17, 2018 6:46 pm

Fri Nov 08, 2019 6:46 am

Hi,

Thanks for your inquiry.
Please refer to the code below to draw two long text with different font style on Pdf page. And I have attached my result Pdf file here, please check it.
Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4);
            PdfSection sec = doc.Sections.Add();

            //draw the first string on Pdf page
            string s1 = "Spire.PDF owns the ability of drawing text in PDF document. It supports text formatting, multilingual and text extraction. Here we will introduce how to draw text in PDF with different styles. ";
            //set the font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Helvetica", 18f, FontStyle.Regular));
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            RectangleF re = new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height);
            page.Canvas.DrawString(s1, font, brush1, re);

            //draw the second string on Pdf page
            string s2 = "Spire.PDF enables users to draw rotate text in PDF, draw transform text in PDF, draw alignment text in PDF, draw alignment text in rectangle and other style settings such as font, size, color, pen, etc.";
            //set the font
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("TimesRoman", 12f, FontStyle.Italic));
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.Red);
            RectangleF re1 = new RectangleF(0, 150, page.GetClientSize().Width, page.GetClientSize().Height);
            page.Canvas.DrawString(s2, font1, brush2, re1);

            doc.SaveToFile("result.pdf", FileFormat.PDF);

If the code couldn't solve your issue, to help us investigate it accurately, please offer us the following information.
1. Your input long string.
2. Your desired result Pdf file.
You could upload them here or send us(support@e-iceblue.com) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Dec 03, 2019 9:08 am

Hi,

Greetings from E-iceblue.
Have you tried the code I offered you last time? Does it solve your issue? Could you please give us some feedback at your convenience?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF

cron