/// <summary> /// Get the converted font. /// </summary> /// <returns>The text font.</returns> internal iTextSharp.text.Font GetFont() { // Create the text font. iTextSharp.text.BaseColor color = new iTextSharp.text.BaseColor(_color); iTextSharp.text.Font font = new iTextSharp.text.Font(GetBaseFont(), _size, (int)_style, color); return(font); }
public static ReportColor Create(iTextSharp.text.BaseColor color) { return(new ReportColor { Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B) }); }
public static System.Drawing.Color GetCompatibleColor(System.Drawing.KnownColor color) { System.Drawing.Color drColor = GetCompatibleColorInternal(color); iTextSharp.text.BaseColor tsColor = new iTextSharp.text.BaseColor(drColor.R, drColor.G, drColor.B); return(GetCompatibleColorInternal(System.Drawing.Color.FromArgb(tsColor.R, tsColor.G, tsColor.B))); }
public PdfPCell ImageCell(string path, float scale, int align, iTextSharp.text.BaseColor CellBorderColer) { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(path)); image.ScalePercent(scale); PdfPCell cell = new PdfPCell(image); cell.BorderColor = CellBorderColer; cell.VerticalAlignment = PdfPCell.ALIGN_CENTER; cell.HorizontalAlignment = align; cell.PaddingBottom = 0f; cell.PaddingTop = 2f; return(cell); }
//rahmenArt, variante, //RahmenArt rahmenArt, Variante variante, public DrawContextDocument(iTextSharp.text.pdf.PdfContentByte pCon, iTextSharp.text.BaseColor Rand, float[] tabb, float[] hohh, float x, float y, float zeit) : base(tabb, hohh, x, y, zeit) { this.pCon = pCon; this.yOff = pCon.PdfDocument.Top; this.Rand = Rand; //if (!fontsInFontFactory) //{ // fontsInFontFactory = true; // iTextSharp.text.FontFactory.RegisterDirectory(FontPath); //} if (!madeBaseFonts) { madeBaseFonts = true; fonts = new BaseFont[8]; fonts[0] = BaseFont.CreateFont(FontPath + "calibri.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[1] = BaseFont.CreateFont(FontPath + "calibrib.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[2] = BaseFont.CreateFont(FontPath + "calibrii.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[3] = BaseFont.CreateFont(FontPath + "calibriz.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[4] = BaseFont.CreateFont(FontPath + "Exocet2.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[5] = BaseFont.CreateFont(FontPath + "Exocet1.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[6] = BaseFont.CreateFont(FontPath + "Exocet2.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); fonts[7] = BaseFont.CreateFont(FontPath + "Exocet1.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); //throw new Exception(); } }
protected AbstractFillPattern(iTextSharp.text.BaseColor pdfColor) { this.pdfColor = pdfColor; }
static System.Drawing.Color GetCompatibleColorInternal(System.Drawing.Color color) { iTextSharp.text.BaseColor tsColor = new iTextSharp.text.BaseColor(color); return(System.Drawing.Color.FromArgb(tsColor.R, tsColor.G, tsColor.B)); }
public SolidFillPattern(iTextSharp.text.BaseColor pdfColor) : base(pdfColor) { }
public override void OnStartPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { if (!UsingCubeFeatures) { return; } iTextSharp.text.BaseColor lineColor = iTextSharp.text.BaseColor.BLACK; if (PrintingBlackBorder) { lineColor = iTextSharp.text.BaseColor.WHITE; } // Vertical bars at: // 13, 114, 223, 312 // Horizontal bars at: // 12, 137, 263, 388 float halfWidth = 1.0f; // Do it twice, once on top, once on bottom for (int i = 0; i < 2; i++) { float top = 17; float bottom = 0; if (i == 1) { top = 783; bottom = 800; } iTextSharp.text.Rectangle Vert1 = new iTextSharp.text.Rectangle(27.5f - halfWidth, top, 27.5f + halfWidth, bottom); Vert1.BackgroundColor = lineColor; document.Add(Vert1); iTextSharp.text.Rectangle Vert2 = new iTextSharp.text.Rectangle(206.2f - halfWidth, top, 206.2f + halfWidth, bottom); Vert2.BackgroundColor = lineColor; document.Add(Vert2); iTextSharp.text.Rectangle Vert3 = new iTextSharp.text.Rectangle(385.3f - halfWidth, top, 385.3f + halfWidth, bottom); Vert3.BackgroundColor = lineColor; document.Add(Vert3); iTextSharp.text.Rectangle Vert4 = new iTextSharp.text.Rectangle(564.1f - halfWidth, top, 564.1f + halfWidth, bottom); Vert4.BackgroundColor = lineColor; document.Add(Vert4); } // Horizontal bars at: // 12, 137, 263, 388 for (int i = 0; i < 2; i++) { float right = 0; float left = 17; if (i == 1) { right = 575; left = 650; } iTextSharp.text.Rectangle Horz1 = new iTextSharp.text.Rectangle(right, 27 - halfWidth, left, 27 + halfWidth); Horz1.BackgroundColor = lineColor; document.Add(Horz1); iTextSharp.text.Rectangle Horz2 = new iTextSharp.text.Rectangle(right, 277 - halfWidth, left, 277 + halfWidth); Horz2.BackgroundColor = lineColor; document.Add(Horz2); iTextSharp.text.Rectangle Horz3 = new iTextSharp.text.Rectangle(right, 527 - halfWidth, left, 527 + halfWidth); Horz3.BackgroundColor = lineColor; document.Add(Horz3); iTextSharp.text.Rectangle Horz4 = new iTextSharp.text.Rectangle(right, 777 - halfWidth, left, 777 + halfWidth); Horz4.BackgroundColor = lineColor; document.Add(Horz4); } /* * int iVert = 0; * * for (int i = 0; i < document.PageSize.Width; i+=20) * { * iTextSharp.text.Rectangle Vert = new iTextSharp.text.Rectangle(i, 20, i+2, 0 ); * Vert.BackgroundColor = iTextSharp.text.BaseColor.RED; * document.Add(Vert); * } * * for (int i = 0; i < document.PageSize.Height; i += 20) * { * iTextSharp.text.Rectangle Vert = new iTextSharp.text.Rectangle(0, i, 20, i+2); * Vert.BackgroundColor = iTextSharp.text.BaseColor.BLUE; * document.Add(Vert); * } * * /* * float top = document.PageSize.Height - 10.0f; * iTextSharp.text.Rectangle TopLeft = new iTextSharp.text.Rectangle(iHorz1 - 1, top+20, iHorz1 + 1, top); * * //iTextSharp.text.Rectangle TopLeft = new iTextSharp.text.Rectangle(iHorz1-1, iVert4, iHorz1 + 1, iVert4); * TopLeft.BackgroundColor = iTextSharp.text.BaseColor.BLUE; * * iTextSharp.text.Rectangle BottomRight = new iTextSharp.text.Rectangle(iHorz4-1, iVert1, iHorz4 + 1, iVert1 -20); * BottomRight.BackgroundColor = iTextSharp.text.BaseColor.RED; * * * iTextSharp.text.Rectangle LeftTop = new iTextSharp.text.Rectangle(iHorz1-20, iVert4-1, iHorz1, iVert4+1); * TopLeft.BackgroundColor = iTextSharp.text.BaseColor.GRAY; * * iTextSharp.text.Rectangle RightBottom = new iTextSharp.text.Rectangle(iHorz4, iVert1-1, iHorz4 + 20, iVert1 +1); * RightBottom.BackgroundColor = iTextSharp.text.BaseColor.GREEN; * * * document.Add(TopLeft); * document.Add(BottomRight); * * document.Add(LeftTop); * document.Add(RightBottom); */ }
public static iTextSharp.text.Rectangle GetDocumentWithBackroundColor(iTextSharp.text.Rectangle pageSize, iTextSharp.text.BaseColor backgroundColor) { pageSize.BackgroundColor = backgroundColor; return(pageSize); }
/// <summary> /// 博格华纳文件添加水印 /// </summary> /// <param name="sourceFile">源文件</param> /// <param name="targetFile">目标文件</param> /// <param name="cType">1:受控水印;2:临时受控水印;3:作废水印</param> /// <param name="code">文档编号,非空时添加文档编号水印</param> /// <param name="aTime">评审日期</param> private bool FileAddWaterMark(string sourceFile, string targetFile, string cType, string code, DateTime aTime) { PdfReader pdfReader = null; PdfStamper pdfStamper = null; string tempPath = Environment.GetEnvironmentVariable("TEMP"); try { IntPtr vHandle = _lopen(sourceFile, OF_READWRITE | OF_SHARE_DENY_NONE); CloseHandle(vHandle); string s = ""; iTextSharp.text.BaseColor color = iTextSharp.text.BaseColor.DARK_GRAY; if (cType == "1") { s = "受 控"; } else if (cType == "2") { s = "临时受控"; } else if (cType == "3") { s = "作 废"; color = iTextSharp.text.BaseColor.RED; } pdfReader = new PdfReader(sourceFile); pdfStamper = new PdfStamper(pdfReader, new FileStream(targetFile, FileMode.Create)); int total = pdfReader.NumberOfPages + 1; PdfContentByte content; BaseFont font = BaseFont.CreateFont(@"C:\Windows\Fonts\msyh.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); PdfGState gs = new PdfGState(); for (int i = 0; i < total; i++) { content = pdfStamper.GetOverContent(i);//在内容上方加水印 if (content == null) { continue; } //透明度 gs.FillOpacity = 0.3f; content.SetGState(gs); content.SetLineWidth(0.05F); content.SetColorStroke(color); content.MoveTo(45F, 50F); content.LineTo(120F, 50F); content.LineTo(120F, 14F); content.MoveTo(45F, 50F); content.LineTo(45F, 14F); content.LineTo(120F, 14F); content.Stroke(); //开始写入文本 content.BeginText(); content.SetColorFill(color); content.SetFontAndSize(font, 5); content.SetTextMatrix(0, 0); content.ShowTextAligned(iTextSharp.text.Element.ALIGN_LEFT, "博格华纳汽车零部件有限公司", 50, 42, 0); content.SetFontAndSize(font, 8); content.ShowTextAligned(iTextSharp.text.Element.ALIGN_CENTER, s, 82, 32, 0); content.SetFontAndSize(font, 5); if (code != "") { content.ShowTextAligned(iTextSharp.text.Element.ALIGN_LEFT, code, 50, 24, 0); } content.ShowTextAligned(iTextSharp.text.Element.ALIGN_LEFT, aTime.ToString("yyyy年MM月dd日"), 80, 16, 0); content.EndText(); } return(true); } catch (Exception ex) { Log.Exception(ex.Message, ex); return(false); } finally { if (pdfStamper != null) { pdfStamper.Close(); } if (pdfReader != null) { pdfReader.Close(); } } }
public Annotation(PdfDictionary annotation, Geometry geometry) { this.Geometry = geometry; PdfString createdString = annotation.GetAsString(PdfName.CREATIONDATE); this.Created = (createdString == null) ? DateTime.MinValue : createdString.ToString().ToDateTime(); PdfString updatedString = annotation.GetAsString(PdfName.M); this.Updated = (updatedString == null) ? DateTime.MinValue : updatedString.ToString().ToDateTime(); PdfString contents = annotation.GetAsString(PdfName.CONTENTS); this.Contents = (contents == null) ? string.Empty : contents.ToString(); PdfString author = annotation.GetAsString(PdfName.T); this.Author = (author == null) ? string.Empty : author.ToString(); PdfString subject = annotation.GetAsString(PdfName.SUBJECT); this.Subject = (subject == null) ? string.Empty : subject.ToString(); PdfArray color = annotation.GetAsArray(PdfName.C); if (color != null && color.Size == 3) { var pdfcolor = new iTextSharp.text.BaseColor(color[0].ToFloat(), color[1].ToFloat(), color[2].ToFloat()); this.Color = pdfcolor.ToDSColor(); } if (this.Color == null) { PdfString ds = annotation.GetAsString(PdfName.DS); //font: Helvetica 12pt; text-align:left; margin:3pt; line-height:13.8pt; color:#000000 if (ds != null) { if (ds.ToString().Contains(';')) { string[] data = ds.ToString().Split(';'); Dictionary <string, string> datadict = new Dictionary <string, string>(); foreach (string d in data) { if (d.Contains(':')) { string[] vp = d.Split(':'); string key = vp[0].Replace(" ", ""); string val = vp[1].Replace(" ", ""); if (!datadict.ContainsKey(key)) { datadict.Add(key, val); } } } if (datadict.ContainsKey("color")) { var syscolor = System.Drawing.ColorTranslator.FromHtml(datadict["color"].ToUpper()); if (syscolor != null) { this.Color = DSCore.Color.ByARGB(syscolor.A, syscolor.R, syscolor.G, syscolor.B); } } } } if (this.Color == null) { this.Color = DSCore.Color.ByARGB(255, 255, 0, 0); } } }
public static DSCore.Color ToDSColor(this iTextSharp.text.BaseColor color) { return(DSCore.Color.ByARGB(color.A, color.R, color.G, color.B)); }