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;
}
