/// <summary> /// Generate lines, boxes, watermark and default text of a single voter card. /// </summary> /// <param name="page">The page containing the card.</param> /// <param name="pdf">The pdf containing the page.</param> /// <param name="xO">The horizontal offset of the card in points.</param> /// <param name="yO">The vertical offset of the card in points.</param> private static void GenerateCard(Page page, PDF pdf, double xO, double yO) { // Add watermark. var font = new Font(pdf, CoreFont.HELVETICA_BOLD); font.SetSize(55); var t = new TextLine(font, "FAKE VALGKORT"); var lightBlue = new[] { 0.647, 0.812, 0.957 }; t.SetColor(lightBlue); t.SetPosition(xO + 20 * U, yO + 50 * U); t.DrawOn(page); // Add 'Afstemningssted' box. var b = new Box(xO + 6 * U, yO + 20 * U, 80 * U, 22 * U); b.DrawOn(page); // Add 'Valgbord' box. b = new Box(xO + 6 * U, yO + 44.5 * U, 80 * U, 7 * U); b.DrawOn(page); // Add 'Vælgernr' box. b = new Box(xO + 6 * U, yO + 54 * U, 80 * U, 7 * U); b.DrawOn(page); // Add 'Afstemningstid' box. b = new Box(xO + 6 * U, yO + 63.5 * U, 80 * U, 7 * U); b.DrawOn(page); // Add lines. var l = new Line(xO + 96 * U, yO + 5 * U, xO + 96 * U, yO + 85 * U); l.DrawOn(page); l = new Line(xO + 96 * U, yO + 25 * U, xO + 205 * U, yO + 25 * U); l.DrawOn(page); l = new Line(xO + 96 * U, yO + 45 * U, xO + 205 * U, yO + 45 * U); l.DrawOn(page); l = new Line(xO + 6 * U, yO + 85 * U, xO + 205 * U, yO + 85 * U); l.DrawOn(page); // Add default text. font = new Font(pdf, CoreFont.HELVETICA); font.SetSize(7); t = new TextLine(font, "Afstemningssted:"); t.SetPosition(xO + 7 * U, yO + 23 * U); t.DrawOn(page); t = new TextLine(font, "Vælgernr.:"); t.SetPosition(xO + 7 * U, yO + 58 * U); t.DrawOn(page); t = new TextLine(font, "Afstemningstid:"); t.SetPosition(xO + 7 * U, yO + 68 * U); t.DrawOn(page); t = new TextLine(font, "Afsender:"); t.SetPosition(xO + 98 * U, yO + 29 * U); t.DrawOn(page); t = new TextLine(font, "Modtager:"); t.SetPosition(xO + 98 * U, yO + 49 * U); t.DrawOn(page); font = new Font(pdf, CoreFont.HELVETICA); font.SetSize(9); t = new TextLine(font, "Folketingsvalg"); t.SetPosition(xO + 7 * U, yO + 10 * U); t.DrawOn(page); t = new TextLine(font, "20. november 2001"); t.SetPosition(xO + 7 * U, yO + 14 * U); t.DrawOn(page); t = new TextLine(font, "Valgbord:"); t.SetPosition(xO + 7 * U, yO + 49 * U); t.DrawOn(page); font = new Font(pdf, CoreFont.HELVETICA_OBLIQUE); font.SetSize(7); t = new TextLine(font, "Medbring kortet ved afstemningen"); t.SetPosition(xO + 6.5 * U, yO + 18.5 * U); t.DrawOn(page); }
private Point DrawParagraphOn( Page page, Paragraph paragraph, bool draw) { List <TextLine> list = new List <TextLine>(); float run_length = 0f; for (int i = 0; i < paragraph.list.Count; i++) { TextLine line = paragraph.list[i]; if (i == 0) { line_height = line.font.body_height + space_between_lines; if (rotate == 0) { y1 += line.font.ascent; } else if (rotate == 90) { x1 += line.font.ascent; } else if (rotate == 270) { x1 -= line.font.ascent; } } String[] tokens = line.str.Split(new Char[] { ' ', '\r', '\n', '\t' }); TextLine text = null; for (int j = 0; j < tokens.Length; j++) { String str = tokens[j]; text = new TextLine(line.font, str); text.SetColor(line.GetColor()); text.SetUnderline(line.GetUnderline()); text.SetStrikeout(line.GetStrikeout()); text.SetURIAction(line.GetURIAction()); text.SetGoToAction(line.GetGoToAction()); text.SetFallbackFont(line.GetFallbackFont()); run_length += line.font.StringWidth(line.GetFallbackFont(), str); if (run_length >= w) { DrawLineOfText(page, list, draw); MoveToNextLine(); list.Clear(); list.Add(text); run_length = line.font.StringWidth(line.GetFallbackFont(), str + " "); } else { list.Add(text); run_length += line.font.StringWidth(line.GetFallbackFont(), " "); } } } DrawNonJustifiedLine(page, list, draw); if (lineBetweenParagraphs) { return(MoveToNextLine()); } return(MoveToNextParagraph(this.space_between_paragraphs)); }
private Point DrawParagraphOn( Page page, Paragraph paragraph, bool draw) { List<TextLine> list = new List<TextLine>(); float run_length = 0f; for (int i = 0; i < paragraph.list.Count; i++) { TextLine line = paragraph.list[i]; if (i == 0) { line_height = line.font.body_height + space_between_lines; if (rotate == 0) { y1 += line.font.ascent; } else if (rotate == 90) { x1 += line.font.ascent; } else if (rotate == 270) { x1 -= line.font.ascent; } } String[] tokens = line.str.Split(new Char[] {' ', '\r', '\n', '\t'}); TextLine text = null; for (int j = 0; j < tokens.Length; j++) { String str = tokens[j]; text = new TextLine(line.font, str); text.SetColor(line.GetColor()); text.SetUnderline(line.GetUnderline()); text.SetStrikeout(line.GetStrikeout()); text.SetURIAction(line.GetURIAction()); text.SetGoToAction(line.GetGoToAction()); text.SetFallbackFont(line.GetFallbackFont()); run_length += line.font.StringWidth(line.GetFallbackFont(), str); if (run_length >= w) { DrawLineOfText(page, list, draw); MoveToNextLine(); list.Clear(); list.Add(text); run_length = line.font.StringWidth(line.GetFallbackFont(), str + " "); } else { list.Add(text); run_length += line.font.StringWidth(line.GetFallbackFont(), " "); } } } DrawNonJustifiedLine(page, list, draw); if (lineBetweenParagraphs) { return MoveToNextLine(); } return MoveToNextParagraph(this.space_between_paragraphs); }