public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); string ARIALUNI_TFF = HttpContext.Current.Server.MapPath("~/fonts/ARIALUNI.TTF"); BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); template.BeginText(); template.SetFontAndSize(bf, 9); template.SetTextMatrix(0, 0); template.ShowText("" + (writer.PageNumber)); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); base.OnCloseDocument(writer, document); pdfTemplate.BeginText(); pdfTemplate.SetFontAndSize(baseFont, 10f); pdfTemplate.SetTextMatrix(0, 0); pdfTemplate.ShowText((writer.PageNumber - 1).ToString()); pdfTemplate.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); template.BeginText(); template.SetFontAndSize(BaseFont.CreateFont(), 10.5f); string text = "" + (writer.PageNumber); template.SetTextMatrix(47.5f + getXofTextMatrix(writer.PageNumber), 0); Console.WriteLine("###-->> onCloseDocText = " + text); template.ShowText(text); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); /******/ template.BeginText(); template.SetTextMatrix(25, 0); template.SetFontAndSize(bf, 8); template.ShowText("" + (writer.PageNumber - 1)); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); #region NumeroPaginas BaseFont bfTimes = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 8f, iTextSharp.text.Font.NORMAL); template.BeginText(); template.SetFontAndSize(bfTimes, times.Size); template.SetTextMatrix(0, 0); template.ShowText("" + (writer.PageNumber)); template.EndText(); #endregion }
private void WriteTotalNumberOfPages(PdfWriter writer, Document document) { var width = _settings.ReportFooterFont.BaseFont.GetWidthPoint(" ", _settings.ReportFooterFont.Size); var height = _settings.ReportSubTitleFont.Size; var pdfContentByteUnder = writer.DirectContentUnder; _numPagesTemplate.BeginText(); _numPagesTemplate.SetFontAndSize(_settings.ReportFooterFont.BaseFont, _settings.ReportFooterFont.Size); _numPagesTemplate.SetRGBColorFill(_settings.ReportFooterFont.Color.R, _settings.ReportFooterFont.Color.G, _settings.ReportFooterFont.Color.B); _numPagesTemplate.SetTextMatrix(0, 0); _numPagesTemplate.ShowText((writer.PageNumber - 1).ToString()); _numPagesTemplate.EndText(); }
private void setFinalPageNumber(PdfWriter writer) { var font = FooterProperties.PdfFont.Fonts[0]; var text = "" + (writer.PageNumber - 1); var textLen = font.BaseFont.GetWidthPoint(text, font.Size); var x = FooterProperties.RunDirection == PdfRunDirection.LeftToRight ? 0 : FooterProperties.TotalPagesCountTemplateWidth - textLen; _totalPageCountTemplate.BeginText(); _totalPageCountTemplate.SetFontAndSize(font.BaseFont, font.Size); _totalPageCountTemplate.SetTextMatrix(x, 0); _totalPageCountTemplate.ShowText(text); _totalPageCountTemplate.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); if (_template != null) { _template.BeginText(); _template.SetFontAndSize(_bf, fontSize); _template.SetTextMatrix(0, 0); // if removing table of contents _template.ShowText((writer.PageNumber - 1 - (_hasCoverPage ? 1 : 0)).ToString()); _template.EndText(); } }
private void InsertCharacteristics(PdfStamper Stamper, int totalpages, string totalstr, int X, int Y, int Z, int W, int D_x, int D_y, int R_x, int R_y) { iTextSharp.text.pdf.PdfContentByte underContent; for (int i = 1; i <= totalpages; i++) { underContent = Stamper.GetOverContent(i); PdfTemplate template = underContent.CreateTemplate(500, 300); template.BeginText(); BaseFont bf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); template.SetFontAndSize(bf, 9); template.SetTextMatrix(100, 100); template.ShowText(totalstr); template.EndText(); underContent.AddTemplate(template, X, Y); string NoStr = "第" + i + "页"; PdfTemplate newtemplate = underContent.CreateTemplate(500, 300); newtemplate.BeginText(); BaseFont newbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); newtemplate.SetFontAndSize(newbf, 9); newtemplate.SetTextMatrix(100, 100); newtemplate.ShowText(NoStr); newtemplate.EndText(); underContent.AddTemplate(newtemplate, Z, W); //if (i == 2 || i == totalpages) if (pid == "COSL H256" && i == 2 && indicator == 0) { string DrawingStr = "图号:" + drawing; PdfTemplate drawingtemplate = underContent.CreateTemplate(500, 300); drawingtemplate.BeginText(); BaseFont drawingbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); drawingtemplate.SetFontAndSize(drawingbf, 12); drawingtemplate.SetTextMatrix(100, 100); drawingtemplate.ShowText(DrawingStr); drawingtemplate.EndText(); underContent.AddTemplate(drawingtemplate, D_x, D_y); string RevStr = "REV." + version.ToString(); PdfTemplate revtemplate = underContent.CreateTemplate(500, 300); revtemplate.BeginText(); BaseFont revbf = BaseFont.CreateFont(Application.StartupPath + "\\Resources\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); revtemplate.SetFontAndSize(revbf, 9); revtemplate.SetTextMatrix(100, 100); revtemplate.ShowText(RevStr); revtemplate.EndText(); underContent.AddTemplate(revtemplate, R_x, R_y); } } }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); template.BeginText(); BaseFont bf_qty = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); Font font_qty = new Font(bf_qty, 10, Font.NORMAL); template.SetFontAndSize(bf_qty, 10f); template.SetTextMatrix(10, 0); int pageNumber = writer.PageNumber - 1; template.ShowText(Convert.ToString(pageNumber)); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); var font = new Font(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)) { Size = 12, Color = BaseColor.Black }; //Document is closed and the template in "Page # of {template}" is filled in with the total number of pages in the document. Comment at the end of OnPageEnd() for more information. template.BeginText(); template.SetFontAndSize(font.BaseFont, font.Size); template.SetTextMatrix(0, 0); template.ShowText("" + (writer.PageNumber - 1)); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); headerTemplate.BeginText(); headerTemplate.SetFontAndSize(bf, 12); headerTemplate.SetTextMatrix(0, 0); headerTemplate.ShowText((writer.PageNumber - 1).ToString()); headerTemplate.EndText(); footerTemplate.BeginText(); footerTemplate.SetFontAndSize(bf, 12); footerTemplate.SetTextMatrix(0, 0); footerTemplate.ShowText((writer.PageNumber - 1).ToString()); footerTemplate.EndText(); }
private void InsertCharacteristics(PdfStamper Stamper, string str, int X, int Y) { iTextSharp.text.pdf.PdfContentByte underContent; underContent = Stamper.GetOverContent(1); PdfTemplate template = underContent.CreateTemplate(500, 300); template.BeginText(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); template.SetFontAndSize(bf, 9); template.SetTextMatrix(100, 100); template.ShowText(str); template.EndText(); underContent.AddTemplate(template, X, Y); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); m_headerTemplate.BeginText(); m_headerTemplate.SetFontAndSize(m_cfg.HeaderPagingFont, m_cfg.PagingFontSize); m_headerTemplate.SetTextMatrix(0, 0); m_headerTemplate.ShowText((writer.PageNumber - 1).ToString(CultureInfo.InvariantCulture)); m_headerTemplate.EndText(); m_footerTemplate.BeginText(); m_footerTemplate.SetFontAndSize(m_cfg.HeaderPagingFont, m_cfg.PagingFontSize); m_footerTemplate.SetTextMatrix(0, 0); m_footerTemplate.ShowText((writer.PageNumber - 1).ToString(CultureInfo.InvariantCulture)); m_footerTemplate.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { if (NoFooter.HasValue) { if (NoFooter.Value) { return; } } base.OnCloseDocument(writer, document); template.BeginText(); template.SetFontAndSize(bf, 8); template.SetTextMatrix(0, 0); template.ShowText("" + (writer.PageNumber)); template.EndText(); }
public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer, document); float len = bf.GetWidthPoint("Página:1/1", 8); headerTemplate.BeginText(); headerTemplate.SetFontAndSize(bf, 8); headerTemplate.SetTextMatrix(0, 0); headerTemplate.ShowText((writer.PageNumber - 1).ToString()); headerTemplate.EndText(); footerTemplate.BeginText(); footerTemplate.SetFontAndSize(bf, 8); footerTemplate.SetTextMatrix(0, 0); footerTemplate.ShowText((writer.PageNumber - 1).ToString()); footerTemplate.EndText(); }
public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF, StringFormat2 format) { template.BeginText(); SetFont(font); SetBrush(brush); float x = rectangleF.X; float y = Math.Max(0, rectangleF.Y - rectangleF.Height / 2); Size2 size = MeasureString(s, font); if (format != null) { switch (format.Alignment) { case StringAlignment2.Center: x = x + (rectangleF.Width - size.Width) / 2f; break; case StringAlignment2.Near: x = x + 2; break; case StringAlignment2.Far: x = x + (rectangleF.Width - size.Width) - 2; break; } switch (format.LineAlignment) { case StringAlignment2.Center: y = y + font.Height / 2f; break; case StringAlignment2.Near: y = y + 2; break; case StringAlignment2.Far: y = y + font.Height; break; } } template.SetTextMatrix(x, currentHeight - y - font.Height * 0.5f * 1.5f); template.ShowText(s.TrimStart().TrimEnd()); template.EndText(); }
private void setFinalPageNumber(PdfWriter writer) { if (FooterProperties.PdfFont == null) { throw new NullReferenceException("PdfFont is null."); } var font = FooterProperties.PdfFont.Fonts[0]; var text = "" + (writer.CurrentPageNumber - 1); var textLen = font.BaseFont.GetWidthPoint(text, font.Size); var x = FooterProperties.RunDirection == PdfRunDirection.LeftToRight ? 0 : FooterProperties.TotalPagesCountTemplateWidth - textLen; _totalPageCountTemplate.BeginText(); _totalPageCountTemplate.SetFontAndSize(font.BaseFont, font.Size); _totalPageCountTemplate.SetTextMatrix(x, 0); _totalPageCountTemplate.ShowText(text); _totalPageCountTemplate.EndText(); }
void DrawGroup(PdfContentByte cb) { //TODO if width and height not know: what to do //PdfTemplate template = cb.CreateTemplate(this.width, this.height); PdfTemplate template = cb.CreateTemplate(500, 500); //draw the list of elements on the new template IList <int> xSpacing = null, ySpacing = null; float defaultSpacing = template.CharacterSpacing; float rise = 0; template.BeginText(); // foreach (IElement elem in this.list) { Text text = (Text)elem; //CssSvgAppliers.GetInstance().ApplyForText(, text.GetCss(), text.GetChunk()); CssSvgAppliers.GetInstance().ApplyForText(template, text.GetCss(), text.GetChunk()); if (!text.IsRelative()) { //when there are x,y coordinates in the text or tspan template.SetTextMatrix(text.GetX(), -1 * text.GetY()); } //System.out.Println(text.chunk.GetFont()); //the spacing if (text.Dx != null) { xSpacing = text.Dx; } if (text.Dy != null) { ySpacing = text.Dy; rise = 0; } if (xSpacing != null || ySpacing != null) { String display = text.GetText(); for (int i = 0; i < display.Length; i++) { if (xSpacing != null && xSpacing.Count > 0) { template.SetCharacterSpacing(xSpacing[0]); xSpacing.Remove(0); } if (ySpacing != null && ySpacing.Count > 0) { rise = rise - ySpacing[0]; template.SetTextRise(rise); ySpacing.Remove(0); } else { template.SetTextRise(rise); } template.ShowText(display.Substring(i, 1)); template.SetCharacterSpacing(defaultSpacing); } } else { template.ShowText(text.GetText()); } } template.EndText(); //add the template at the x, y position cb.ConcatCTM(1, 0, 0, -1, 0, 0); cb.Add(template); }
private void HalfA4Draw(Document document, PdfWriter writer, PdfReader reader, PdfContentByte cb, string pkgcate, int i, int j) { PdfImportedPage newPage; document.NewPage(); newPage = writer.GetImportedPage(reader, 1); cb.AddTemplate(newPage, 0, 0); if ((bool)drumno.IsChecked) { cb.BeginText(); BaseFont bf = BaseFont.CreateFont(@"c:\windows\fonts\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); cb.SetFontAndSize(bf, 14); List <MarkLocation> axis = DrumAxisList("HalfA4"); cb.SetTextMatrix(axis[0].AsixX, axis[0].AsixY); cb.ShowText(pkgcate + "号:" + j); cb.SetTextMatrix(axis[1].AsixX, axis[1].AsixY); cb.ShowText(pkgcate + "号:" + (Convert.ToInt32(j) + Convert.ToInt32(0))); cb.EndText(); } int originX = 241; int[] originY = { 239, 649 }; if ((bool)Mark3C.IsChecked) { ///3C标签 iTextSharp.text.Image splitline = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\CCC.jpg"); splitline.ScaleAbsolute(50, 50); splitline.SetAbsolutePosition(originX - splitline.PlainWidth, originY[0] - splitline.PlainHeight); cb.AddImage(splitline); splitline.SetAbsolutePosition(originX - splitline.PlainWidth, originY[1] - splitline.PlainHeight); cb.AddImage(splitline); //originX = originX + (int)splitline.PlainHeight; } if ((bool)MarkRohs.IsChecked) { iTextSharp.text.Image rohsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\rohs.jpg"); rohsl.ScaleAbsolute(80, 80); rohsl.SetAbsolutePosition(originX - rohsl.ScaledWidth, originY[0] - rohsl.ScaledHeight); cb.AddImage(rohsl); rohsl.SetAbsolutePosition(originX - rohsl.ScaledWidth, originY[1] - rohsl.ScaledHeight); cb.AddImage(rohsl); //originX = originX + (int)rohsl.PlainHeight; } if ((bool)MarkQs.IsChecked) { iTextSharp.text.Image qsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\qs.jpg"); qsl.ScaleAbsolute(45, 60); qsl.SetAbsolutePosition(originX - qsl.ScaledWidth, originY[0] - qsl.ScaledHeight); cb.AddImage(qsl); qsl.SetAbsolutePosition(originX - qsl.ScaledWidth, originY[1] - qsl.ScaledHeight); cb.AddImage(qsl); //originX = originX + (int)qsl.PlainHeight; } if ((bool)HideLogo.IsChecked) { iTextSharp.text.Image bi = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\blank.png"); bi.ScaleAbsolute(63, 54); bi.SetAbsolutePosition(492, 351); cb.AddImage(bi); bi.SetAbsolutePosition(492, 762); cb.AddImage(bi); } if ((bool)CustomMark.IsChecked) { int tmx = 8, tmy = 20, w = 170, h = 80; if (CustomMarkText.Text.Length < 2) { w = w / 2; } PdfTemplate cut = cb.CreateTemplate(w, h); cut.BeginText(); cut.SetFontAndSize(bf, 55); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, CustomMarkText.Text, w / 2, 10, 0); cut.EndText(); cb.AddTemplate(cut, 1, 0, 0, 1, 180, 60); cb.AddTemplate(cut, 1, 0, 0, 1, 180, 471); } }
private void A4Draw(Document document, PdfWriter writer, PdfReader reader, PdfContentByte cb, string pkgcate, int i, int j) { PdfImportedPage newPage; document.NewPage(); //PdfStamper stamp = new PdfStamper(reader, new FileStream("Finish.pdf", FileMode.Create)); newPage = writer.GetImportedPage(reader, 1); if (newPage.Height > newPage.Width) { cb.AddTemplate(newPage, 0, 0); } else { cb.AddTemplate(newPage, 0, 1, -1, 0, newPage.Height, 0); } cb.BeginText(); MarkLocation axis = DrumAxis("A4", 0); cb.SetFontAndSize(bf, 14); cb.SetTextMatrix(0, 1, -1, 0, axis.AsixX, axis.AsixY); //cb.ShowText("桶号:" + j + " " + "to " + Convert.ToInt32(textBox2.Text)); cb.ShowText(pkgcate + "号:" + j); cb.EndText(); int originX = int.Parse(AsixX.Text), originY = int.Parse(AsixY.Text); int MaxX = int.Parse(this.Resources["A4MaxX"].ToString()); int MinY = int.Parse(this.Resources["A4MinY"].ToString()); List <int> ActualX = new List <int>(); List <int> ActualY = new List <int>(); if ((bool)CustomMark.IsChecked) { //自定义文本标签外间距,内间距,尺寸 int x = 0, y = 0, tmx = 8, tmy = 20, w = 170, h = 80; if (CustomMarkText.Text.Length < 2) { w = w / 2; } PdfTemplate cut = cb.CreateTemplate(w, h); //cut.MoveTo(x, y); //cut.LineTo(w - x, 0 + y); //cut.LineTo(w - x, h - y); //cut.LineTo(x, h - y); //cut.LineTo(x, y); //cut.Stroke(); cut.BeginText(); cut.SetFontAndSize(bf, 90); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, CustomMarkText.Text, w / 2, 10, 0); //cut.ShowText(culabeltext.Text); cut.EndText(); float zoom = float.Parse(Zoom.Text) / 100; cb.AddTemplate(cut, 0, 1 * zoom, -1 * zoom, 0, originX + h * 1 * zoom, originY - cut.Width * 1 * zoom); ActualX.Add((int)(cut.Height * zoom) + 1); ActualY.Add((int)(cut.Width * zoom) + 2); originX += (int)(cut.Height * zoom) + 1; } if ((bool)StandardMark.IsChecked) { int tmx = 4, tmy = 10, w = 170, h = 30; PdfTemplate cut = cb.CreateTemplate(w, h); cut.BeginText(); cut.SetFontAndSize(bf, 15); cut.SetTextMatrix(tmx, tmy); cut.ShowTextAligned(1, "企业标准:" + StandardCB.Text, w / 2, 10, 0); cut.EndText(); cb.AddTemplate(cut, 0, 1, -1, 0, 500, 40); } if ((bool)Mark3C.IsChecked) { ///3C标签 iTextSharp.text.Image splitline = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\CCC.jpg"); splitline.RotationDegrees = 90; splitline.ScaleAbsolute(50, 50); if (originX + splitline.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)splitline.PlainHeight + 1); ActualY.Add((int)splitline.PlainWidth + 1); splitline.SetAbsolutePosition(originX, originY - splitline.PlainWidth); cb.AddImage(splitline); //document.Add(splitline); originX = originX + (int)splitline.PlainHeight; } if ((bool)MarkRohs.IsChecked) { iTextSharp.text.Image rohsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\rohs.jpg"); rohsl.RotationDegrees = 90; rohsl.ScaleAbsolute(100, 100); if (originX + rohsl.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)rohsl.PlainHeight + 1); ActualX.Add((int)rohsl.PlainWidth + 1); rohsl.SetAbsolutePosition(originX, originY - rohsl.PlainWidth); cb.AddImage(rohsl); //document.Add(rohsl); originX = originX + (int)rohsl.PlainHeight; } if ((bool)MarkQs.IsChecked) { iTextSharp.text.Image qsl = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\qs.jpg"); qsl.RotationDegrees = 90; qsl.ScaleAbsolute(45, 60); if (originX + qsl.PlainWidth > MaxX) { originX = int.Parse(AsixX.Text); originY -= ActualY.Max(); } ActualX.Add((int)qsl.PlainHeight + 1); ActualY.Add((int)qsl.PlainWidth + 1); qsl.SetAbsolutePosition(originX, originY - qsl.PlainWidth); cb.AddImage(qsl); //document.Add(qsl); originX = originX + (int)qsl.PlainHeight; } if ((bool)HideLogo.IsChecked) { iTextSharp.text.Image bi = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\blank.png"); bi.ScaleAbsolute(57, 76); bi.SetAbsolutePosition(26, 656); cb.AddImage(bi); } }
public Chap1011() { Console.WriteLine("Chapter 10 example 11: a PdfPTable in a template"); // step 1: creation of a document-object Rectangle rect = new Rectangle(PageSize.A4); rect.BackgroundColor = new Color(238, 221, 88); Document document = new Document(rect, 50, 50, 50, 50); try { // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1011.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: PdfTemplate template = writer.DirectContent.CreateTemplate(20, 20); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String text = "Vertical"; float size = 16; float width = bf.GetWidthPoint(text, size); template.BeginText(); template.SetRGBColorFillF(1, 1, 1); template.SetFontAndSize(bf, size); template.SetTextMatrix(0, 2); template.ShowText(text); template.EndText(); template.Width = width; template.Height = size + 2; Image img = Image.GetInstance(template); img.RotationDegrees = 90; Chunk ck = new Chunk(img, 0, 0); PdfPTable table = new PdfPTable(3); table.WidthPercentage = 100; table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; PdfPCell cell = new PdfPCell(img); cell.Padding = 4; cell.BackgroundColor = new Color(0, 0, 255); cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell("I see a template on my right"); table.AddCell(cell); table.AddCell("I see a template on my left"); table.AddCell(cell); table.AddCell("I see a template everywhere"); table.AddCell(cell); table.AddCell("I see a template on my right"); table.AddCell(cell); table.AddCell("I see a template on my left"); Paragraph p1 = new Paragraph("This is a template "); p1.Add(ck); p1.Add(" just here."); p1.Leading = img.ScaledHeight * 1.1f; document.Add(p1); document.Add(table); Paragraph p2 = new Paragraph("More templates "); p2.Leading = img.ScaledHeight * 1.1f; p2.Alignment = Element.ALIGN_JUSTIFIED; img.ScalePercent(70); for (int k = 0; k < 20; ++k) { p2.Add(ck); } document.Add(p2); // step 5: we close the document document.Close(); } catch (Exception de) { Console.Error.WriteLine(de.Message); Console.Error.WriteLine(de.StackTrace); } }
public Chap1013() { Console.WriteLine("Chapter 10 Example 13: Spot Color"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1013.pdf", FileMode.Create)); BaseFont bf = BaseFont.CreateFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED); // step 3: we open the document document.Open(); // step 4: we add some content PdfContentByte cb = writer.DirectContent; // Note: I made up these names unless someone give me a PANTONE swatch as gift ([email protected]) PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f)); PdfSpotColor spc_rgb = new PdfSpotColor("PANTONE 147", 0.9f, new Color(114, 94, 38)); PdfSpotColor spc_g = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f)); // Stroke a rectangle with CMYK alternate cb.SetColorStroke(spc_cmyk, .5f); cb.SetLineWidth(10f); // draw a rectangle cb.Rectangle(100, 700, 100, 100); // add the diagonal cb.MoveTo(100, 700); cb.LineTo(200, 800); // stroke the lines cb.Stroke(); // Fill a rectangle with CMYK alternate cb.SetColorFill(spc_cmyk, spc_cmyk.Tint); cb.Rectangle(250, 700, 100, 100); cb.Fill(); // Stroke a circle with RGB alternate cb.SetColorStroke(spc_rgb, spc_rgb.Tint); cb.SetLineWidth(5f); cb.Circle(150f, 500f, 100f); cb.Stroke(); // Fill the circle with RGB alternate cb.SetColorFill(spc_rgb, spc_rgb.Tint); cb.Circle(150f, 500f, 50f); cb.Fill(); // example with colorfill cb.SetColorFill(spc_g, spc_g.Tint); cb.MoveTo(100f, 200f); cb.LineTo(200f, 250f); cb.LineTo(400f, 150f); cb.Fill(); document.NewPage(); String text = "Some text to show"; document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk)))); document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f)))); // example with template PdfTemplate t = cb.CreateTemplate(500f, 500f); // Stroke a rectangle with CMYK alternate t.SetColorStroke(new SpotColor(spc_cmyk, .5f)); t.SetLineWidth(10f); // draw a rectangle t.Rectangle(100, 10, 100, 100); // add the diagonal t.MoveTo(100, 10); t.LineTo(200, 100); // stroke the lines t.Stroke(); // Fill a rectangle with CMYK alternate t.SetColorFill(spc_g, spc_g.Tint); t.Rectangle(100, 125, 100, 100); t.Fill(); t.BeginText(); t.SetFontAndSize(bf, 20f); t.SetTextMatrix(1f, 0f, 0f, 1f, 10f, 10f); t.ShowText("Template text upside down"); t.EndText(); t.Rectangle(0, 0, 499, 499); t.Stroke(); cb.AddTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f); } catch (Exception de) { Console.Error.WriteLine(de.Message); Console.Error.WriteLine(de.StackTrace); } // step 5: we close the document document.Close(); }
public Chap1003() { Console.WriteLine("Chapter 10 example 3: Templates"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1003.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.DirectContent; // we create a PdfTemplate PdfTemplate template = cb.CreateTemplate(500, 200); // we add some graphics template.MoveTo(0, 200); template.LineTo(500, 0); template.Stroke(); template.SetRGBColorStrokeF(255f, 0f, 0f); template.Circle(250f, 100f, 80f); template.Stroke(); // we add some text template.BeginText(); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); template.SetFontAndSize(bf, 12); template.SetTextMatrix(100, 100); template.ShowText("Text at the position 100,100 (relative to the template!)"); template.EndText(); // we add the template on different positions cb.AddTemplate(template, 0, 0); cb.AddTemplate(template, 0, 1, -1, 0, 500, 200); cb.AddTemplate(template, .5f, 0, 0, .5f, 100, 400); // we go to a new page document.NewPage(); cb.AddTemplate(template, 0, 400); cb.AddTemplate(template, 2, 0, 0, 2, -200, 400); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); }