public override void DrawRectangle(IPen pen, IColor fillColor, float x, float y, float width, float height) { x = CheckVal(x, false); y = CheckVal(y, true, height); width = CheckVal(width); height = CheckVal(height); fCanvas.Rectangle(x, y, width, height); if (pen != null && !fillColor.IsTransparent()) { SetPen(pen); SetFillColor(fillColor); fCanvas.ClosePathFillStroke(); } else if (pen != null) { SetPen(pen); fCanvas.ClosePathStroke(); } else if (!fillColor.IsTransparent()) { SetFillColor(fillColor); fCanvas.Fill(); } }
/// <summary> /// Add a filled and stroked rectangle /// </summary> /// <returns></returns> private void addFillRectangle(float x, float y, float width, float height, StyleInfo styleInfo) { //first design the filled rectangle addFillRectangle(x, y, width, height, styleInfo.BackgroundColor); //second, stroke the rectangle pdfContent.SetColorStroke(new BaseColor(styleInfo.Color)); pdfContent.ClosePathStroke(); }
public void StrokeAndFill(){ MetaPen pen = state.CurrentPen; MetaBrush brush = state.CurrentBrush; int penStyle = pen.Style; int brushStyle = brush.Style; if (penStyle == MetaPen.PS_NULL) { cb.ClosePath(); if (state.PolyFillMode == MetaState.ALTERNATE) { cb.EoFill(); } else { cb.Fill(); } } else { bool isBrush = (brushStyle == MetaBrush.BS_SOLID || (brushStyle == MetaBrush.BS_HATCHED && state.BackgroundMode == MetaState.OPAQUE)); if (isBrush) { if (state.PolyFillMode == MetaState.ALTERNATE) cb.ClosePathEoFillStroke(); else cb.ClosePathFillStroke(); } else { cb.ClosePathStroke(); } } }
private void exportToPDF_click(object sender, EventArgs e) { System.IO.FileStream fs = new FileStream("Graphics.pdf", FileMode.Create); Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(document, fs); document.Open(); PdfContentByte cb = writer.DirectContent; float scaling; float scalingY = (float)document.PageSize.Height / (max_y * 2); float scalingX = (float)document.PageSize.Width / (max_x * 2); if (scalingX < scalingY) { scaling = scalingX; } else { scaling = scalingY; } cb.SetColorStroke(new iTextSharp.text.BaseColor(Color.Red)); cb.MoveTo(0, document.PageSize.Height / 2); cb.LineTo(document.PageSize.Width, document.PageSize.Height / 2); cb.ClosePathStroke(); cb.MoveTo(document.PageSize.Width / 2, 0); cb.LineTo(document.PageSize.Width / 2, document.PageSize.Height); cb.ClosePathStroke(); foreach (GraphicObject gobject in list_gobjects) { gobject.draw(cb, document.PageSize.Width, document.PageSize.Height, scaling); } document.Close(); writer.Close(); fs.Close(); }
// --------------------------------------------------------------------------- /** * Draws the time table for a day at the film festival. * @param directcontent a canvas to which the time table has to be drawn. */ protected void DrawTimeTable(PdfContentByte directcontent) { directcontent.SaveState(); directcontent.SetLineWidth(1.2f); float llx, lly, urx, ury; llx = OFFSET_LEFT; lly = OFFSET_BOTTOM; urx = OFFSET_LEFT + WIDTH; ury = OFFSET_BOTTOM + HEIGHT; directcontent.MoveTo(llx, lly); directcontent.LineTo(urx, lly); directcontent.LineTo(urx, ury); directcontent.LineTo(llx, ury); directcontent.ClosePath(); directcontent.Stroke(); llx = OFFSET_LOCATION; lly = OFFSET_BOTTOM; urx = OFFSET_LOCATION + WIDTH_LOCATION; ury = OFFSET_BOTTOM + HEIGHT; directcontent.MoveTo(llx, lly); directcontent.LineTo(urx, lly); directcontent.LineTo(urx, ury); directcontent.LineTo(llx, ury); directcontent.ClosePathStroke(); directcontent.SetLineWidth(1); directcontent.MoveTo( OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM ); directcontent.LineTo( OFFSET_LOCATION + WIDTH_LOCATION / 2, OFFSET_BOTTOM + HEIGHT ); float y; for (int i = 1; i < LOCATIONS; i++) { y = OFFSET_BOTTOM + (i * HEIGHT_LOCATION); if (i == 2 || i == 6) { directcontent.MoveTo(OFFSET_LOCATION, y); directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y); } else { directcontent.MoveTo(OFFSET_LOCATION + WIDTH_LOCATION / 2, y); directcontent.LineTo(OFFSET_LOCATION + WIDTH_LOCATION, y); } directcontent.MoveTo(OFFSET_LEFT, y); directcontent.LineTo(OFFSET_LEFT + WIDTH, y); } directcontent.Stroke(); directcontent.RestoreState(); }
public override void draw(PdfContentByte cb, float doc_width, float doc_height, float scaling) { setScaling(scaling); base.draw(cb, doc_width, doc_height, scaling); cb.MoveTo(points[0].X + doc_width / 2, points[0].Y + doc_height / 2); cb.LineTo(points[1].X + doc_width / 2, points[1].Y + doc_height / 2); cb.ClosePathStroke(); }
protected internal override void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url) { if (si.BStyleTop != BorderStyleEnum.None) { switch (si.BStyleTop) { case BorderStyleEnum.Dashed: _contentByte.SetLineDash(new float[] { '3', '2' }, 0); break; case BorderStyleEnum.Dotted: _contentByte.SetLineDash(new float[] { '2' }, 0); break; case BorderStyleEnum.Solid: default: _contentByte.SetLineDash(new float[] { }, 0); break; } _contentByte.SetRgbColorStroke(si.BColorTop.R, si.BColorTop.G, si.BColorTop.B); } float RadiusX = (width / 2.0f); float RadiusY = (height / 2.0f); _contentByte.Ellipse(x, PageSize.yHeight - y, x + RadiusX, y + RadiusY); if (!si.BackgroundColor.IsEmpty) { _contentByte.SetRgbColorStrokeF(si.BackgroundColor.R, si.BackgroundColor.G, si.BackgroundColor.B); } if (si.BackgroundColor.IsEmpty) { _contentByte.ClosePathStroke(); } else { _contentByte.ClosePathFillStroke(); } }
/// <summary> /// Renders the object in a document using a <see cref="PdfContentByte"/> by invoking the <see cref="Render(ContentWriter, Vector2D)"/> method. /// This method can be overridden in derived classes to specify rendering. /// </summary> /// <param name="cb">The <see cref="PdfContentByte"/> used for rendering.</param> /// <param name="offset">The calculated offset for the rendered item.</param> protected internal virtual void Render(PdfContentByte cb, Vector2D offset) { using (var writer = new ContentWriter(cb)) { var stroke = this as StrokeObject; var fill = this as FillObject; bool hasstroke = stroke?.BorderColor.HasValue ?? false; bool hasfill = fill?.FillColor.HasValue ?? false; if (hasstroke) { cb.SetLineWidth((float)stroke.BorderWidth.Value(UnitsOfMeasure.Points)); cb.SetColorStroke(new Color(stroke.BorderColor.Value)); } if (hasfill) { cb.SetColorFill(new Color(fill.FillColor.Value)); } Render(writer, offset); if (hasstroke && hasfill) { if (writer.CloseShape) { cb.ClosePathFillStroke(); } else { cb.FillStroke(); } } else if (hasstroke) { if (writer.CloseShape) { cb.ClosePathStroke(); } else { cb.Stroke(); } } else if (hasfill) { cb.Fill(); } } }
public override void draw(PdfContentByte cb, float doc_width, float doc_height, float scaling) { setScaling(scaling); base.draw(cb, doc_width, doc_height, scaling); cb.Circle(points[0].X + doc_width / 2, points[0].Y + doc_height / 2, scaled_radius); if (filled) { cb.ClosePathFillStroke(); } else { cb.ClosePathStroke(); } }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); cb.SaveState(); cb.BeginText(); cb.SetFontAndSize(helv, 10); float textSize = 60; float textBase = 15; // Este lo pone la informacion en la parte inferior float x = 365 - (Dependencia.Length / 2) * 8; cb.SetTextMatrix(x, textBase); //Dependencia cb.ShowText(Dependencia); cb.SetFontAndSize(helv, 8); cb.SetTextMatrix(document.Left, textBase); //Fecha cb.ShowText(String.Format("{0}-{1}-{2}", PrintTime.Day, PrintTime.Month, PrintTime.Year)); cb.SetTextMatrix(document.Right - textSize, textBase); //Numero de pagina cb.ShowText(String.Format("Página {0} de ", writer.PageNumber)); cb.AddTemplate(total, document.Right - 15, textBase); cb.EndText(); //cb.SetRGBColorStroke(0x00, 0x00, 0x00); //cb.Rectangle(35, 10, 525, 20); //cb.Stroke(); cb.MoveTo(90, 25); //Linea horizontal cb.LineTo(90, 10); cb.MoveTo(490, 25); //Linea vertical 1 cb.LineTo(490, 10); cb.MoveTo(35, 25); //Linea vertical 2 cb.LineTo(560, 25); cb.ClosePathStroke(); cb.RestoreState(); }
public void StrokeAndFill() { var pen = _state.CurrentPen; var brush = _state.CurrentBrush; var penStyle = pen.Style; var brushStyle = brush.Style; if (penStyle == MetaPen.PS_NULL) { Cb.ClosePath(); if (_state.PolyFillMode == MetaState.Alternate) { Cb.EoFill(); } else { Cb.Fill(); } } else { var isBrush = (brushStyle == MetaBrush.BS_SOLID || (brushStyle == MetaBrush.BS_HATCHED && _state.BackgroundMode == MetaState.Opaque)); if (isBrush) { if (_state.PolyFillMode == MetaState.Alternate) { Cb.ClosePathEoFillStroke(); } else { Cb.ClosePathFillStroke(); } } else { Cb.ClosePathStroke(); } } }
// --------------------------------------------------------------------------- /** * Draws a row of squares. * @param canvas the canvas to which the squares have to be drawn * @param x X coordinate to position the row * @param y Y coordinate to position the row * @param side the side of the square * @param gutter the space between the squares */ public void CreateSquares(PdfContentByte canvas, float x, float y, float side, float gutter) { canvas.SaveState(); canvas.SetColorStroke(new GrayColor(0.2f)); canvas.SetColorFill(new GrayColor(0.9f)); canvas.MoveTo(x, y); canvas.LineTo(x + side, y); canvas.LineTo(x + side, y + side); canvas.LineTo(x, y + side); canvas.Stroke(); x = x + side + gutter; canvas.MoveTo(x, y); canvas.LineTo(x + side, y); canvas.LineTo(x + side, y + side); canvas.LineTo(x, y + side); canvas.ClosePathStroke(); x = x + side + gutter; canvas.MoveTo(x, y); canvas.LineTo(x + side, y); canvas.LineTo(x + side, y + side); canvas.LineTo(x, y + side); canvas.Fill(); x = x + side + gutter; canvas.MoveTo(x, y); canvas.LineTo(x + side, y); canvas.LineTo(x + side, y + side); canvas.LineTo(x, y + side); canvas.FillStroke(); x = x + side + gutter; canvas.MoveTo(x, y); canvas.LineTo(x + side, y); canvas.LineTo(x + side, y + side); canvas.LineTo(x, y + side); canvas.ClosePathFillStroke(); canvas.RestoreState(); }
protected void gvHorarios_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "View1") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow filaSeleccionada = gvHorarios.Rows[index]; String valor1 = filaSeleccionada.Cells[1].Text; String valor2 = filaSeleccionada.Cells[3].Text; String codigo = filaSeleccionada.Cells[0].Text; GridView1.Visible = true; BotonModificarAsistencia.Visible = true; BotonCancelar.Visible = true; Labelt1.Visible = true; Labelt2.Visible = true; Labelt1.Text = "Asistencia: " + valor1; Labelt2.Text = valor2; LabelCodigoHorario.Text = codigo; Consultar_Asistencia(); } if (e.CommandName == "View2") { int index0 = Convert.ToInt32(e.CommandArgument); GridViewRow filaSeleccionada0 = gvHorarios.Rows[index0]; String code = filaSeleccionada0.Cells[0].Text; BindGridViewData(code); int columnsCount = GridView2.HeaderRow.Cells.Count; PdfPTable pdfTable = new PdfPTable(columnsCount); foreach (TableCell gridViewHeaderCell in GridView2.HeaderRow.Cells) { Font font = new Font(); font.Color = new BaseColor(GridView2.HeaderStyle.ForeColor); PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewHeaderCell.Text, font)); pdfCell.BackgroundColor = new BaseColor(GridView2.HeaderStyle.BackColor); float[] values = new float[3]; values[0] = 30; values[1] = 85; values[2] = 20; pdfTable.SetWidths(values); pdfTable.AddCell(pdfCell); } foreach (GridViewRow gridViewRow in GridView2.Rows) { if (gridViewRow.RowType == DataControlRowType.DataRow) { foreach (TableCell gridViewCell in gridViewRow.Cells) { Font font = new Font(); font.Color = new BaseColor(GridView2.RowStyle.ForeColor); PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewCell.Text, font)); pdfCell.BackgroundColor = new BaseColor(GridView2.RowStyle.BackColor); //pdfCell.HorizontalAlignment=1; pdfTable.AddCell(pdfCell); } } } Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f); PdfWriter writer = PdfWriter.GetInstance(pdfDocument, Response.OutputStream); //iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(Server.MapPath(".") +"/imagenes/logo_2.jpg"); //imagen.BorderWidth = 0; //imagen.Alignment = Element.ALIGN_RIGHT; //float percentage = 0.0f; //percentage = 100 / imagen.Width; //imagen.ScalePercent(percentage * 100); //imagen.IndentationRight = 60; //imagen.IndentationLeft = 80; //imagen.ScaleToFit(100, 100); pdfDocument.Open(); //pdfDocument.Add(imagen); int index = Convert.ToInt32(e.CommandArgument); GridViewRow filaSeleccionada = gvHorarios.Rows[index]; String tituloe = filaSeleccionada.Cells[1].Text; String fechae = filaSeleccionada.Cells[3].Text; String descpe = filaSeleccionada.Cells[2].Text; //String entradae = filaSeleccionada.Cells[4].Text; //String salidae = filaSeleccionada.Cells[5].Text; //pdfDocument.Add(new Paragraph("Fecha:")); PdfContentByte cb = writer.DirectContent; ColumnText ct = new ColumnText(cb); Phrase myText = new Phrase("ASISTENCIA\n\nTitulo Entrenamiento: " + tituloe); ct.SetSimpleColumn(myText, 82, 820, 580, 317, 15, Element.ALIGN_LEFT); ct.Go(); PdfContentByte cb1 = writer.DirectContent; ColumnText ct1 = new ColumnText(cb1); Phrase myText1 = new Phrase("Fecha Asistencia: " + fechae + " \n\nDescripcion: " + descpe); ct1.SetSimpleColumn(myText1, 82, 740, 580, 317, 15, Element.ALIGN_LEFT); ct1.Go(); cb.MoveTo(70, 765); cb.LineTo(530, 765); cb.ClosePathStroke(); pdfDocument.Add(Chunk.NEWLINE); pdfDocument.Add(new Paragraph(" ")); pdfDocument.Add(Chunk.NEWLINE); pdfDocument.Add(new Paragraph(" ")); pdfDocument.Add(Chunk.NEWLINE); pdfDocument.Add(new Paragraph(" ")); pdfDocument.Add(pdfTable); pdfDocument.Close(); Response.ContentType = "application/pdf"; Response.AppendHeader("content-disposition", "attachment;filename=Asistencia_" + fechae + ".pdf"); Response.Write(pdfDocument); Response.Flush(); Response.End(); } }
public Stream getConstanciaVisita(Int32 VisitaCorretajeId) { try { var visita = context.VisitaCorretaje.FirstOrDefault(x => x.VisitaCorretajeId == VisitaCorretajeId); var nombre = String.Empty; byte[] pdfBytes; Document doc = new Document(PageSize.A4, 100f, 100f, 100f, 100f); using (MemoryStream output = new MemoryStream()) { Font font = FontFactory.GetFont(FontFactory.HELVETICA, 12); Font fontBold = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12); PdfWriter wri = PdfWriter.GetInstance(doc, output); doc.Open(); PdfContentByte cb = wri.DirectContent; cb.SetColorStroke(new CMYKColor(1f, 1f, 0f, 0.05f)); cb.MoveTo(14, 825);//70, 200); cb.LineTo(580, 825); cb.LineTo(580, 15); cb.LineTo(14, 15); cb.ClosePathStroke(); Image pic = Image.GetInstance(HttpContext.Current.Server.MapPath(@"~\Content\img\Logo Afari Transparente.png")); pic.ScaleAbsolute(120, 35); pic.SetAbsolutePosition(20, 780); doc.Add(pic); pic = Image.GetInstance(HttpContext.Current.Server.MapPath(@"~\Content\img\membretada\isotipoafari.png")); pic.ScaleAbsolute(269, 273); pic.SetAbsolutePosition(180, 350); doc.Add(pic); Paragraph paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); Paragraph header = new Paragraph("CONSTANCIA DE VISITA", fontBold) { Alignment = Element.ALIGN_CENTER }; doc.Add(header); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("CLIENTE: " + visita.Cliente.ToUpper(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("DATOS INMUEBLE", fontBold) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("DIRECCIÓN: " + visita.Direccion.ToUpper(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("TIPO: " + visita.Tipo.ToUpper(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("PRECIO: " + ((visita.Moneda == "SOL" ? "S/ " : "$ ") + visita.Precio.ToString("#,##0.00")).ToUpper(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("DATOS CLIENTE", fontBold) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("NOMBRE: " + visita.NombreCliente.ToUpper(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("FECHA VISITA: " + visita.Fecha.ToString("dd/MM/yyyy"), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph("HORA: " + visita.Hora.ToString(), font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); paragraph = new Paragraph(" ", font) { Alignment = Element.ALIGN_LEFT }; doc.Add(paragraph); //var arrFirma = visita.Firma.Split(','); byte[] bytesFirma = Convert.FromBase64String(visita.Firma); pic = Image.GetInstance(bytesFirma); pic.Alignment = Element.ALIGN_CENTER; if (pic.Height > 180 || pic.Width > 250) { pic.ScaleAbsolute((pic.Width * (float)0.8), pic.Height * (float)0.8); } // doc.Add(pic); paragraph = new Paragraph("FIRMA", font) { Alignment = Element.ALIGN_CENTER }; doc.Add(paragraph); pic = Image.GetInstance(HttpContext.Current.Server.MapPath(@"~\Content\img\membretada\footer.png")); pic.ScaleAbsolute(320, 42); pic.SetAbsolutePosition(140, 20); doc.Add(pic); doc.Close(); pdfBytes = output.ToArray(); } var stream = new MemoryStream(pdfBytes); return(stream); } catch (Exception ex) { return(null); } }
private void drawLine(int zeroValX, int zeroVlY, Font fontContent, List <double> valList, PdfWriter writer) { try { PdfContentByte cb = writer.DirectContent; cb.SetColorStroke(Color.BLACK); cb.SetColorFill(Color.BLACK); //画框 cb.SaveState(); cb.SetLineWidth(1f); cb.MoveTo(zeroValX, zeroVlY); cb.LineTo(zeroValX + 300, zeroVlY); cb.LineTo(zeroValX + 300, zeroVlY + 130); cb.LineTo(zeroValX, zeroVlY + 130); cb.ClosePathStroke(); cb.Stroke(); //文本 ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase("线性系数", fontContent), zeroValX + 320, zeroVlY + 120, 0); ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase("R方:" + r2.ToString("0.000"), fontContent), zeroValX + 320, zeroVlY + 100, 0); //ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, // new Phrase("方程:"+ strGS, fontContent), zeroValX + 320, zeroVlY + 80, 0); //零 ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase("0", fontContent), zeroValX - 5, zeroVlY - 12, 0); //画X轴短线 for (int i = 1; i <= 6; i++) { cb.MoveTo(zeroValX + i * 45, zeroVlY); cb.LineTo(zeroValX + i * 45, zeroVlY - 3); cb.Stroke(); ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, new Phrase(i.ToString(), fontContent), zeroValX + i * 45, zeroVlY - 12, 0); } for (int i = 1; i <= 5; i++) { cb.MoveTo(zeroValX - 3, zeroVlY + i * 21); cb.LineTo(zeroValX, zeroVlY + i * 21); cb.Stroke(); ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(i + "0000", fontContent), zeroValX - 10, zeroVlY + i * 21, 0); } double dataVal = valList.First(); float x = 0; float y = 0; x = Convert.ToSingle(zeroValX + 45); y = Convert.ToSingle(GetColuValue(zeroVlY, dataVal)); cb.MoveTo(x, y); dataVal = valList.Last(); x = Convert.ToSingle(zeroValX + valList.Count * 45); y = Convert.ToSingle(GetColuValue(zeroVlY, dataVal)); cb.LineTo(x, y); cb.Stroke(); cb.SetColorFill(Color.BLUE); //画点 for (int i = 1; i <= valList.Count; i++) { y = Convert.ToSingle(GetColuValue(zeroVlY, valList[i - 1])); cb.MoveTo(150 + i * 45 - kuang, y - kuang); cb.LineTo(150 + i * 45 + kuang, y - kuang); cb.LineTo(150 + i * 45 + kuang, y + kuang); cb.LineTo(150 + i * 45 - kuang, y + kuang); cb.Fill(); cb.Stroke(); } cb.RestoreState(); } catch (Exception ex) { Console.WriteLine("[ERROR] : " + ex.ToString()); } }
private void BtnPrint_Click(object sender, EventArgs e) { Document document = new Document(); this.produkterDir = produkterLocation(); this.fvfilename = this.produkterDir + "produkter.pdf"; // if (this.fvfilename.Contains("/")) { this.fvfilename = this.fvfilename.Replace("/", "-"); } PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(this.fvfilename, FileMode.Create)); // open the document document.Open(); PdfContentByte cb = writer.DirectContent; cb.SetColorStroke(new CMYKColor(100f, 100f, 100f, 100f)); cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f)); // x, y of bottom left corner, width, height //----------------------------------------------------------- cb.Rectangle(300f, 775f, 260f, 25f); // pierwsza tabelka cb.Stroke(); cb.Rectangle(300f, 745f, 135f, 25f); // druga tabelka cb.Stroke(); cb.Rectangle(440f, 745f, 120f, 25f); // druga tabelka cb.Stroke(); cb.Rectangle(300f, 650f, 260f, 90f); // czwarta tabelka cb.Stroke(); if (logoExist() == true) { iTextSharp.text.Image imgLogo = iTextSharp.text.Image.GetInstance(this.imageLogo); imgLogo.ScaleAbsolute(264, 187); imgLogo.SetAbsolutePosition(30, 613); imgLogo.Alignment = iTextSharp.text.Image.TEXTWRAP; document.Add(imgLogo); } iTextSharp.text.Font georgia = FontFactory.GetFont("georgia", 10f); int fontSix = Convert.ToInt32(this.fontsize); Paragraph p = new Paragraph(this.foretagnamn, FontFactory.GetFont(FontFactory.TIMES_BOLD, fontSix, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0))); Chapter chapter2 = new Chapter(p, 0); if (logoExist() == false) { document.Add(p); } cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f)); PlaceText(writer.DirectContent, "BENÄMNING", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, 650, 30, 30, 14, Element.ALIGN_LEFT); PlaceText(writer.DirectContent, "", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 346, 650, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "ENHETER", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 447, 650, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "À-PRIS", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, 650, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "Produkter", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.BOLD), 386, 793, -185, 30, 14, Element.ALIGN_RIGHT); cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f)); string path = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + @"\data\produkter.xml"; // listViewProdukter.Items.Clear(); XDocument xmldoc = XDocument.Load(path); var items = (from i in xmldoc.Descendants("produkt") // where (string)(i.Element("pnamn")) == "AL LAMELL 30 mm 9,6 m²" select new { pnamn = i.Element("pnamn").Value, pris = i.Element("pris").Value }).ToList(); // liczba stron if ((items.Count % 40) == 0) { this.pagesAll = items.Count / 40; } else if ((items.Count % 40) != 0) { this.pagesAll = (items.Count / 40) + 1; } double item_price = 0.8; string s_item_price; int currentPage = 1; string text_faktura_datum = @"Datum"; string text_faktura_address_l1 = this.adress1; string text_faktura_address_l2 = this.adress2; string text_faktura_address_l3 = this.adress3; PdfContentByte cbs = writer.DirectContent; cbs.BeginText(); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); cbs.SetTextMatrix(443, 762); cbs.ShowText(text_faktura_datum); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); cbs.SetTextMatrix(303, 732); cbs.ShowText("Företagadress"); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); cbs.SetTextMatrix(303, 762); cbs.ShowText("Sida"); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); cbs.SetTextMatrix(314, 749); cbs.ShowText(" " + currentPage.ToString() + " / " + this.pagesAll.ToString()); string strDateNow = System.DateTime.Now.ToString("yyyy-MM-dd"); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); cbs.SetTextMatrix(460, 749); cbs.ShowText(strDateNow); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); cbs.SetTextMatrix(314, 717); cbs.ShowText(text_faktura_address_l1); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); cbs.SetTextMatrix(314, 702); cbs.ShowText(text_faktura_address_l2); cbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); cbs.SetTextMatrix(314, 687); cbs.ShowText(text_faktura_address_l3); cbs.EndText(); int kLine = 650; int underLine = 633; for (int i = 0; i < items.Count; i++) { if (items[i].pris.ToString() != "") { if (IsNumber(items[i].pris.ToString()) == true) { item_price = Convert.ToDouble(items[i].pris.ToString()); s_item_price = item_price.ToString("0,0.00") + " kr"; } else { item_price = 0; s_item_price = items[i].pris.ToString(); } } else { item_price = 0; s_item_price = ""; } PlaceText(writer.DirectContent, items[i].pnamn.ToString(), FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, kLine, 30, 30, 14, Element.ALIGN_LEFT); PlaceText(writer.DirectContent, s_item_price, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, kLine, -185, 30, 14, Element.ALIGN_RIGHT); kLine = kLine - 15; cb.MoveTo(100, underLine); cb.LineTo(560, underLine); cb.ClosePathStroke(); underLine = underLine - 15; if (Is40(i) == true && i != 0) // // if (i == 40 || i == 80 || i == 120 || i == 160 || i == 200) { kLine = 685; underLine = 668; document.NewPage(); // currentPage = document.PageNumber; PdfContentByte Dcbs = writer.DirectContent; Dcbs.BeginText(); Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); Dcbs.SetTextMatrix(443, 762); Dcbs.ShowText(text_faktura_datum); Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); Dcbs.SetTextMatrix(460, 749); Dcbs.ShowText(strDateNow); Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 8); Dcbs.SetTextMatrix(303, 762); Dcbs.ShowText("Sida"); Dcbs.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 12); Dcbs.SetTextMatrix(314, 749); currentPage = currentPage + 1; Dcbs.ShowText(" " + currentPage.ToString() + " / " + this.pagesAll.ToString()); Dcbs.EndText(); // x, y of bottom left corner, width, height //----------------------------------------------------------- cb.Rectangle(300f, 775f, 260f, 25f); // first table cb.Stroke(); cb.Rectangle(300f, 745f, 135f, 25f); // second table cb.Stroke(); cb.Rectangle(440f, 745f, 120f, 25f); // third table cb.Stroke(); if (logoExist() == true) { iTextSharp.text.Image imgLogo = iTextSharp.text.Image.GetInstance(this.imageLogo); imgLogo.ScaleAbsolute(264, 187); imgLogo.SetAbsolutePosition(30, 613); imgLogo.Alignment = iTextSharp.text.Image.TEXTWRAP; document.Add(imgLogo); } if (logoExist() == false) { document.Add(p); } cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f)); PlaceText(writer.DirectContent, "BENÄMNING", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 600, kLine + 15, 30, 30, 14, Element.ALIGN_LEFT); PlaceText(writer.DirectContent, "", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 346, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "ENHETER", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 447, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "À-PRIS", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL), 556, kLine + 15, -185, 30, 14, Element.ALIGN_RIGHT); PlaceText(writer.DirectContent, "Produkter", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.BOLD), 386, 793, -185, 30, 14, Element.ALIGN_RIGHT); cb.SetColorFill(new CMYKColor(100f, 100f, 100f, 100f)); cb.MoveTo(100, 683); cb.LineTo(560, 683); cb.ClosePathStroke(); } } cb.ClosePathFillStroke(); document.Close(); System.Threading.Thread.Sleep(1000); try { System.Diagnostics.Process.Start(this.fvfilename); } catch { } }
private static void DrawLine(PdfContentByte pdfContentByte, float fromX, float fromY, float toX, float toY) { pdfContentByte.MoveTo(fromX, fromY); pdfContentByte.LineTo(toX, toY); pdfContentByte.ClosePathStroke(); }