/// <summary> /// Scales the pdf image if nessarry by percent. /// </summary> /// <param name="img">The img.</param> /// <param name="frame">The frame.</param> /// <returns>The scaled image.</returns> private iTextSharp.text.Image ScaleIfNessarry(iTextSharp.text.Image img, Frame frame) { try { double scalingPrescision = 0.25; double scaledWidthPercent = 0; double scaledHeightPercent = 0; double odfScaledWidth = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgWidth); double odfScaledHeight = AODL.Document.Helper.SizeConverter.GetDoubleFromAnOfficeSizeValue(frame.SvgHeight); if ((frame.Height - odfScaledHeight) > scalingPrescision || (frame.Height - odfScaledHeight) < scalingPrescision) { scaledHeightPercent = ((100.0/frame.Height) * odfScaledHeight); Console.WriteLine("ScaledHeightPerc {0} , frame {1}, odfScaledHeight {2}", scaledHeightPercent, frame.Height, odfScaledHeight); } if ((frame.Width - odfScaledWidth) > scalingPrescision || (frame.Width - odfScaledWidth) < scalingPrescision) { scaledWidthPercent = ((100.0/frame.Width) * odfScaledWidth); } if (scaledHeightPercent != 0 || scaledWidthPercent != 0) { img.ScalePercent((float) scaledWidthPercent, (float) scaledHeightPercent); } return img; } catch(Exception) { throw; } }
/// <summary> /// Gets the text contents. /// </summary> /// <param name="textCollection">The text collection.</param> /// <returns>The content. ArrayList of chunks and phrases.</returns> public static ICollection GetTextContents(ITextCollection textCollection, iTextSharp.text.Font font) { ArrayList contents = new ArrayList(); foreach(object obj in textCollection) { if (obj is AODL.Document.Content.Text.FormatedText) { contents.Add(FormatedTextConverter.Convert( obj as AODL.Document.Content.Text.FormatedText)); } else if (obj is AODL.Document.Content.Text.SimpleText) { contents.Add(SimpleTextConverter.Convert( obj as AODL.Document.Content.Text.SimpleText, font)); } else if (obj is AODL.Document.Content.Text.TextControl.TabStop) { contents.Add(SimpleTextConverter.ConvertTabs( obj as AODL.Document.Content.Text.TextControl.TabStop, font)); } else if (obj is AODL.Document.Content.Text.TextControl.WhiteSpace) { contents.Add(SimpleTextConverter.ConvertWhiteSpaces( obj as AODL.Document.Content.Text.TextControl.WhiteSpace, font)); } } return contents; }
// http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, BaseLine line, IBaseStyleDecorator style, iTextSharp.text.Rectangle rectangle) { if (contentByte == null) { throw new ArgumentNullException("contentByte"); } if (style == null) { throw new ArgumentNullException("style"); } if (rectangle == null) { throw new ArgumentNullException("rectangle"); } if (line == null) { BaseShape.FillBackGround(contentByte,style,rectangle); } else { BaseShape.SetupShape(contentByte,style); contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point); contentByte.RoundRectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height, CornerRadius); BaseShape.FinishShape(contentByte); } }
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, BaseLine line, IBaseStyleDecorator style, Point from,Point to) { throw new NotImplementedException(); }
public RectangleJ(iTextSharp.text.Rectangle rect) { rect.Normalize(); x = rect.Left; y = rect.Bottom; width = rect.Width; height = rect.Height; }
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, BaseLine line, IBaseStyleDecorator style, iTextSharp.text.Rectangle rectangle) { if (contentByte == null) { throw new ArgumentNullException("contentByte"); } if (style == null) { throw new ArgumentNullException("style"); } if (rectangle == null) { throw new ArgumentNullException("rectangle"); } if ((line == null)||(line.Thickness < 1)) { BaseShape.FillBackGround(contentByte,style,rectangle); } else if ((style.BackColor == GlobalValues.DefaultBackColor)) { BaseShape.SetupShape(contentByte,style); contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point); contentByte.MoveTo(rectangle.Left ,rectangle.Top ); contentByte.LineTo(rectangle.Left, rectangle.Top - rectangle.Height); contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top - rectangle.Height); contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top); contentByte.LineTo(rectangle.Left, rectangle.Top); BaseShape.FinishShape(contentByte); } else { BaseShape.FillBackGround(contentByte,style,rectangle); } }
public void DrawBorder (iTextSharp.text.pdf.PdfContentByte contentByte, iTextSharp.text.Rectangle rectangle, ICSharpCode.Reports.Core.Exporter.IBaseStyleDecorator style) { if ( contentByte == null) { throw new ArgumentNullException("contentByte"); } contentByte.SetColorStroke(style.PdfFrameColor); contentByte.SetLineWidth(UnitConverter.FromPixel(baseline.Thickness).Point); contentByte.MoveTo(rectangle.Left ,rectangle.Top ); contentByte.LineTo(rectangle.Left, rectangle.Top - rectangle.Height); contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top - rectangle.Height); contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top); contentByte.LineTo(rectangle.Left, rectangle.Top); contentByte.FillStroke(); contentByte.ResetRGBColorFill(); }
public void FillEvent(string title, iTextSharp.text.Image imgLogo, int pageNumber, string shid, string businessName, string landownerName) { _title = title; _imgLogo = imgLogo; _shid = shid; _businessName = businessName; _landownerName = landownerName; _pageNumber = pageNumber; }
public void FillEvent(float[] hdrTableLayout, string[] hdrNameList, int shid, string payeeName, string title, iTextSharp.text.Image imgLogo) { _hdrTableLayout = hdrTableLayout; _hdrNameList = hdrNameList; _payeeName = payeeName; _shid = shid.ToString(); _title = title; _imgLogo = imgLogo; }
public static void AddParagraph(Document doc, int alignment, iTextSharp.text.Font font, iTextSharp.text.IElement content) { Paragraph paragraph = new Paragraph(); paragraph.SetLeading(0f, 1.2f); paragraph.Alignment = alignment; paragraph.Font = font; paragraph.Add(content); doc.Add(paragraph); }
public void AddString(string str ,iTextSharp.text.Font font) { if(doc!=null) { Paragraph myParagraph = new Paragraph(str, font); doc.Add(myParagraph); // Chunk chunk = new Chunk(str + "金鑫珠宝销售记录单Hello world", FontFactory.getFont(FontFactory.COURIER, 20, iTextSharp.text.Font.ITALIC, new iTextSharp.text.Color(255, 0, 0))); // doc.Add(chunk); } }
/// <summary> /// Converts the specified simple text. /// </summary> /// <param name="simpleText">The simple text.</param> /// <returns></returns> public static iTextSharp.text.Chunk Convert(AODL.Document.Content.Text.SimpleText simpleText, iTextSharp.text.Font font) { try { return new iTextSharp.text.Chunk(simpleText.Text, font); } catch(Exception) { throw; } }
public void FillEvent(string statementDate, int pageNumber, string title, iTextSharp.text.Image imgLogo) { if (statementDate != null && statementDate.Length > 0) { _statementDate = statementDate; } else { _statementDate = ""; } _pageNumber = pageNumber; _title = title; _imgLogo = imgLogo; }
/// <summary> /// Sets VisibleSignature's info. /// It can be null. /// </summary> /// <param name="text">Sets the signature text identifying the signer.</param> /// <param name="useLastPageToShowSignature">If it sets to true, value of the Page property will be ignored.</param> /// <param name="position">Position and dimension of the field in the page.</param> /// <param name="runDirection">Possible run direction values, left-to-right or right-to-left</param> /// <param name="pageNumberToShowSignature">The page to place the field. The fist page is 1.</param> /// <param name="imagePath">Signature's image. It can be null.</param> public void VisibleSignature(string text, bool useLastPageToShowSignature, iTextSharp.text.Rectangle position, PdfRunDirection runDirection, int pageNumberToShowSignature = 1, string imagePath = null) { _digitalSignature.VisibleSignature = new VisibleSignature { CustomText = text, UseLastPageToShowSignature = useLastPageToShowSignature, Position = position, RunDirection = runDirection, Font = _pdfReport.DataBuilder.PdfFont, ImagePath = imagePath, PageNumberToShowSignature = pageNumberToShowSignature }; }
public void FillEvent(string shid, string busName, string addr1, string addr2, string csz, decimal checkAmount, int pageNumber, string title, iTextSharp.text.Image imgLogo) { _shid = shid; _businessName = busName; _memAddr1 = addr1; _memAddr2 = addr2; _memCSZ = csz; _checkAmount = checkAmount; _pageNumber = pageNumber; _title = title; _imgLogo = imgLogo; }
public override void DrawItem(iTextSharp.text.pdf.PdfWriter pdfWriter, ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter) { base.DrawItem(pdfWriter, converter); iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance(image,null,false); iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); im.ScaleAbsolute (r.Width,r.Height); im.SetAbsolutePosition(r.Left,r.Top - r.Height); PdfContentByte cb = base.PdfWriter.DirectContent; cb.AddImage(im); }
public Conv() { IsDrag = new ReactiveProperty <bool>(true).AddTo(Disposable); IsConvertingShare = new ReactiveProperty <bool>(true).AddTo(Disposable); ButtonStart = new AsyncReactiveCommand().AddTo(Disposable); ButtonStart = IsConvertingShare.ToAsyncReactiveCommand(); ButtonStart.Subscribe(async _ => { await Task.Run(() => { using (var Pdf = new iTextSharp()) { Pdf.Output = SaveFile(Path.GetFileName(LastInput), Path.GetDirectoryName(LastInput)); if (Pdf.Output == string.Empty) { return; } Pdf.Open(); foreach (var dp in DataPieces.OrderBy(x => x.page.Value)) { switch (dp.fork) { case DataPiece.Fork.Bitmap: Pdf.AddToPdf(dp.path); break; case DataPiece.Fork.Zip: Pdf.AddToPdf(dp.byteData); break; } } } }); MessageBox.Show("完了"); }); ButtonRemoveAll = new AsyncReactiveCommand().AddTo(Disposable); ButtonRemoveAll = IsConvertingShare.ToAsyncReactiveCommand(); ButtonRemoveAll.Subscribe(async _ => { DataPieces.Clear(); }); }
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte, BaseLine line, IBaseStyleDecorator style, Point from,Point to) { if (contentByte == null) { throw new ArgumentNullException("contentByte"); } BaseShape.SetupShape(contentByte,style); contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point); contentByte.MoveTo(from.X,from.Y ); contentByte.LineTo(to.X,to.Y); BaseShape.FinishShape(contentByte); }
public void FillEvent(DateTime reportDate, int shid, string taxID, string busName, string adrLine1, string adrLine2, string csz, int pageNumber, string title, iTextSharp.text.Image imgLogo) { _reportDate = reportDate; _shid = shid; _busName = busName; _adrLine1 = adrLine1; _adrLine2 = adrLine2; _csz = csz; _pageNumber = pageNumber; _title = title; _imgLogo = imgLogo; }
/// <summary> /// Converts the tabs. /// </summary> /// <param name="tabStop">The tab stop.</param> /// <returns>Chunkck containing whitespace for a tab.</returns> public static iTextSharp.text.Phrase ConvertTabs(AODL.Document.Content.Text.TextControl.TabStop tabStop, iTextSharp.text.Font font) { try { // Only a trick since PDF doesn't support tab stops as know from other // formats, so we only use whitespace character for the beginning // TODO: do it better iTextSharp.text.Phrase phrase = new iTextSharp.text.Phrase(" ", font); return phrase; } catch(Exception) { throw; } }
private bool addImage(string sFilename, iTextSharp.text.Document doc) { bool bReturn = false; iTextSharp.text.Image img; try { Paragraph p1 = new Paragraph(new Chunk(sFilename, FontFactory.GetFont(FontFactory.HELVETICA, 12))); doc.Add(p1); #if !TEST Bitmap myBitmap = new Bitmap(sFilename); if (sFilename.ToLower().EndsWith("jpg")) img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Jpeg); else if (sFilename.ToLower().EndsWith("gif")) img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Gif); else if (sFilename.ToLower().EndsWith("bmp")) img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Bmp); else if (sFilename.ToLower().EndsWith("png")) img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Png); else throw new NotSupportedException("Unsupported image format"); //is the image to wide or to high? float fWidth=doc.Right - doc.Left - doc.RightMargin - doc.LeftMargin; float fHeight=doc.Top - doc.Bottom - doc.TopMargin - doc.BottomMargin; if ((myBitmap.Width > fWidth) || (myBitmap.Height>fHeight)) img.ScaleToFit(fWidth, fHeight); #else img = iTextSharp.text.Image.GetInstance(sFilename); #endif doc.Add(img); doc.NewPage(); //used to create a new page for every image bReturn = true; } catch (iTextSharp.text.BadElementException bx) { System.Diagnostics.Debug.WriteLine("BadElementException in doc.add() for '" + sFilename + "': " + bx.Message); } catch (iTextSharp.text.DocumentException dx) { System.Diagnostics.Debug.WriteLine("DocumentException in doc.add() for '" + sFilename + "': " + dx.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception in doc.add() for '" + sFilename + "': " + ex.Message); } return bReturn; }
private static PdfPTable TableOfHeader(Document document, iTextSharp.text.Image imageOfHeader, Phrase textOfHeader) { PdfPTable table = new PdfPTable(2); PdfPCell cellOfImage = new PdfPCell(imageOfHeader); PdfPCell cellOfText = new PdfPCell(textOfHeader); cellOfImage.HorizontalAlignment = Element.ALIGN_LEFT; cellOfImage.Border = 0; cellOfText.HorizontalAlignment = Element.ALIGN_RIGHT; cellOfText.Border = 0; table.AddCell(cellOfImage); table.AddCell(cellOfText); table.TotalWidth = document.PageSize.Width - 80; return table; }
public void FillEvent(SqlDataReader dr, string statementDate, int pageNumber, string title, iTextSharp.text.Image imgLogo) { if (statementDate != null && statementDate.Length > 0) { _statementDate = statementDate; } else { _statementDate = ""; } _groName = dr.GetString(dr.GetOrdinal("GrowerName")); _groAdr1 = dr.GetString(dr.GetOrdinal("GroAdr1")); _groAdr2 = dr.GetString(dr.GetOrdinal("GroAdr2")); _groCSZ = dr.GetString(dr.GetOrdinal("GroCSZ")); _pageNumber = pageNumber; _title = title; _imgLogo = imgLogo; }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document) { base.OnEndPage(writer, document); if (writer.PageNumber > 1) { float leftMargin = 64f; cb.BeginText(); cb.SetFontAndSize(arial, 10f); cb.SetColorFill(gray); cb.SetTextMatrix(document.PageSize.GetLeft(leftMargin), document.PageSize.GetBottom(25f)); cb.ShowText("© " + DateTime.Today.Year.ToString() + " IDC"); cb.SetTextMatrix(document.PageSize.GetRight(50f), document.PageSize.GetBottom(25f)); cb.ShowText(writer.PageNumber.ToString()); cb.EndText(); } }
public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try { table.SetWidths(new int[] { 24, 24, 2 }); table.TotalWidth = 527; table.LockedWidth = true; table.DefaultCell.FixedHeight = 20; table.DefaultCell.Border = Rectangle.BOTTOM_BORDER; table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; table.AddCell(string.Format("{0}", writer.PageNumber)); table.WriteSelectedRows(0, -1, 34, 803, writer.DirectContent); } catch (DocumentException de) { throw de; } }
/// <summary> /// Converts the white spaces. /// </summary> /// <param name="whiteSpace">The white space.</param> /// <returns>Chunck containing the whitspaces.</returns> public static iTextSharp.text.Phrase ConvertWhiteSpaces(AODL.Document.Content.Text.TextControl.WhiteSpace whiteSpace, iTextSharp.text.Font font) { try { string simulatedWhitespaces = ""; if (whiteSpace.Count != null) { for(int i=0; i < Int32.Parse(whiteSpace.Count); i++) { simulatedWhitespaces += " "; } } return new iTextSharp.text.Phrase(simulatedWhitespaces, font); } catch(Exception) { throw; } }
/// <summary> /// This method create a cell in the pdf file /// </summary> /// <param name="image"></param> /// <returns></returns> public PdfPCell CreateCell(iTextSharp.text.Image image) { cell = new PdfPCell(image); cell.PaddingTop = 10; cell.PaddingRight = 0; cell.PaddingBottom = 10; cell.PaddingLeft = 15; cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cell.Border = 0; return cell; }
public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo) { string curFont = renderInfo.GetFont().PostscriptFontName; //Check if faux bold is used if ((renderInfo.GetTextRenderMode() == (int)TextRenderMode.FillThenStrokeText)) { curFont += "-Bold"; } //This code assumes that if the baseline changes then we're on a newline Vector curBaseline = renderInfo.GetBaseline().GetStartPoint(); Vector topRight = renderInfo.GetAscentLine().GetEndPoint(); iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]); Single curFontSize = rect.Height; //See if something has changed, either the baseline, the font or the font size if ((this.lastBaseLine == null) || (curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) || (curFontSize != lastFontSize) || (curFont != lastFont)) { //if we've put down at least one span tag close it if ((this.lastBaseLine != null)) { this.result.AppendLine("</span>"); } //If the baseline has changed then insert a line break if ((this.lastBaseLine != null) && curBaseline[Vector.I2] != lastBaseLine[Vector.I2]) { this.result.AppendLine("<br />"); } //Create an HTML tag with appropriate styles this.result.AppendFormat("<span style=\"font-family:{0};font-size:{1}\">", curFont, curFontSize); } //Append the current text this.result.Append(renderInfo.GetText()); //Set currently used properties this.lastBaseLine = curBaseline; this.lastFontSize = curFontSize; this.lastFont = curFont; }
public override IList<iTextSharp.text.IElement> Content(iTextSharp.tool.xml.IWorkerContext ctx, iTextSharp.tool.xml.Tag tag, string content) { switch (tag.Name) { case "html": if (tag.Attributes.ContainsKey("lang") && !string.IsNullOrEmpty(tag.Attributes["lang"])) { this.document.AddLanguage(tag.Attributes["lang"]); } else { throw new Exception("document language is missing."); } break; case "title": if (!string.IsNullOrEmpty(content)) { this.document.AddTitle(content); } else { throw new Exception("document title is missing." + content); } break; default: break; } //string language = tag.Attributes["lang"]; //this.document.AddLanguage(language); return base.Content(ctx, tag, content); }
public void FillEvent(iTextSharp.text.Image imgLogo, string statementDate, string ldoBusinessName, string ldoAddressLine1, string ldoAddressLine2, string ldoCityStateZip) { _imgLogo = imgLogo; _statementDate = statementDate; _ldoBusinessName = ldoBusinessName; _ldoAddressLine1 = ldoAddressLine1; _ldoAddressLine2 = ldoAddressLine2; _ldoCityStateZip = ldoCityStateZip; }
public override void OnStartPage(PdfWriter writer, iTextSharp.text.Document document) { iTextSharp.text.Image header = iTextSharp.text.Image.GetInstance(PathResolver.MapPath("images/ADB_Logo.gif")); PdfPTable tableHeader = new PdfPTable(2); tableHeader.WidthPercentage = 100; PdfPCell imageHeaderCell = new PdfPCell(header); imageHeaderCell.Rowspan = 2; imageHeaderCell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right imageHeaderCell.Border = 0; imageHeaderCell.PaddingBottom = 3; tableHeader.AddCell(imageHeaderCell); Font helvetica20 = FontFactory.GetFont(FontFactory.HELVETICA, 16); PdfPCell typeNameCell = new PdfPCell(new Phrase(TypesReader.GetDiagramName(this.type), helvetica20)); typeNameCell.HorizontalAlignment = 2; typeNameCell.Border = 0; tableHeader.AddCell(typeNameCell); PdfPCell adbCell = new PdfPCell(new Phrase(GlobalStringResource.ADB, helvetica20)); adbCell.HorizontalAlignment = 2; adbCell.Border = 0; tableHeader.AddCell(adbCell); PdfPCell lineCell = new PdfPCell(); lineCell.Colspan = 2; lineCell.Border = 1; lineCell.PaddingBottom = 5; tableHeader.AddCell(lineCell); document.Add(tableHeader); }