private static void AddWaterMarkText(PdfContentByte pdfData, string watermarkText, BaseFont font, float fontSize, float angle, BaseColor color, iTextSharp.text.Rectangle realPageSize, float opFill, float opStroke, float xP, float yP, int align) { //var gstate = new PdfGState { FillOpacity = 0.35f, StrokeOpacity = 0.3f }; var gstate = new PdfGState { FillOpacity = opFill, StrokeOpacity = opStroke }; pdfData.SaveState(); pdfData.SetGState(gstate); pdfData.SetColorFill(color); pdfData.BeginText(); pdfData.SetFontAndSize(font, fontSize); //var x = (realPageSize.Right + realPageSize.Left) / 2; //var y = (realPageSize.Bottom + realPageSize.Top) / 2; var x = realPageSize.Right * (xP); var y = realPageSize.Top * (1 - yP); //pdfData.ShowTextAligned(Element.ALIGN_LEFT, watermarkText, x, y, angle); pdfData.ShowTextAligned(align, watermarkText, x, y, angle); pdfData.EndText(); pdfData.RestoreState(); }
public void printClubsOKHeader() { try { BaseFont f_cb = BaseFont.CreateFont("c:\\windows\\fonts\\calibrib.ttf", BaseFont.CP1250, BaseFont.NOT_EMBEDDED); BaseFont f_cn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1250, BaseFont.NOT_EMBEDDED); left_margin = 25; cb = writer.DirectContent; // First we must activate writing cb.BeginText(); // First we write out the header information // Start with the invoice type header writeText(cb, "Kluby platby OK", left_margin, top_margin, f_cb, 50); moveTop(60); cb.EndText(); } catch (Exception rror) { System.Windows.Forms.MessageBox.Show(rror.Message); } }
public void crearPieDePagina(Document doc, PdfWriter writer) { BaseFont bf = basePie; PdfContentByte cb = writer.DirectContent; cb.MoveTo(40, 120); cb.LineTo(doc.PageSize.Width - 40, 120); cb.Stroke(); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(doc.Left, 80); cb.ShowText("Teléfono: (506) 2511-8000"); cb.SetTextMatrix(doc.Left, 68); cb.ShowText("http://www.ecci.ucr.ac.cr"); cb.SetTextMatrix(doc.Right - 95, 80); cb.ShowText("Fax: (506) 2511-5527"); cb.EndText(); Image imagen = colocarImagenAcreditacion(doc); imagen.Alignment = Image.TEXTWRAP | Image.ALIGN_CENTER; doc.Add(imagen); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); if (npages.juststartednewset) { EndPageSet(); } string text; float len; text = $"id: {PeopleId} Page {pg} of "; PeopleId = NextPeopleId; len = font.GetWidthPoint(text, 8); dc.BeginText(); dc.SetFontAndSize(font, 8); dc.SetTextMatrix(30, 30); dc.ShowText(text); dc.EndText(); dc.AddTemplate(npages.template, 30 + len, 30); npages.n = pg++; }
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document) { int pageN = writer.PageNumber; string text = string.Empty; //string[] reportName = writer.Info.Get(PdfName.TITLE).ToString().Split(':'); text = string.Format("{0} Page {1} of ", StringUtilities.fillString(" ", 80), pageN); //PdfContentByte dc = writer.DirectContent; float len = footerBaseFont.GetWidthPoint(text, 8); contentByte.BeginText(); //if last page, figure out if it is last page contentByte.SetFontAndSize(footerBaseFont, 8); //Madhu fix for defexct PWNU00001411 contentByte.SetTextMatrix(len / 2, 30); contentByte.ShowText(text); contentByte.EndText(); //Madhu fix for defexct PWNU00001411 contentByteFooter.AddTemplate(templateFooter, 25, document.PageSize.Height - 500); contentByte.AddTemplate(template, len + len / 2, 30); }
private bool CreateSmallerTexBox(string textBoxName, float left, float top, double width, string content, PdfContentByte contentByte) { bool success = false; try { var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); contentByte.BeginText(); contentByte.SetFontAndSize(baseFont, 6); contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, content, left, top, 0); contentByte.EndText(); success = true; } catch (Exception) { throw; } return(success); }
private async Task GenerateWaterMark(string filePath, string filePathWaterMark) { try { using (FileStream stream = new FileStream(filePathWaterMark, FileMode.OpenOrCreate)) { PdfReader pdfReader = new PdfReader(filePath); PdfStamper pdfStamper = new PdfStamper(pdfReader, stream); for (int pageIndex = 1; pageIndex <= pdfReader.NumberOfPages; pageIndex++) { //Rectangle class in iText represent geomatric representation... in this case, rectanle object would contain page geomatry Rectangle pageRectangle = pdfReader.GetPageSizeWithRotation(pageIndex); //pdfcontentbyte object contains graphics and text content of page returned by pdfstamper PdfContentByte pdfData = pdfStamper.GetUnderContent(pageIndex); //create fontsize for watermark pdfData.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 45); //create new graphics state and assign opacity PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = 0.4F; //set graphics state to pdfcontentbyte pdfData.SetGState(graphicsState); //set color of watermark pdfData.SetColorFill(BaseColor.Gray); //indicates start of writing of text pdfData.BeginText(); //show text as per position and rotation pdfData.ShowTextAligned(Element.ALIGN_CENTER, "Not Official Copy", pageRectangle.Width / 2, pageRectangle.Height / 2, 45); //call endText to invalid font set pdfData.EndText(); } //close stamper and output filestream //stream.Dispose(); pdfStamper.Close(); pdfReader.Close(); } } catch (Exception ex) { _logger.Log(ex); } }
private bool CreateLabel(string label, float left, float top, string content, PdfContentByte contentByte) { bool success = false; try { var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //var baseFont = BaseFont.CreateFont("Arial", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); contentByte.BeginText(); contentByte.SetFontAndSize(baseFont, 8); contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, string.IsNullOrWhiteSpace(content) ? string.Empty : content, left, top, 0); contentByte.EndText(); success = true; } catch (Exception) { throw; } return(success); }
/// <summary> /// Draw the header of the grid. /// </summary> /// <param name="cb">content byte to manipulate the a part of a pdf document</param> /// <param name="location">location (rectangle in mm) of the grid</param> /// <param name="mm_Per_s">mm per second</param> /// <param name="mm_Per_mV">mm per milliVolt</param> /// <param name="bottomCuttoff">bottom cutoff of used filter</param> /// <param name="topCutoff">top butoff of used filter</param> public static void DrawGridHeader(PdfContentByte cb, RectangleF location, float mm_Per_s, float mm_Per_mV, double bottomCutoff, double topCutoff) { try { cb.BeginText(); System.Text.StringBuilder sbText = new System.Text.StringBuilder(); if (!double.IsNaN(bottomCutoff)) { if (!double.IsNaN(topCutoff)) { sbText.AppendFormat("{0}-{1} Hz, ", bottomCutoff, topCutoff); } else { sbText.AppendFormat("{0}-inf Hz, ", bottomCutoff); } } else if (!double.IsNaN(topCutoff)) { sbText.AppendFormat("0-{0} Hz, ", topCutoff); } sbText.AppendFormat("{0:0} mm/s, {1:0} mm/mV ", mm_Per_s, mm_Per_mV); string sText = sbText.ToString(); cb.ShowTextAligned( PdfContentByte.ALIGN_RIGHT, sText, (location.Right * PdfDocumentDpi) / mm_Per_Inch, (-(location.Bottom + 2.0f) * PdfDocumentDpi) / mm_Per_Inch, 0); cb.EndText(); } catch { } }
public static void OnStartPage(PdfWriter writer, Document document, string watermarkText) { float fontSize = 80; float xPosition = 300; float yPosition = 400; float angle = 45; try { PdfContentByte under = writer.DirectContentUnder; BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); under.BeginText(); under.SetColorFill(BaseColor.LIGHT_GRAY); under.SetFontAndSize(baseFont, fontSize); under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, xPosition, yPosition, angle); under.EndText(); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } }
/// <summary> /// 向pdf页输出文字 /// </summary> /// <param name="textColor">字体颜色</param> /// <param name="fontPath">字体</param> /// <param name="fontSize">字体大小 pt</param> /// <param name="textLeading">行距</param> /// <param name="textSpacing">字间距</param> /// <param name="textContent">文字内容</param> /// <param name="textX">输出位置的X坐标</param> /// <param name="textY">输出位置的Y坐标</param> public void PaintText(string textColor, string fontPath, float fontSize, float textLeading, float textSpacing, string textContent, float textX, float textY, float maxWidth) { CMYK_Color cmyk_titleColor = new CMYK_Color().GetCMYK_Color(textColor); FontFactory.Register(fontPath); BaseFont bfChinese = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); PdfContentByte contentByte = pdfWriter.DirectContent; contentByte.BeginText(); contentByte.SetCMYKColorFill(cmyk_titleColor.C, cmyk_titleColor.M, cmyk_titleColor.Y, cmyk_titleColor.K); contentByte.SetCMYKColorStroke(cmyk_titleColor.C, cmyk_titleColor.M, cmyk_titleColor.Y, cmyk_titleColor.K); contentByte.SetFontAndSize(bfChinese, fontSize); contentByte.SetLeading(textLeading); contentByte.SetCharacterSpacing(textSpacing); contentByte.SetTextMatrix(textX, textY); float floLineContentSize = bfChinese.GetWidthPointKerned(textContent, fontSize); if (floLineContentSize > maxWidth) { string strOutputContent = textContent.Substring(0, textContent.Length - 1); floLineContentSize = bfChinese.GetWidthPointKerned(strOutputContent, fontSize); while (floLineContentSize > maxWidth) { strOutputContent = textContent.Substring(0, strOutputContent.Length - 1); floLineContentSize = bfChinese.GetWidthPointKerned(strOutputContent, fontSize); } contentByte.ShowText(strOutputContent); //contentByte.ShowTextAligned((int)ContentAlignment.TopCenter, strOutputContent, textX, textY, 0); } else { contentByte.ShowText(textContent); } contentByte.Stroke(); contentByte.EndText(); }
/// <summary> /// Draw the header of the grid. /// </summary> /// <param name="cb">content byte to manipulate the a part of a pdf document</param> /// <param name="location">location (rectangle in mm) of the grid</param> /// <param name="dtTimeStamp">Time stamp of the beginning of the signal</param> /// <param name="mm_Per_s">mm per second</param> /// <param name="mm_Per_mV">mm per milliVolt</param> public static void DrawGridHeader(PdfContentByte cb, RectangleF location, DateTime dtTimeStamp, float mm_Per_s, float mm_Per_mV) { try { float fX = (location.X * PdfDocumentDpi) / mm_Per_Inch, fY = (-location.Y * PdfDocumentDpi) / mm_Per_Inch; string sText = dtTimeStamp.ToLongTimeString(); cb.BeginText(); if (dtTimeStamp.Year >= 1500) { sText = dtTimeStamp.ToShortDateString() + " " + sText; } cb.ShowTextAligned( PdfContentByte.ALIGN_LEFT, sText, fX, fY, 0); fX = (location.Right * PdfDocumentDpi) / mm_Per_Inch; sText = mm_Per_s.ToString("0") + " mm/s, " + mm_Per_mV.ToString("0") + " mm/mV"; cb.ShowTextAligned( PdfContentByte.ALIGN_RIGHT, sText, fX, fY, 0); cb.EndText(); } catch {} }
public override void OnEndPage(PdfWriter pw, Document doc) { float FontSize = 9; RecipeBook.PageOrder.AddLast(RecipeBook.PageNum); string PageNum = RecipeBook.PageNum.ToString(); float len = RecipeBook.BaseFont.GetWidthPoint(PageNum, FontSize); PdfContentByte cb = pw.DirectContent; cb.SetColorFill(BaseColor.DARK_GRAY); cb.BeginText(); cb.SetFontAndSize(RecipeBook.BaseFont, FontSize); if (RecipeBook.PageNum % 2 == 1) { cb.SetTextMatrix(doc.GetRight(len), doc.GetBottom(-RecipeBook.Margin)); } else { cb.SetTextMatrix(doc.GetLeft(0), doc.GetBottom(-RecipeBook.Margin)); } cb.ShowText(PageNum); string Copyright = string.Format("Copyright © {0}-{1} {2}", g.Company.RecipeBookCopyright, DateTime.Today.Year, g.Company.LegalName); len = RecipeBook.BaseFont.GetWidthPoint(Copyright, FontSize); float pos = (doc.Right - doc.Left - len) / 2; cb.SetTextMatrix(doc.GetLeft(pos), doc.GetBottom(-RecipeBook.Margin)); cb.ShowText(Copyright); cb.EndText(); if (RecipeBook.NextPageNum > 0) { RecipeBook.PageNum = RecipeBook.NextPageNum; RecipeBook.NextPageNum = 0; } }
private void AddMultiLineWaterMarkText(PdfContentByte pdfData, DateTime dtCurrentDate, float fontSize, float angle, Rectangle realPageSize) { iTextSharp.text.pdf.BaseFont baseFont; BaseColor color = BaseColor.RED; var x = (realPageSize.Right + realPageSize.Left) / 3; var y = (realPageSize.Bottom + realPageSize.Top) / 2; string sTextDate = dtCurrentDate.ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); var gstate = new PdfGState { FillOpacity = 0.35f, StrokeOpacity = 0.3f }; pdfData.SaveState(); pdfData.SetGState(gstate); pdfData.SetColorFill(color); pdfData.BeginText(); baseFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.WINANSI, false); //adding some lines to the left ColumnText.ShowTextAligned(pdfData, Element.ALIGN_CENTER, new Phrase("Confidential", new Font(baseFont, fontSize)), x, y, angle); baseFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.WINANSI, false); ColumnText.ShowTextAligned(pdfData, Element.ALIGN_CENTER, new Phrase("Downloaded by", new Font(baseFont, fontSize)), x + 70, y - 10, angle); pdfData.EndText(); ColumnText.ShowTextAligned(pdfData, Element.ALIGN_CENTER, new Phrase("beguschs", new Font(baseFont, fontSize)), x + 140, y - 20, angle); ColumnText.ShowTextAligned(pdfData, Element.ALIGN_CENTER, new Phrase(sTextDate, new Font(baseFont, fontSize)), x + 210, y - 30, angle); pdfData.EndText(); pdfData.RestoreState(); }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { base.OnEndPage(writer, document); iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); String text = "Page " + writer.PageNumber + " of "; this.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //Add paging to footer { cb.BeginText(); var arial_italic_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ariali.ttf"); var arial_italic_base = BaseFont.CreateFont(arial_italic_path, BaseFont.IDENTITY_H, false); cb.SetFontAndSize(arial_italic_base, 8); int marginRight = 80; cb.SetTextMatrix(document.PageSize.GetRight(marginRight), document.PageSize.GetBottom(30)); cb.ShowText(text); float len = bf.GetWidthPoint(text, 8); cb.EndText(); cb.AddTemplate(footerTemplate, document.PageSize.GetRight(marginRight) + len, document.PageSize.GetBottom(30)); } PdfPTable t = this.DisplayLogo(); t.TotalWidth = this.TotalWidth; t.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - this.Margin, writer.DirectContent); t = this.DisplayWIHeader(); t.TotalWidth = this.TotalWidth; t.WriteSelectedRows(0, -1, document.LeftMargin , document.PageSize.Height - this.Margin - 0.93f * this.Scale, writer.DirectContent); t = this.DisplayFooter(); t.TotalWidth = this.TotalWidth; t.WriteSelectedRows(0, -1, document.LeftMargin, document.BottomMargin, writer.DirectContent); }
// write on end of each page public override void OnEndPage(PdfWriter writer, Document document) { //Adiociona os direitos autorais na última página #region Footer base.OnEndPage(writer, document); PdfPTable footerTbl = new PdfPTable(1); footerTbl.WidthPercentage = 100f; footerTbl.TotalWidth = 1000f; footerTbl.HorizontalAlignment = 0; PdfPCell cell; footerTbl.DefaultCell.HorizontalAlignment = 0; footerTbl.WidthPercentage = 100; cell = new PdfPCell(new Phrase("Copyright © " + DateTime.Now.Year + " | Automasul ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK))); cell.Border = 0; cell.Colspan = 1; cell.PaddingLeft = 0; cell.HorizontalAlignment = 0; footerTbl.AddCell(cell); footerTbl.WriteSelectedRows(0, -30, 230, 30, writer.DirectContent); base.OnEndPage(writer, document); int pageN = writer.PageNumber; String text = pageN.ToString(); iTextSharp.text.Rectangle pageSize = document.PageSize; cb.SetRGBColorFill(100, 100, 100); cb.BeginText(); cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 11F); cb.SetTextMatrix(document.RightMargin, pageSize.GetBottom(document.BottomMargin)); cb.ShowText(text); cb.EndText(); cb.AddTemplate(template, document.RightMargin + 0, pageSize.GetBottom(document.BottomMargin)); #endregion }
protected byte[] CreatePdfWithOverlappingTextHorizontal(String[] text1, String[] text2) { MemoryStream baos = new MemoryStream(); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, baos); writer.CompressionLevel = 0; doc.Open(); PdfContentByte canvas = writer.DirectContent; float ystart = 500; float xstart = 50; canvas.BeginText(); canvas.SetFontAndSize(BaseFont.CreateFont(), 12); float x = xstart; float y = ystart; foreach (string text in text1) { canvas.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x, y, 0); x += 70.0f; } x = xstart + 12; y = ystart; foreach (string text in text2) { canvas.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x, y, 0); x += 70.0f; } canvas.EndText(); doc.Close(); return(baos.ToArray()); }
private byte[] CreatePdfWithLittleFontSize() { MemoryStream baos = new MemoryStream(); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, baos); doc.Open(); BaseFont font = BaseFont.CreateFont(); PdfContentByte canvas = writer.DirectContent; canvas.BeginText(); canvas.SetFontAndSize(font, 0.2f); canvas.MoveText(45, doc.PageSize.Height - 45); PdfTextArray textArray = new PdfTextArray(); textArray.Add("P"); textArray.Add("r"); textArray.Add("e"); textArray.Add("f"); textArray.Add("a"); textArray.Add("c"); textArray.Add("e"); textArray.Add(" "); canvas.ShowText(textArray); canvas.SetFontAndSize(font, 10); canvas.ShowText(textArray); canvas.EndText(); doc.Close(); byte[] pdfBytes = baos.ToArray(); return(pdfBytes); }
public override void OnEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.DirectContent; cb.SaveState(); // Cabeçalho tabelaCabecalho.TotalWidth = (document.Right - document.Left); tabelaCabecalho.WriteSelectedRows(0, -1, document.Left, document.PageSize.Height - 15, cb); // Rodapé tabelaRodape.TotalWidth = (document.Right - document.Left); tabelaRodape.WriteSelectedRows(0, -1, document.Left, document.PageSize.Height - 795, cb); cb.RestoreState(); // Numero de Páginas String text = pagina.ToString() + "/"; if (pagina == count) { count++; } pagina++; float textSize = helv.GetWidthPoint(text, 10); float textBase = document.Bottom - 17; cb.SaveState(); cb.BeginText(); cb.SetFontAndSize(helv, 10); cb.SetTextMatrix((document.Right - 20), textBase); cb.ShowText(text); cb.EndText(); cb.AddTemplate(tpPag, (document.Right - 20) + textSize, textBase); cb.RestoreState(); }
public void CreatePdfLow() { // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(RESULT_LOW, FileMode.Create)); writer.CompressionLevel = PdfStream.NO_COMPRESSION; // step 3 document.Open(); // step 4 PdfContentByte canvas = writer.DirectContentUnder; canvas.SaveState(); // q canvas.BeginText(); // BT canvas.MoveText(36, 788); // 36 788 Td canvas.SetFontAndSize(BaseFont.CreateFont(), 12); // /F1 12 Tf canvas.ShowText("Hello World!"); // (Hello World!)Tj canvas.EndText(); // ET canvas.RestoreState(); // Q // step 5 document.Close(); }
public override void DrawString(string text, IFont font, IBrush brush, float x, float y) { if (brush != null) { SetFillColor(brush.Color); } int h = GetTextHeight(font); x = CheckVal(x, false); y = CheckVal(y, true, h); try { BaseFont baseFont = GetBaseFont(font); fCanvas.SetFontAndSize(baseFont, font.Size); fCanvas.BeginText(); fCanvas.SetTextMatrix(x, y); fCanvas.ShowText(text); } finally { fCanvas.EndText(); } }
private bool CreateTexBox(string textBoxName, float left, float top, double width, string content, PdfContentByte contentByte) { bool success = false; try { BaseFont baseFont = BaseFont.CreateFont(this.FontPath, BaseFont.CP1250, BaseFont.EMBEDDED); //contentByte.SetColorFill(new BaseColor(255, 0, 0)); contentByte.BeginText(); contentByte.SetFontAndSize(baseFont, 9); contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, string.IsNullOrWhiteSpace(content) ? string.Empty : content, left, top, 0); //contentByte. contentByte.EndText(); success = true; } catch (Exception) { throw; } return(success); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); string ARIALUNI_TFF = HttpContext.Current.Server.MapPath("~/fonts/ARIALUNI.TTF"); BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); int pageN = writer.PageNumber; string text = pageN.ToString() + "/"; float len = bf.GetWidthPoint(text, 9f); iTextSharp.text.Rectangle pageSize = document.PageSize; cb.SetRGBColorFill(100, 100, 100); cb.BeginText(); cb.SetFontAndSize(bf, 9); cb.SetTextMatrix(document.LeftMargin, pageSize.GetBottom(document.BottomMargin)); cb.ShowText(text); cb.EndText(); cb.AddTemplate(template, document.LeftMargin + len, pageSize.GetBottom(document.BottomMargin)); }
public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle) { int alignment = 0; switch (hAlignment) { case HAlignment.VA_CENTER: alignment = PdfContentByte.ALIGN_CENTER; break; case HAlignment.VA_LEFT: alignment = PdfContentByte.ALIGN_LEFT; break; case HAlignment.VA_RIGHT: alignment = PdfContentByte.ALIGN_RIGHT; break; default: break; } float fontSize = FontSize(font); float fontRise = 0.0f; switch (vAlignment) { case VAlignment.VA_BOTTOM: fontRise = 0.5f; break; case VAlignment.VA_MIDDLE: fontRise = 0.0f * fontSize; break; case VAlignment.VA_TOP: fontRise = -0.5f * fontSize; break; default: break; } _cb.BeginText(); BaseFont bf = ToBaseFont(font); _cb.SetTextRise(fontRise); _cb.SetTextMatrix(1.0f, 0.0f, 0.0f, 1.0f, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f); _cb.ShowTextAligned(alignment, text, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f, 0.0f); _cb.EndText(); }
//************************************************* //** Date created: Tuesday, January 05, 2010 //** Created by : PAWN\rmcbai1 //************************************************** /// <summary> /// Create and print our Page header. I should /// probably find a way to do this via the overrides /// list below, but not today. /// </summary> /// //************************************************* private void PrintPageHeader(PdfContentByte cb, Image jpeg) { try { jpeg.ScalePercent(84); jpeg.SetAbsolutePosition(1, 730); _document.Add(jpeg); bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix(400, 732); cb.ShowText(_reportData.Tables["OUTPUT"].Rows[1][1].ToString()); cb.SetTextMatrix(400, 720); cb.ShowText("RunDate: " + DateTime.Now.ToShortDateString()); cb.SetTextMatrix(400, 708); cb.ShowText("Report # 201"); cb.SetTextMatrix(10, 700); cb.ShowText("Operational"); cb.SetTextMatrix(10, 690); // PWNU00000582 4/1/2010 SMurphy added date info //cb.ShowText(_dateRange); cb.ShowText(this.StartDate + " to " + this.EndDate); bf = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //Font titleFont = new Font(bf, 12, Font.BOLD); cb.SetTextMatrix(100, 648); cb.ShowText("MULTIPLE SALE OR OTHER DISPOSITION OF PISTOLS AND REVOLVERS "); } catch (Exception ex) { _errTxt = ex.Message; _errCode = 1; throw; } return; }
public override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); Rectangle pagesize = document.PageSize; Rectangle rect; if (Header != String.Empty) { cb.BeginText(); cb.SetFontAndSize(bf, 12); cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetTop(30)); cb.ShowText(Header); cb.EndText(); cb.MoveTo(pagesize.GetLeft(40), pagesize.GetTop(35)); cb.LineTo(pagesize.GetRight(40), pagesize.GetTop(35)); cb.SetLineWidth(3f); cb.Stroke(); } if (Body != null) { cb = writer.DirectContent; //cb.BeginText(); cb.SetFontAndSize(bf, 100); rect = new Rectangle(pagesize.GetLeft(40), pagesize.GetTop(40), 100, 100); cb.Rectangle(rect); cb.Stroke(); ColumnText ct = new ColumnText(cb); ct.SetSimpleColumn(rect); ct.AddElement(new iTextSharp.text.Paragraph(Body)); ct.Go(); //cb.ShowText("hello"); //cb.EndText(); } }
// --------------------------------------------------------------------------- /** * Generates a PDF file with the text 'Hello World' */ public byte[] CreatePdf() { using (MemoryStream ms = new MemoryStream()) { using (Document document = new Document()) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, ms); // step 3 document.Open(); // step 4 // we add the text to the direct content, but not in the right order PdfContentByte cb = writer.DirectContent; BaseFont bf = BaseFont.CreateFont(); cb.BeginText(); cb.SetFontAndSize(bf, 12); cb.MoveText(88.66f, 367); cb.ShowText("ld"); cb.MoveText(-22f, 0); cb.ShowText("Wor"); cb.MoveText(-15.33f, 0); cb.ShowText("llo"); cb.MoveText(-15.33f, 0); cb.ShowText("He"); cb.EndText(); // we also add text in a form XObject PdfTemplate tmp = cb.CreateTemplate(250, 25); tmp.BeginText(); tmp.SetFontAndSize(bf, 12); tmp.MoveText(0, 7); tmp.ShowText("Hello People"); tmp.EndText(); cb.AddTemplate(tmp, 36, 343); } return(ms.ToArray()); } }
public static byte[] AddPageNumbers(byte[] pdf, ref BackgroundWorker bw) { MemoryStream ms = new MemoryStream(); PdfReader reader = new PdfReader(pdf); int n = reader.NumberOfPages; iTextSharp.text.Rectangle psize = reader.GetPageSize(1); Document document = new Document(psize, 50, 50, 50, 50); PdfWriter writer = PdfWriter.GetInstance(document, ms); document.Open(); PdfContentByte cb = writer.DirectContent; int p = 0; for (int page = 1; page <= reader.NumberOfPages; page++) { bw.ReportProgress(page); document.NewPage(); p++; PdfImportedPage importedPage = writer.GetImportedPage(reader, page); cb.AddTemplate(importedPage, 0, 0); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, string.Format("{0}", p), document.PageSize.Width / 2, (float)((document.PageSize.Height * 0.01)) , 0); cb.EndText(); } document.Close(); return(ms.ToArray()); }
// write on start of each page public override void OnStartPage(PdfWriter writer, Document document) { base.OnStartPage(writer, document); if (Report_Code == Page_Code.P0007) { /*Logsheet*/ if (Logsheet != null) { Rectangle pageSize = document.PageSize; int pageN = writer.PageNumber; String text = "Page No. " + pageN + " / "; float len = bf.GetWidthPoint(text, 8); cb.SetRGBColorFill(100, 100, 100); cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, text, pageSize.GetRight(40), pageSize.GetTop(30), 0); cb.EndText(); cb.AddTemplate(template, pageSize.GetRight(40), pageSize.GetTop(30)); } } }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); if (Reporte == 1) { PdfTemplate templateM = cb.CreateTemplate(50, 50); templates.Add(templateM); int pageN = writer.CurrentPageNumber; string pageText = "Página " + pageN.ToString("00") + " de "; string pageSicorp = "Academia GOLL " + DateTime.Now.ToString("dd-MM-yyyy"); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); float len = bf.GetWidthPoint(pageText, 10); cb.BeginText(); cb.SetFontAndSize(bf, 10); cb.SetTextMatrix((document.PageSize.Width - 120f), document.PageSize.GetBottom(document.BottomMargin - 5)); cb.ShowText(pageText); cb.EndText(); cb.AddTemplate(templateM, (document.PageSize.Width - 120f) + len, document.PageSize.GetBottom(document.BottomMargin - 5)); cbsimarn.BeginText(); cbsimarn.SetFontAndSize(bf, 10); cbsimarn.SetTextMatrix(document.LeftMargin, document.PageSize.GetBottom(document.BottomMargin - 5)); cbsimarn.ShowText(pageSicorp); cbsimarn.EndText(); } else if (Reporte == 3) { //PdfTemplate templateM = cb.CreateTemplate(50, 50); //string pageSicorp = "SICORP " + DateTime.Now.ToString("dd-MM-yyyy"); //BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //cbsimarn.BeginText(); //cbsimarn.SetFontAndSize(bf, 10); //cbsimarn.SetTextMatrix(document.LeftMargin, document.PageSize.GetBottom(document.BottomMargin)); //cbsimarn.ShowText(pageSicorp); //cbsimarn.EndText(); } }
/** * Initializes a page. * <P> * If the footer/header is set, it is printed. * @throws DocumentException on error */ protected internal void InitPage() { // the pagenumber is incremented pageN++; // initialisation of some page objects annotationsImp.ResetAnnotations(); pageResources = new PageResources(); writer.ResetContent(); graphics = new PdfContentByte(writer); text = new PdfContentByte(writer); text.Reset(); text.BeginText(); textEmptySize = text.Size; markPoint = 0; SetNewPageSizeAndMargins(); imageEnd = -1; indentation.imageIndentRight = 0; indentation.imageIndentLeft = 0; indentation.indentBottom = 0; indentation.indentTop = 0; currentHeight = 0; // backgroundcolors, etc... thisBoxSize = new Hashtable(boxSize); if (pageSize.BackgroundColor != null || pageSize.HasBorders() || pageSize.BorderColor != null) { Add(pageSize); } float oldleading = leading; int oldAlignment = alignment; // if there is a footer, the footer is added DoFooter(); // we move to the left/top position of the page text.MoveText(Left, Top); DoHeader(); pageEmpty = true; // if there is an image waiting to be drawn, draw it if (imageWait != null) { Add(imageWait); imageWait = null; } leading = oldleading; alignment = oldAlignment; CarriageReturn(); IPdfPageEvent pageEvent = writer.PageEvent; if (pageEvent != null) { if (firstPageEvent) { pageEvent.OnOpenDocument(writer, this); } pageEvent.OnStartPage(writer, this); } firstPageEvent = false; }
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The * barcode is always placed at coodinates (0, 0). Use the * translation matrix to move it elsewhere.<p> * The bars and text are written in the following colors:<p> * <P><TABLE BORDER=1> * <TR> * <TH><P><CODE>barColor</CODE></TH> * <TH><P><CODE>textColor</CODE></TH> * <TH><P>Result</TH> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with current fill color</TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with <CODE>barColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD> * </TR> * </TABLE> * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the dimensions the barcode occupies */ public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) { Rectangle rect = this.BarcodeSize; float barStartX = 0; float barStartY = 0; float textStartY = 0; if (font != null) { if (baseline <= 0) textStartY = barHeight - baseline; else { textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size); barStartY = textStartY + baseline; } } switch (codeType) { case EAN13: case UPCA: case UPCE: if (font != null) barStartX += font.GetWidthPoint(code[0], size); break; } byte[] bars = null; int[] guard = GUARD_EMPTY; switch (codeType) { case EAN13: bars = GetBarsEAN13(code); guard = GUARD_EAN13; break; case EAN8: bars = GetBarsEAN8(code); guard = GUARD_EAN8; break; case UPCA: bars = GetBarsEAN13("0" + code); guard = GUARD_UPCA; break; case UPCE: bars = GetBarsUPCE(code); guard = GUARD_UPCE; break; case SUPP2: bars = GetBarsSupplemental2(code); break; case SUPP5: bars = GetBarsSupplemental5(code); break; } float keepBarX = barStartX; bool print = true; float gd = 0; if (font != null && baseline > 0 && guardBars) { gd = baseline / 2; } if (barColor != null) cb.SetColorFill(barColor); for (int k = 0; k < bars.Length; ++k) { float w = bars[k] * x; if (print) { if (Array.BinarySearch(guard, k) >= 0) cb.Rectangle(barStartX, barStartY - gd, w - inkSpreading, barHeight + gd); else cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight); } print = !print; barStartX += w; } cb.Fill(); if (font != null) { if (textColor != null) cb.SetColorFill(textColor); cb.BeginText(); cb.SetFontAndSize(font, size); switch (codeType) { case EAN13: cb.SetTextMatrix(0, textStartY); cb.ShowText(code.Substring(0, 1)); for (int k = 1; k < 13; ++k) { string c = code.Substring(k, 1); float len = font.GetWidthPoint(c, size); float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2; cb.SetTextMatrix(pX, textStartY); cb.ShowText(c); } break; case EAN8: for (int k = 0; k < 8; ++k) { string c = code.Substring(k, 1); float len = font.GetWidthPoint(c, size); float pX = TEXTPOS_EAN8[k] * x - len / 2; cb.SetTextMatrix(pX, textStartY); cb.ShowText(c); } break; case UPCA: cb.SetTextMatrix(0, textStartY); cb.ShowText(code.Substring(0, 1)); for (int k = 1; k < 11; ++k) { string c = code.Substring(k, 1); float len = font.GetWidthPoint(c, size); float pX = keepBarX + TEXTPOS_EAN13[k] * x - len / 2; cb.SetTextMatrix(pX, textStartY); cb.ShowText(c); } cb.SetTextMatrix(keepBarX + x * (11 + 12 * 7), textStartY); cb.ShowText(code.Substring(11, 1)); break; case UPCE: cb.SetTextMatrix(0, textStartY); cb.ShowText(code.Substring(0, 1)); for (int k = 1; k < 7; ++k) { string c = code.Substring(k, 1); float len = font.GetWidthPoint(c, size); float pX = keepBarX + TEXTPOS_EAN13[k - 1] * x - len / 2; cb.SetTextMatrix(pX, textStartY); cb.ShowText(c); } cb.SetTextMatrix(keepBarX + x * (9 + 6 * 7), textStartY); cb.ShowText(code.Substring(7, 1)); break; case SUPP2: case SUPP5: for (int k = 0; k < code.Length; ++k) { string c = code.Substring(k, 1); float len = font.GetWidthPoint(c, size); float pX = (7.5f + (9 * k)) * x - len / 2; cb.SetTextMatrix(pX, textStartY); cb.ShowText(c); } break; } cb.EndText(); } return rect; }
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The * barcode is always placed at coodinates (0, 0). Use the * translation matrix to move it elsewhere.<p> * The bars and text are written in the following colors:<p> * <P><TABLE BORDER=1> * <TR> * <TH><P><CODE>barColor</CODE></TH> * <TH><P><CODE>textColor</CODE></TH> * <TH><P>Result</TH> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with current fill color</TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with <CODE>barColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD> * </TR> * </TABLE> * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the dimensions the barcode occupies */ public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) { String fullCode = code; if (generateChecksum && checksumText) fullCode = CalculateChecksum(code); if (!startStopText) fullCode = fullCode.Substring(1, fullCode.Length - 2); float fontX = 0; if (font != null) { fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size); } byte[] bars = GetBarsCodabar(generateChecksum ? CalculateChecksum(code) : code); int wide = 0; for (int k = 0; k < bars.Length; ++k) { wide += (int)bars[k]; } int narrow = bars.Length - wide; float fullWidth = x * (narrow + wide * n); float barStartX = 0; float textStartX = 0; switch (textAlignment) { case Element.ALIGN_LEFT: break; case Element.ALIGN_RIGHT: if (fontX > fullWidth) barStartX = fontX - fullWidth; else textStartX = fullWidth - fontX; break; default: if (fontX > fullWidth) barStartX = (fontX - fullWidth) / 2; else textStartX = (fullWidth - fontX) / 2; break; } float barStartY = 0; float textStartY = 0; if (font != null) { if (baseline <= 0) textStartY = barHeight - baseline; else { textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size); barStartY = textStartY + baseline; } } bool print = true; if (barColor != null) cb.SetColorFill(barColor); for (int k = 0; k < bars.Length; ++k) { float w = (bars[k] == 0 ? x : x * n); if (print) cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight); print = !print; barStartX += w; } cb.Fill(); if (font != null) { if (textColor != null) cb.SetColorFill(textColor); cb.BeginText(); cb.SetFontAndSize(font, size); cb.SetTextMatrix(textStartX, textStartY); cb.ShowText(fullCode); cb.EndText(); } return BarcodeSize; }
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The * barcode is always placed at coodinates (0, 0). Use the * translation matrix to move it elsewhere.<p> * The bars and text are written in the following colors:<p> * <P><TABLE BORDER=1> * <TR> * <TH><P><CODE>barColor</CODE></TH> * <TH><P><CODE>textColor</CODE></TH> * <TH><P>Result</TH> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with current fill color</TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with <CODE>barColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD> * </TR> * </TABLE> * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the dimensions the barcode occupies */ public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) { string fullCode; if (codeType == CODE128_RAW) { int idx = code.IndexOf('\uffff'); if (idx < 0) fullCode = ""; else fullCode = code.Substring(idx + 1); } else if (codeType == CODE128_UCC) fullCode = GetHumanReadableUCCEAN(code); else fullCode = RemoveFNC1(code); float fontX = 0; if (font != null) { fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size); } string bCode; if (codeType == CODE128_RAW) { int idx = code.IndexOf('\uffff'); if (idx >= 0) bCode = code.Substring(0, idx); else bCode = code; } else { bCode = GetRawText(code, codeType == CODE128_UCC); } int len = bCode.Length; float fullWidth = (len + 2) * 11 * x + 2 * x; float barStartX = 0; float textStartX = 0; switch (textAlignment) { case Element.ALIGN_LEFT: break; case Element.ALIGN_RIGHT: if (fontX > fullWidth) barStartX = fontX - fullWidth; else textStartX = fullWidth - fontX; break; default: if (fontX > fullWidth) barStartX = (fontX - fullWidth) / 2; else textStartX = (fullWidth - fontX) / 2; break; } float barStartY = 0; float textStartY = 0; if (font != null) { if (baseline <= 0) textStartY = barHeight - baseline; else { textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size); barStartY = textStartY + baseline; } } byte[] bars = GetBarsCode128Raw(bCode); bool print = true; if (barColor != null) cb.SetColorFill(barColor); for (int k = 0; k < bars.Length; ++k) { float w = bars[k] * x; if (print) cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight); print = !print; barStartX += w; } cb.Fill(); if (font != null) { if (textColor != null) cb.SetColorFill(textColor); cb.BeginText(); cb.SetFontAndSize(font, size); cb.SetTextMatrix(textStartX, textStartY); cb.ShowText(fullCode); cb.EndText(); } return this.BarcodeSize; }
/** Places the barcode in a <CODE>PdfContentByte</CODE>. The * barcode is always placed at coodinates (0, 0). Use the * translation matrix to move it elsewhere.<p> * The bars and text are written in the following colors:<p> * <P><TABLE BORDER=1> * <TR> * <TH><P><CODE>barColor</CODE></TH> * <TH><P><CODE>textColor</CODE></TH> * <TH><P>Result</TH> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with current fill color</TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>null</CODE></TD> * <TD><P>bars and text painted with <CODE>barColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>null</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with current color<br>text painted with <CODE>textColor</CODE></TD> * </TR> * <TR> * <TD><P><CODE>barColor</CODE></TD> * <TD><P><CODE>textColor</CODE></TD> * <TD><P>bars painted with <CODE>barColor</CODE><br>text painted with <CODE>textColor</CODE></TD> * </TR> * </TABLE> * @param cb the <CODE>PdfContentByte</CODE> where the barcode will be placed * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the dimensions the barcode occupies */ public override Rectangle PlaceBarcode(PdfContentByte cb, Color barColor, Color textColor) { string fullCode = code; float fontX = 0; string bCode = code; if (extended) bCode = GetCode39Ex(code); if (font != null) { if (generateChecksum && checksumText) fullCode += GetChecksum(bCode); if (startStopText) fullCode = "*" + fullCode + "*"; fontX = font.GetWidthPoint(fullCode = altText != null ? altText : fullCode, size); } if (generateChecksum) bCode += GetChecksum(bCode); int len = bCode.Length + 2; float fullWidth = len * (6 * x + 3 * x * n) + (len - 1) * x; float barStartX = 0; float textStartX = 0; switch (textAlignment) { case Element.ALIGN_LEFT: break; case Element.ALIGN_RIGHT: if (fontX > fullWidth) barStartX = fontX - fullWidth; else textStartX = fullWidth - fontX; break; default: if (fontX > fullWidth) barStartX = (fontX - fullWidth) / 2; else textStartX = (fullWidth - fontX) / 2; break; } float barStartY = 0; float textStartY = 0; if (font != null) { if (baseline <= 0) textStartY = barHeight - baseline; else { textStartY = -font.GetFontDescriptor(BaseFont.DESCENT, size); barStartY = textStartY + baseline; } } byte[] bars = GetBarsCode39(bCode); bool print = true; if (barColor != null) cb.SetColorFill(barColor); for (int k = 0; k < bars.Length; ++k) { float w = (bars[k] == 0 ? x : x * n); if (print) cb.Rectangle(barStartX, barStartY, w - inkSpreading, barHeight); print = !print; barStartX += w; } cb.Fill(); if (font != null) { if (textColor != null) cb.SetColorFill(textColor); cb.BeginText(); cb.SetFontAndSize(font, size); cb.SetTextMatrix(textStartX, textStartY); cb.ShowText(fullCode); cb.EndText(); } return this.BarcodeSize; }