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.

Mon Sep 20, 2021 5:54 am

I tried make the width smaller, but then how can i make the percentage number margin to the left a bit

alpha = alphabert
name = long text as the image
id = numbers inside the bracket
sharealc = the percentage number

Code: Select all

    private static void DrawBeneficiary(ref RectangleF rect, PdfSection section, ref PdfPageBase page, PdfMargins margin, float x, ref float y, List<String> benefiDetails)
    {
        PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 12f));
        PdfStringFormat alignJustify = new PdfStringFormat(PdfTextAlignment.Justify);
        PdfStringFormat alignRight = new PdfStringFormat(PdfTextAlignment.Right);
        alignJustify.LineSpacing = font3.Height * 1.2f;
        alignRight.LineSpacing = font3.Height * 1.2f;
        float pageWidth = page.Canvas.ClientSize.Width;
        float xTab1 = 20;

        float pageTab1Width = page.Canvas.ClientSize.Width - xTab1 - 30;
        string alpha = benefiDetails[0];
        string name = benefiDetails[1];
        string id = benefiDetails[2];
        string sharealc = benefiDetails[3];
        string text1 = alpha + name + id;
        float checkBreakPoint = rect.Location.Y + (font3.MeasureString(text1, alignJustify).Height) + 5;
       
        //Check whether require to continue next page START
        if (checkBreakPoint > (page.Canvas.ClientSize.Height - margin.Bottom))
        {

            page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, true);
            y = margin.Top;
            rect = new RectangleF(rect.Location.X, y, rect.Width, rect.Height);

        }
        //Check whether require to continue next page START END

        //Draw Content Beneficary
        rect = new RectangleF(xTab1, rect.Location.Y, pageTab1Width, rect.Height);
        InsertFlexiContent1(page, rect, text1, true);

        //Draw ShareAlc align right
        text1 = sharealc;
        //Render HTML text
        PdfBrush brush = PdfBrushes.Black;
        PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(text1, font3, brush);
        richTextElement.TextAlign = Spire.Pdf.Graphics.TextAlign.Right;


        //Format Layout
       
        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
        format.Layout = PdfLayoutType.Paginate;
        format.Break = PdfLayoutBreakType.FitPage;

        float getNumberOfLine = calculateHeightLength(page, font3.MeasureString(text1).Width, rect.Width);

        getNumberOfLine++;

        //Draw htmlString
        richTextElement.Draw(page.Canvas, rect);
        float rect_y = rect.Location.Y + (font3.MeasureString(text1, alignRight).Height * getNumberOfLine) + 5; //Add new line(s) and move down 5

        rect = new RectangleF(rect.Location.X, rect_y, rect.Width, rect.Height);
    }

    private static RectangleF InsertFlexiContent1(PdfPageBase page, RectangleF rect, string htmlText, bool blnAddLine)
    {
        //Render HTML text
        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f));
        PdfStringFormat alignJustify = new PdfStringFormat(PdfTextAlignment.Left);
        alignJustify.LineSpacing = font.Height * 1.2f;
        PdfBrush brush = PdfBrushes.Black;
        PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, font, brush);
        richTextElement.TextAlign = Spire.Pdf.Graphics.TextAlign.Left;

        //Format Layout
        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
        format.Layout = PdfLayoutType.Paginate;
        format.Break = PdfLayoutBreakType.FitPage;

        float getNumberOfLine = calculateHeightLength(page, font.MeasureString(htmlText).Width, rect.Width);

        if (blnAddLine)
        {
            getNumberOfLine++;
        }

        //Draw htmlString
        if (htmlText.Contains("<b>") || htmlText.Contains("<i>"))
        {
            richTextElement.Draw(page.Canvas, rect);
        }
        else
        {
            page.Canvas.DrawString(htmlText, font, brush, rect, alignJustify);
        }

        float y = rect.Location.Y + (font.MeasureString(htmlText, alignJustify).Height * getNumberOfLine) + 5; //Add new line(s) and move down 5

        rect = new RectangleF(rect.Location.X, y, rect.Width, rect.Height);

        return rect;

    }



Image

lean5503
 
Posts: 10
Joined: Thu Sep 09, 2021 2:41 am

Mon Sep 20, 2021 1:36 pm

I done fixed! Btw, thank you so much @Brian.Li for your help!
Wish you stay safe and healthy!

Code: Select all
    private static void DrawBeneficiary(ref RectangleF rect, PdfSection section, ref PdfPageBase page, PdfMargins margin, float x, ref float y, List<String> benefiDetails)
    {
        PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 12f));
        PdfStringFormat alignJustify = new PdfStringFormat(PdfTextAlignment.Justify);
        PdfStringFormat alignRight = new PdfStringFormat(PdfTextAlignment.Right);
        alignJustify.LineSpacing = font3.Height * 1.2f;
        alignRight.LineSpacing = font3.Height * 1.2f;
        float pageWidth = page.Canvas.ClientSize.Width;
        float xTab1 = 20;

        float pageTab1Width = page.Canvas.ClientSize.Width - xTab1 -30 ;
        float pageTab1Width2 = page.Canvas.ClientSize.Width - xTab1;

        string alpha = benefiDetails[0];
        string name = benefiDetails[1];
        string id = benefiDetails[2];
        string sharealc = benefiDetails[3];
        string text1 = alpha + name + id;
        float checkBreakPoint = rect.Location.Y + (font3.MeasureString(text1, alignJustify).Height) + 5;
       
        //Check whether require to continue next page START
        if (checkBreakPoint > (page.Canvas.ClientSize.Height - margin.Bottom))
        {

            page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, true);
            y = margin.Top;
            rect = new RectangleF(rect.Location.X, y, rect.Width, rect.Height);

        }
        //Check whether require to continue next page START END

        //Draw Content Beneficary
        rect = new RectangleF(xTab1, rect.Location.Y, pageTab1Width, rect.Height);
        InsertFlexiContent1(page, rect, text1, true);



        //Draw ShareAlc align right
        text1 = sharealc;
        //Render HTML text
        PdfBrush brush = PdfBrushes.Black;
        PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(text1, font3, brush);
        richTextElement.TextAlign = Spire.Pdf.Graphics.TextAlign.Right;


        //Format Layout
       
        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
        format.Layout = PdfLayoutType.Paginate;
        format.Break = PdfLayoutBreakType.FitPage;

        float getNumberOfLine = calculateHeightLength(page, font3.MeasureString(text1).Width, rect.Width);

        getNumberOfLine++;

        //Draw htmlString
        RectangleF rect2 = new RectangleF(xTab1, rect.Location.Y, pageTab1Width2, rect.Height);
        richTextElement.Draw(page.Canvas, rect2);
        float rect_y = rect.Location.Y + (font3.MeasureString(text1, alignRight).Height * getNumberOfLine) + 5; //Add new line(s) and move down 5

        rect = new RectangleF(rect.Location.X, rect_y, rect.Width, rect.Height);
    }

lean5503
 
Posts: 10
Joined: Thu Sep 09, 2021 2:41 am

Tue Sep 21, 2021 5:42 am

Hi,

Glad to inform that your issue has been fixed by yourself.
If you have other questions, please do not hesitate to contact us.
Wish you all the best :D

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF

cron