public float[] DrawOn(Page page) { if (numberOfRows == 0) { return(new float[] { x, y }); } float boxHeight = rowHeight * numberOfRows; Box box = new Box(); box.SetLocation(x, y); box.SetSize(rowLength, boxHeight); box.DrawOn(page); float field_y = 0f; int row_span = 1; float row_y = 0; foreach (Field field in fields) { if (field.x == 0f) { row_y += row_span * rowHeight; row_span = field.values.Length; } field_y = row_y; for (int i = 0; i < field.values.Length; i++) { Font font = (i == 0) ? f1 : f2; float fontSize = (i == 0) ? labelFontSize : valueFontSize; int color = (i == 0) ? labelColor : valueColor; new TextLine(font, field.values[i]) .SetFontSize(fontSize) .SetColor(color) .PlaceIn(box, field.x + f1.GetDescent(), field_y - font.GetDescent()) .SetAltDescription((i == 0) ? field.altDescription[i] : (field.altDescription[i] + ",")) .SetActualText((i == 0) ? field.actualText[i] : (field.actualText[i] + ",")) .DrawOn(page); endOfLinePoints.Add(new float[] { field.x + f1.GetDescent() + font.StringWidth(field.values[i]), field_y - font.GetDescent(), }); if (i == (field.values.Length - 1)) { new Line(0f, 0f, rowLength, 0f) .PlaceIn(box, 0f, field_y) .DrawOn(page); if (field.x != 0f) { new Line(0f, -(field.values.Length - 1) * rowHeight, 0f, 0f) .PlaceIn(box, field.x, field_y) .DrawOn(page); } } field_y += rowHeight; } } return(new float[] { x + rowLength, y + boxHeight }); }
public Example_01() { FileStream fos = new FileStream("Example_01.pdf", FileMode.Create); BufferedStream bos = new BufferedStream(fos); PDF pdf = new PDF(bos); pdf.setCompressor(Compressor.ORIGINAL_ZLIB); Page page = new Page(pdf, Letter.PORTRAIT); Box flag = new Box(); flag.SetPosition(100.0, 100.0); flag.SetSize(190.0, 100.0); flag.SetColor(RGB.WHITE); flag.DrawOn(page); double sw = 7.69; // stripe width Line stripe = new Line(0.0, sw/2, 190.0, sw/2); stripe.SetWidth(sw); stripe.SetColor(RGB.OLD_GLORY_RED); for (int row = 0; row < 7; row++) { stripe.PlaceIn(flag, 0.0, row * 2 * sw); stripe.DrawOn(page); } Box union = new Box(); union.SetSize(76.0, 53.85); union.SetColor(RGB.OLD_GLORY_BLUE); union.SetFillShape(true); union.PlaceIn(flag, 0.0, 0.0); union.DrawOn(page); double h_si = 12.6; // horizontal star interval double v_si = 10.8; // vertical star interval Point star = new Point(h_si/2, v_si/2); star.SetShape(Point.STAR); star.SetRadius(3.0); star.SetColor(RGB.WHITE); star.SetFillShape(true); for (int row = 0; row < 6; row++) { for (int col = 0; col < 5; col++) { star.PlaceIn(union, row * h_si, col * v_si); star.DrawOn(page); } } star.SetPosition(h_si, v_si); for (int row = 0; row < 5; row++) { for (int col = 0; col < 4; col++) { star.PlaceIn(union, row * h_si, col * v_si); star.DrawOn(page); } } pdf.Flush(); bos.Close(); }
private void DrawBackground( Page page, double x, double y, double cell_w, double cell_h) { page.SetBrushColor(brushColor[0], brushColor[1], brushColor[2]); Box box = new Box(x, y, cell_w, cell_h); box.SetColor(bgColor); box.SetFillShape(true); box.DrawOn(page); }
public float[] DrawOn(Page page) { float xText = x; float yText = y + font.ascent; while (paragraphs.Count > 0) { // The paragraphs are reversed so we can efficiently remove the first one: TextLine textLine = paragraphs[paragraphs.Count - 1]; paragraphs.RemoveAt(paragraphs.Count - 1); textLine.SetLocation(xText, yText); beginParagraphPoints.Add(new float[] { xText, yText }); while (true) { textLine = DrawLineOnPage(textLine, page); if (textLine.GetText().Equals("")) { break; } yText = textLine.Advance(leading); if (yText + font.descent >= (y + h)) { // The paragraphs are reversed so we can efficiently add new first paragraph: paragraphs.Add(textLine); if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } return(new float[] { x + w, y + h }); } } xText = x; yText += paragraphLeading; } if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } return(new float[] { x + w, y + h }); }
public float[] DrawOn(Page page) { this.xText = x1; this.yText = y1 + font.GetAscent(); foreach (Paragraph paragraph in paragraphs) { int numberOfTextLines = paragraph.list.Count; StringBuilder buf = new StringBuilder(); for (int i = 0; i < numberOfTextLines; i++) { TextLine textLine = paragraph.list[i]; buf.Append(textLine.text); } for (int i = 0; i < numberOfTextLines; i++) { TextLine textLine = paragraph.list[i]; if (i == 0) { beginParagraphPoints.Add(new float[] { xText, yText }); } textLine.SetAltDescription((i == 0) ? buf.ToString() : Single.space); textLine.SetActualText((i == 0) ? buf.ToString() : Single.space); float[] point = DrawTextLine(page, xText, yText, textLine); xText = point[0]; if (textLine.GetTrailingSpace()) { xText += spaceBetweenTextLines; } yText = point[1]; } xText = x1; yText += paragraphLeading; } float height = ((yText - paragraphLeading) - y1) + font.descent; if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x1, y1); box.SetSize(width, height); box.DrawOn(page); } return(new float[] { x1 + width, y1 + height }); }
public Example_02() { FileStream fos = new FileStream("Example_02.pdf", FileMode.Create); BufferedStream bos = new BufferedStream(fos); PDF pdf = new PDF(bos); pdf.setCompressor(Compressor.ORIGINAL_ZLIB); Page page = new Page(pdf, Letter.PORTRAIT); Box flag = new Box(85, 85, 64, 32); PDFjet.NET.Path path = new PDFjet.NET.Path(); path.Add(new Point(13.0, 0.0)); path.Add(new Point(15.5, 4.5)); path.Add(new Point(18.0, 3.5)); path.Add(new Point(15.5, 13.5, Point.IS_CURVE_POINT)); path.Add(new Point(15.5, 13.5, Point.IS_CURVE_POINT)); path.Add(new Point(20.5, 7.5, Point.IS_CURVE_POINT)); path.Add(new Point(21.0, 9.5)); path.Add(new Point(25.0, 9.0)); path.Add(new Point(24.0, 13.0)); path.Add(new Point(25.5, 14.0)); path.Add(new Point(19.0, 19.0)); path.Add(new Point(20.0, 21.5)); path.Add(new Point(13.5, 20.5)); path.Add(new Point(13.5, 27.0)); path.Add(new Point(12.5, 27.0)); path.Add(new Point(12.5, 20.5)); path.Add(new Point( 6.0, 21.5)); path.Add(new Point( 7.0, 19.0)); path.Add(new Point( 0.5, 14.0)); path.Add(new Point( 2.0, 13.0)); path.Add(new Point( 1.0, 9.0)); path.Add(new Point( 5.0, 9.5)); path.Add(new Point( 5.5, 7.5)); path.Add(new Point(10.5, 13.5, Point.IS_CURVE_POINT)); path.Add(new Point(10.5, 13.5, Point.IS_CURVE_POINT)); path.Add(new Point( 8.0, 3.5, Point.IS_CURVE_POINT)); path.Add(new Point(10.5, 4.5)); path.setClosePath(true); path.SetColor(RGB.RED); path.SetFillShape(true); path.PlaceIn(flag, 19.0, 3.0); path.DrawOn(page); Box box = new Box(); box.SetSize(16, 32); box.SetColor(RGB.RED); box.SetFillShape(true); box.PlaceIn(flag, 0.0, 0.0); box.DrawOn(page); box.PlaceIn(flag, 48.0, 0.0); box.DrawOn(page); path.ScaleBy(15.0); path.SetFillShape(false); path.DrawOn(page); pdf.Flush(); bos.Close(); }
/// <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); }
public float[] DrawOn(Page page) { if (numberOfRows == 0) { return new float[] { x, y }; } float boxHeight = rowHeight*numberOfRows; Box box = new Box(); box.SetLocation(x, y); box.SetSize(rowLength, boxHeight); box.DrawOn(page); float field_y = 0f; int row_span = 1; float row_y = 0; foreach (Field field in fields) { if (field.x == 0f) { row_y += row_span*rowHeight; row_span = field.values.Length; } field_y = row_y; for (int i = 0; i < field.values.Length; i++) { Font font = (i == 0) ? f1 : f2; float fontSize = (i == 0) ? labelFontSize : valueFontSize; int color = (i == 0) ? labelColor : valueColor; new TextLine(font, field.values[i]) .SetFontSize(fontSize) .SetColor(color) .PlaceIn(box, field.x + f1.GetDescent(), field_y - font.GetDescent()) .SetAltDescription((i == 0) ? field.altDescription[i] : (field.altDescription[i] + ",")) .SetActualText((i == 0) ? field.actualText[i] : (field.actualText[i] + ",")) .DrawOn(page); endOfLinePoints.Add(new float[] { field.x + f1.GetDescent() + font.StringWidth(field.values[i]), field_y - font.GetDescent(), }); if (i == (field.values.Length - 1)) { new Line(0f, 0f, rowLength, 0f) .PlaceIn(box, 0f, field_y) .DrawOn(page); if (field.x != 0f) { new Line(0f, -(field.values.Length-1)*rowHeight, 0f, 0f) .PlaceIn(box, field.x, field_y) .DrawOn(page); } } field_y += rowHeight; } } return new float[] { x + rowLength, y + boxHeight }; }
/** * Draws this form on the specified page. * * @param page the page to draw on. * @return x and y coordinates of the bottom right corner of this component. * @throws Exception */ public float[] DrawOn(Page page) { foreach (Field field in fields) { if (field.format) { field.values = Format(field.values[0], field.values[1], this.f2, this.rowLength); field.altDescription = new String[field.values.Length]; field.actualText = new String[field.values.Length]; for (int i = 0; i < field.values.Length; i++) { field.altDescription[i] = field.values[i]; field.actualText[i] = field.values[i]; } } if (field.x == 0f) { numberOfRows += field.values.Length; } } if (numberOfRows == 0) { return(new float[] { x, y }); } float boxHeight = rowHeight * numberOfRows; Box box = new Box(); box.SetLocation(x, y); box.SetSize(rowLength, boxHeight); if (page != null) { box.DrawOn(page); } float yField = 0f; int rowSpan = 1; float yRow = 0; foreach (Field field in fields) { if (field.x == 0f) { yRow += rowSpan * rowHeight; rowSpan = field.values.Length; } yField = yRow; for (int i = 0; i < field.values.Length; i++) { if (page != null) { Font font = (i == 0) ? f1 : f2; float fontSize = (i == 0) ? labelFontSize : valueFontSize; int color = (i == 0) ? labelColor : valueColor; new TextLine(font, field.values[i]) .SetFontSize(fontSize) .SetColor(color) .PlaceIn(box, field.x + font.descent, yField - font.descent) .SetAltDescription((i == 0) ? field.altDescription[i] : (field.altDescription[i] + ",")) .SetActualText((i == 0) ? field.actualText[i] : (field.actualText[i] + ",")) .DrawOn(page); endOfLinePoints.Add(new float[] { field.x + f1.descent + font.StringWidth(field.values[i]), yField + font.descent, }); if (page != null && i == (field.values.Length - 1)) { new Line(0f, 0f, rowLength, 0f) .PlaceIn(box, 0f, yField) .DrawOn(page); if (field.x != 0f) { new Line(0f, -(field.values.Length - 1) * rowHeight, 0f, 0f) .PlaceIn(box, field.x, yField) .DrawOn(page); } } } yField += rowHeight; } } return(new float[] { x + rowLength, y + boxHeight }); }
private float[] DrawText(Page page) { List <String> list = new List <String>(); String[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (String line in lines) { if (IsCJK(line)) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < line.Length; i++) { Char ch = line[i]; if (font.StringWidth(fallbackFont, buf.ToString() + ch) < this.w) { buf.Append(ch); } else { list.Add(buf.ToString()); buf.Length = 0; buf.Append(ch); } } String str = buf.ToString().Trim(); if (!str.Equals("")) { list.Add(str); } } else { if (font.StringWidth(fallbackFont, line) < this.w) { list.Add(line); } else { StringBuilder buf = new StringBuilder(); String[] tokens = TextUtils.SplitTextIntoTokens(line, font, fallbackFont, this.w); foreach (String token in tokens) { if (font.StringWidth(fallbackFont, (buf.ToString() + " " + token).Trim()) < this.w) { buf.Append(" " + token); } else { list.Add(buf.ToString().Trim()); buf.Length = 0; buf.Append(token); } } String str = buf.ToString().Trim(); if (!str.Equals("")) { list.Add(str); } } } } lines = list.ToArray(); float xText; float yText = y + font.ascent; for (int i = 0; i < lines.Length; i++) { if (textAlign == Align.LEFT) { xText = x; } else if (textAlign == Align.RIGHT) { xText = (x + this.w) - (font.StringWidth(fallbackFont, lines[i])); } else if (textAlign == Align.CENTER) { xText = x + (this.w - font.StringWidth(fallbackFont, lines[i])) / 2; } else { throw new Exception("Invalid text alignment option."); } if (page != null) { page.DrawString(font, fallbackFont, lines[i], xText, yText); } if (i < (lines.Length - 1)) { yText += font.bodyHeight + spaceBetweenLines; } } this.h = (yText - y) + font.descent; if (page != null && drawBorder) { Box box = new Box(); box.SetLocation(x, y); box.SetSize(w, h); box.DrawOn(page); } if (page != null && (uri != null || key != null)) { page.AddAnnotation(new Annotation( uri, key, // The destination name x, y, x + w, y + h, uriLanguage, uriAltDescription, uriActualText)); } return(new float[] { this.x + this.w, this.y + this.h }); }