/// <summary> /// 利用itextsharp生成文字签名 /// </summary> public void ConvertPdf2() { string sourcePath = $"C:\\test\\source.pdf"; string targetPath = $"E:\\test\\target.pdf"; string fontPath = $"C:\\Windows\\Fonts\\simkai.ttf"; //读原始PDF using (iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sourcePath)) { //定义流 using (iTextSharp.text.pdf.PdfStamper stream = new iTextSharp.text.pdf.PdfStamper(reader, new FileStream(targetPath, FileMode.Create, FileAccess.Write, FileShare.None))) { //加载字体 iTextSharp.text.Font font = new iTextSharp.text.Font(iTextSharp.text.pdf.BaseFont.CreateFont(fontPath, iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED), 12); //获取顶层图层 iTextSharp.text.pdf.PdfContentByte canvas = stream.GetOverContent(1); iTextSharp.text.pdf.ColumnText.ShowTextAligned(canvas, iTextSharp.text.Element.ALIGN_LEFT, new iTextSharp.text.Phrase("签名1", font), 3090, 93, 0); //left, bottom, rotation iTextSharp.text.pdf.ColumnText.ShowTextAligned(canvas, iTextSharp.text.Element.ALIGN_LEFT, new iTextSharp.text.Phrase("签名2", font), 3090, 73, 0); //left, bottom, rotation iTextSharp.text.pdf.ColumnText.ShowTextAligned(canvas, iTextSharp.text.Element.ALIGN_LEFT, new iTextSharp.text.Phrase("签名3", font), 3090, 53, 0); //left, bottom, rotation iTextSharp.text.pdf.ColumnText.ShowTextAligned(canvas, iTextSharp.text.Element.ALIGN_LEFT, new iTextSharp.text.Phrase("签名4", font), 3090, 33, 0); //left, bottom, rotation } } }
public static void SignPdfFile(string sourceDocument, string destinationPath, Stream privateKeyStream, string password, string reason, string location) { Pkcs12Store pk12 = new Pkcs12Store(privateKeyStream, password.ToCharArray()); privateKeyStream.Dispose(); string alias = null; foreach (string tAlias in pk12.Aliases) { if (pk12.IsKeyEntry(tAlias)) { alias = tAlias; break; } } var pk = pk12.GetKey(alias).Key; iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sourceDocument); using (FileStream fout = new FileStream(destinationPath, FileMode.Create, FileAccess.ReadWrite)) { using (iTextSharp.text.pdf.PdfStamper stamper = iTextSharp.text.pdf.PdfStamper.CreateSignature(reader, fout, '\0')) { iTextSharp.text.pdf.PdfSignatureAppearance appearance = stamper.SignatureAppearance; iTextSharp.text.pdf.BaseFont bf = iTextSharp.text.pdf.BaseFont.CreateFont(System.Web.HttpContext.Current.Server.MapPath("~/fonts/iconic/fonts/Material-Design-Iconic-Font.ttf"), iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 11); appearance.Layer2Font = font; //appearance.Image = new iTextSharp.text.pdf.PdfImage(); appearance.Reason = reason; appearance.Location = location; appearance.SetVisibleSignature(new iTextSharp.text.Rectangle(20, 10, 170, 60), 1, "Icsi-Vendor"); iTextSharp.text.pdf.security.IExternalSignature es = new iTextSharp.text.pdf.security.PrivateKeySignature(pk, "SHA-256"); iTextSharp.text.pdf.security.MakeSignature.SignDetached(appearance, es, new X509Certificate[] { pk12.GetCertificate(alias).Certificate }, null, null, null, 0, iTextSharp.text.pdf.security.CryptoStandard.CMS); stamper.Close(); } } }
public FontStyle(Models.Typography.FontStyle bFontStyle) { _styleFont = iTextSharp.text.FontFactory.GetFont(bFontStyle.Path, bFontStyle.Font.Encoding, bFontStyle.Font.IsEmbedded, bFontStyle.Font.DefaultFontSize.Points); _key = bFontStyle.Font.Key + "_" + bFontStyle.Key; }
private void AddTexto(iTextSharp.text.Phrase phrase, string texto, int fontType, int fontSize) { iTextSharp.text.Font textFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, (float)fontSize, fontType, iTextSharp.text.BaseColor.BLACK); phrase.Add(new iTextSharp.text.Chunk(texto, textFont)); phrase.Add(new iTextSharp.text.Chunk(Environment.NewLine, textFont)); }
/// <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); }
/// <summary> /// create log table /// </summary> /// <param name="pdfDocument"></param> /// <param name="pdfFont"></param> /// <param name="tables"></param> private static void CreateLogTable(iTextSharp.text.Document pdfDocument, iTextSharp.text.Font pdfFont, List <TableDto> tables) { // TODO 创建表格 iTextSharp.text.pdf.PdfPTable pdfTable = new iTextSharp.text.pdf.PdfPTable(5); // TODO 添加列标题 pdfTable.AddCell(CreatePdfPCell("版本号", pdfFont)); pdfTable.AddCell(CreatePdfPCell("修订日期", pdfFont)); pdfTable.AddCell(CreatePdfPCell("修订内容", pdfFont)); pdfTable.AddCell(CreatePdfPCell("修订人", pdfFont)); pdfTable.AddCell(CreatePdfPCell("审核人", pdfFont)); for (var i = 0; i < 16; i++) { // TODO 添加数据行,循环数据库表字段 pdfTable.AddCell(CreatePdfPCell("", pdfFont)); pdfTable.AddCell(CreatePdfPCell("", pdfFont)); pdfTable.AddCell(CreatePdfPCell("", pdfFont)); pdfTable.AddCell(CreatePdfPCell("", pdfFont)); pdfTable.AddCell(CreatePdfPCell("", pdfFont)); } // TODO 设置表格居中 pdfTable.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; pdfTable.TotalWidth = 540F; pdfTable.LockedWidth = true; pdfTable.SetWidths(new float[] { 80F, 100F, 200F, 80F, 80F }); // TODO 添加表格 pdfDocument.Add(pdfTable); }
/// <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) { try { 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); } catch (Exception ex) { throw; } }
private void Barcode_Generator(PictureBox picture) { try { BarcodeLib.Barcode barcode = new BarcodeLib.Barcode() { IncludeLabel = true, Alignment = AlignmentPositions.CENTER, Width = 300, Height = 100, RotateFlipType = RotateFlipType.RotateNoneFlipNone, BackColor = Color.White, ForeColor = Color.Black, }; BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\Arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 14); Image img = barcode.Encode(TYPE.CODE128B, id.ToString(), Color.Black, Color.White, picture.Width, picture.Height); picture.Image = img; } catch (Exception exp) { MessageBox.Show(exp.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Text转成PDF /// </summary> /// <param name="sourcePath">源路径</param> /// <param name="targetPath">目标路径</param> /// <param name="fontPath">系统字体路径</param> /// <returns></returns> public static bool TextConvert(string sourcePath, string targetPath, string fontPath = default(string)) { var path = fontPath != default(string) ? fontPath : FontPath; using (var objReader = new StreamReader(sourcePath, Encoding.Default)) { iTextSharp.text.Document textDocument = null; try { var baseFont = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); var font = new Font(baseFont); textDocument = new iTextSharp.text.Document(); PdfWriter.getInstance(textDocument, new FileStream(targetPath, FileMode.Create)); textDocument.Open(); var strRead = objReader.ReadToEnd(); textDocument.Add(new Paragraph(strRead == "" ? " " : strRead, font)); textDocument.Close(); } catch (Exception e) { Console.WriteLine(e.Message); throw; } finally { if (textDocument != null && textDocument.isOpen()) { textDocument.Close(); } } } return(true); }
public void printOrder(List <Product> productsCart) { var file = Path.GetTempFileName(); string filepath = Path.GetTempPath(); string strFilename = MainUtils.getCurrentTime("h_mm_ss") + ".pdf"; using (MemoryStream ms = new MemoryStream()) { iTextSharp.text.Document document = new iTextSharp.text.Document(getPageSize(), 20, 20, 15, 15); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.Combine(filepath, strFilename), FileMode.Create)); document.AddTitle("Document Title"); document.Open(); iTextSharp.text.pdf.BaseFont Vn_Helvetica = iTextSharp.text.pdf.BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", "Identity-H", iTextSharp.text.pdf.BaseFont.EMBEDDED); iTextSharp.text.Font titleFont = new iTextSharp.text.Font(Vn_Helvetica, 18, iTextSharp.text.Font.BOLD); iTextSharp.text.Font subTitleFont = new iTextSharp.text.Font(Vn_Helvetica, 14, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font boldTableFont = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.BOLD); iTextSharp.text.Font endingMessageFont = new iTextSharp.text.Font(Vn_Helvetica, 10, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font bodyFont = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.NORMAL); document.Add(new iTextSharp.text.Paragraph(Properties.Settings.Default.ShopName, titleFont)); var orderInfoTable = new PdfPTable(2); orderInfoTable.HorizontalAlignment = 0; orderInfoTable.SpacingBefore = 10; orderInfoTable.SpacingAfter = 10; orderInfoTable.DefaultCell.Border = 0; orderInfoTable.SetWidths(new int[] { 70, 150 }); //Id of Order orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã đơn hàng: ", boldTableFont)); orderInfoTable.AddCell(""); double totalPrice = 0; //Products for (int i = 0; i < productsCart.Count; i++) { int c = i + 1; orderInfoTable.AddCell(new iTextSharp.text.Phrase("Sản phẩm " + c + ": ", boldTableFont)); orderInfoTable.AddCell(new iTextSharp.text.Phrase(productsCart[i].getName(), bodyFont)); orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã sản phẩm " + c + ": ", boldTableFont)); orderInfoTable.AddCell(productsCart[i].getpID()); orderInfoTable.AddCell(new iTextSharp.text.Phrase("Số lượng " + c + ": ", boldTableFont)); orderInfoTable.AddCell(productsCart[i].getQuantity().ToString()); totalPrice += double.Parse(productsCart[i].getPrice()); } //Total price orderInfoTable.AddCell(new iTextSharp.text.Phrase("Tổng giá:", boldTableFont)); orderInfoTable.AddCell(Convert.ToDecimal(totalPrice).ToString("###,###,###.00") + " dong"); document.Add(orderInfoTable); document.Close(); } System.Diagnostics.Process.Start(filepath + strFilename); }
public void BuildBorderCell(PdfPTable pdfTable, string strText, iTextSharp.text.Font font) { PdfPCell cell = new PdfPCell(new Phrase(strText, font)); cell.Border = iTextSharp.text.Rectangle.TOP_BORDER; cell.PaddingTop = 5f; pdfTable.AddCell(cell); }
public iTextSharp.text.Font ToPDFFont() { iTextSharp.text.Font.FontFamily family = iTextSharp.text.Font.FontFamily.HELVETICA; Enum.TryParse <iTextSharp.text.Font.FontFamily>(FontFamily, out family); iTextSharp.text.Font content = new iTextSharp.text.Font(family, (float)FontSize, iTextSharp.text.Font.GetStyleValue(Style), Color.ToPDFColor()); return(content); }
private FontInfo(string name, float size, FontStyle style, iTextSharp.text.Font iFont) { this.name = name; this.size = size; this.style = style; this.iFont = iFont; this.ascenderHeight = GetAscenderHeight(iFont); this.descenderHeight = GetDescenderHeight(iFont); this.baseHeight = GetBaseHeight(iFont); this.height = GetLineHeight(iFont); }
/// <summary> /// 创建pdf表格单元格 /// </summary> /// <param name="text"></param> /// <param name="pdfFont"></param> /// <returns></returns> private static iTextSharp.text.pdf.PdfPCell CreatePdfPCell(string text, iTextSharp.text.Font pdfFont) { iTextSharp.text.Phrase phrase = new iTextSharp.text.Phrase(text, pdfFont); iTextSharp.text.pdf.PdfPCell pdfPCell = new iTextSharp.text.pdf.PdfPCell(phrase); // TODO 单元格垂直居中显示 pdfPCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; pdfPCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; pdfPCell.MinimumHeight = 30; return(pdfPCell); }
/// <summary> /// 自己扩展--指定字体 /// </summary> /// <param name="content"></param> /// <param name="_Font"></param> public Cell(string content, iTextSharp.text.Font _Font) : base(0, 0, 0, 0) { // creates a Rectangle with BY DEFAULT a border of 0.5 this.Border = UNDEFINED; this.BorderWidth = 0.5F; // initializes the arraylist and adds an element arrayList = new ArrayList(); try { addElement(new Paragraph(content, _Font)); } catch (BadElementException bee) { bee.GetType(); } }
/// <summary> /// Converts the specified heading. /// </summary> /// <param name="heading">The heading.</param> /// <returns>A PDF paragraph representing the ODF heading</returns> public static iTextSharp.text.Paragraph Convert(Header heading) { try { iTextSharp.text.Font font = DefaultDocumentStyles.Instance().DefaultTextFont; IStyle style = heading.Document.CommonStyles.GetStyleByName(heading.StyleName); if (style != null && style is ParagraphStyle) { if ((ParagraphStyle)style != null) { if (((ParagraphStyle)style).ParentStyle != null) { IStyle parentStyle = heading.Document.CommonStyles.GetStyleByName( ((ParagraphStyle)style).ParentStyle); if (parentStyle != null && parentStyle is ParagraphStyle && ((ParagraphStyle)parentStyle).TextProperties != null && ((ParagraphStyle)style).TextProperties != null) { // get parent style first font = TextPropertyConverter.GetFont(((ParagraphStyle)parentStyle).TextProperties); // now use the orignal style as multiplier font = TextPropertyConverter.FontMultiplier(((ParagraphStyle)style).TextProperties, font); } else { font = TextPropertyConverter.GetFont(((ParagraphStyle)style).TextProperties); } } else { font = TextPropertyConverter.GetFont(((ParagraphStyle)style).TextProperties); } } } iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph("", font); // default ctor protected - why ?? paragraph.AddRange(FormatedTextConverter.GetTextContents(heading.TextContent, font)); return(paragraph); } catch (Exception ex) { throw; } }
private HttpResponseMessage GetPdfResponseForDictionary(Dictionary dictionary) { iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4); var memoryStream = new MemoryStream(); iTextSharp.text.pdf.PdfWriter.GetInstance(document, memoryStream); document.Open(); string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF"); iTextSharp.text.pdf.BaseFont baseFont = iTextSharp.text.pdf.BaseFont.CreateFont( ARIALUNI_TFF, iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 14, iTextSharp.text.Font.NORMAL); uint rowNumber = 1; foreach (var phrasesPair in dictionary.PhrasesPairs.OrderBy(p => p.FirstPhrase.Text)) { document.Add(new iTextSharp.text.Paragraph( string.Format("{0}) {1} - {2}", rowNumber++, phrasesPair.FirstPhrase.Text, phrasesPair.SecondPhrase.Text), font)); } document.NewPage(); rowNumber = 1; foreach (var phrasesPair in dictionary.PhrasesPairs.OrderBy(p => p.SecondPhrase.Text)) { document.Add(new iTextSharp.text.Paragraph( string.Format("{0}) {1} - {2}", rowNumber++, phrasesPair.SecondPhrase.Text, phrasesPair.FirstPhrase.Text), font)); } document.AddAuthor(dictionary.OwnerId); document.Close(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new ByteArrayContent(memoryStream.ToArray()); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); string filename = string.Format("{0}.pdf", dictionary.Name); response.Content.Headers.ContentDisposition.FileName = Uri.EscapeUriString(filename); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return(response); }
private void FillForm(User user) { string pdfTemplate = @"fill3.pdf"; var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Certificate"); Directory.CreateDirectory(path); string newFile = Path.Combine(path, user.Email + ".pdf"); var pdfReader = new PdfReader(pdfTemplate); var pdfStamper = new PdfStamper(pdfReader, new FileStream( newFile, FileMode.Create)); var pdfFormFields = pdfStamper.AcroFields; var fontpath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"fonts\TypographerRotunda.ttf"); var fontCustom = BaseFont.CreateFont(fontpath, BaseFont.CP1252, BaseFont.EMBEDDED); var font = new iTextSharp.text.Font(fontCustom, 12f); // pdfFormFields.SetFieldProperty("name", "textsize", 16f, null); // var s = FontFactory.GetFont(FontFactory.COURIER_BOLD, 2f, iTextSharp.text.Font.BOLD); //pdfFormFields.AddSubstitutionFont(s.BaseFont); pdfFormFields.SetFieldProperty("name", "textfont", font.BaseFont, null); pdfFormFields.SetField("name", user.FullName.ToUpper()); pdfFormFields.SetField("serialNo", user.Id.ToString("00000")); pdfStamper.FormFlattening = true; // close the pdf pdfStamper.Close(); //throw new NotImplementedException(); }
public static byte[] CreatePdfDefinitionFromAssignment(SqlConnection conn, SqlTransaction trans, Assignment a, TreeView t, string title) { byte[] pdfData = null; PdfDocument document = null; MemoryStream ms = null; try { ms = new MemoryStream(); document = new PdfDocument(); PdfWriter writer = PdfWriter.GetInstance(document, ms); document.Open(); PdfImage labLogo = GetLaboratoryLogo(conn, trans, a.LaboratoryId); if (labLogo != null) { CropImageToHeight(labLogo, 64f); labLogo.SetAbsolutePosition(document.GetRight(10f) - labLogo.PlainWidth, document.GetTop(10f) - 40f); document.Add(labLogo); } PdfFont fontTimes10 = new PdfFont(baseFontTimes, 10f); PdfFont fontTimes12 = new PdfFont(baseFontTimes, 12f); PdfFont fontTimesBold12 = new PdfFont(baseFontTimesBold, 12f); PdfFont fontTimesBold20 = new PdfFont(baseFontTimesBold, 20f); PdfFont fontTimesItalic8 = new PdfFont(baseFontTimesItalic, 8f); PdfFont fontTimesItalic10 = new PdfFont(baseFontTimesItalic, 10f); PdfFont fontCourier10 = new PdfFont(baseFontCourier, 10f); PdfFont fontCourierBold10 = new PdfFont(baseFontCourierBold, 10f); PdfParagraph p = new PdfParagraph(); p.SetLeading(16f, 0f); AddTextToParagraph(p, title, fontTimesBold20); AddTextToParagraph(p, "Oversikt generert: " + DateTime.Now.ToString(Utils.DateTimeFormatNorwegian), fontTimes10); AddTextToParagraph(p, "", fontTimes10); AddTextToParagraph(p, "Ordre: " + a.Name, fontTimes12); AddTextToParagraph(p, "Beskrivelse: " + a.Description, fontTimes12); AddTextToParagraph(p, "Laboratorium: " + a.LaboratoryName(conn, trans), fontTimes12); AddTextToParagraph(p, "Ansvarlig: " + a.ResponsibleName(conn, trans), fontTimes12); AddTextToParagraph(p, "Oppdragsgiver: " + a.CustomerContactName, fontTimes12); AddTextToParagraph(p, "Tidsfrist: " + a.Deadline.Value.ToString(Utils.DateFormatNorwegian), fontTimes12); if (a.RequestedSigmaAct == 0) { AddTextToParagraph(p, "Ønsket sigma aktivitet: ", fontTimes12); } else { AddTextToParagraph(p, "Ønsket sigma aktivitet: " + a.RequestedSigmaAct, fontTimes12); } if (a.RequestedSigmaMDA == 0) { AddTextToParagraph(p, "Ønsket sigma usikkerhet: ", fontTimes12); } else { AddTextToParagraph(p, "Ønsket sigma usikkerhet: " + a.RequestedSigmaMDA, fontTimes12); } AddTextToParagraph(p, "", fontTimes10); document.Add(p); if (!String.IsNullOrEmpty(a.ContentComment)) { p = new PdfParagraph(); p.SetLeading(10f, 0f); AddTextToParagraph(p, "Kommentar:", fontTimesBold12); AddTextToParagraph(p, "", fontTimes10); string[] lines = a.ContentComment.Split(new char[] { '\n' }); foreach (string line in lines) { AddTextToParagraph(p, line, fontTimesItalic10); } AddTextToParagraph(p, "", fontTimesItalic10); document.Add(p); } p = new PdfParagraph(); p.SetLeading(14f, 0f); AddTextToParagraph(p, "Ordre enheter:", fontTimesBold12); AddTextToParagraph(p, "", fontTimes10); foreach (TreeNode n in t.Nodes) { AddTextToParagraph(p, n.Text, fontCourierBold10); foreach (TreeNode n2 in n.Nodes) { AddTextToParagraph(p, " " + n2.Text, fontCourier10); foreach (TreeNode n3 in n2.Nodes) { AddTextToParagraph(p, " " + n3.Text, fontCourier10); } } } document.Add(p); p = new PdfParagraph(); AddTextToParagraph(p, "", fontTimes10); AddTextToParagraph(p, "Merknad: Analysemetoder merket med A har en prøvetype, prepararingsmetode og analysemetode som kan resultere i akkrediterte resultater", fontTimesItalic8); document.Add(p); } finally { document?.Close(); if (ms != null) { pdfData = ms.GetBuffer(); } } return(pdfData); }
public void MergePdf(string[] pdfFiles, string outputPath) { int pdfCount = 0; int f = 0; string filename = String.Empty; iTextSharp.text.pdf.PdfReader reader = null; int pageCount = 0; iTextSharp.text.Document pdfDoc = null; iTextSharp.text.pdf.PdfWriter writer = null; iTextSharp.text.pdf.PdfContentByte cb = null; iTextSharp.text.pdf.PdfImportedPage page = null; int rotation = 0; iTextSharp.text.Font bookmarkFont = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 4, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.RED); try { pdfCount = pdfFiles.Length; if (pdfCount > 1) { filename = pdfFiles[f]; reader = new iTextSharp.text.pdf.PdfReader(filename); pageCount = reader.NumberOfPages; pdfDoc = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18); writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, new System.IO.FileStream(outputPath, System.IO.FileMode.Create)); pdfDoc.AddAuthor("OPGK w Lublinie sp. z o. o. Sławomir Aleksak"); pdfDoc.AddCreator("Konwerter"); pdfDoc.Open(); cb = writer.DirectContent; while (f < pdfCount) { var i = 0; while (i < pageCount) { i += 1; pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i)); pdfDoc.NewPage(); if (i == 1) { iTextSharp.text.Paragraph para = new iTextSharp.text.Paragraph(System.IO.Path.GetFileName(filename).ToUpper(), bookmarkFont); iTextSharp.text.Chapter chpter = new iTextSharp.text.Chapter(para, f + 1); pdfDoc.Add(chpter); } page = writer.GetImportedPage(reader, i); rotation = reader.GetPageRotation(i); if (rotation == 90) { cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height); } if (rotation == 270) { cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30); } else { cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0); } } f += 1; if (f < pdfCount) { filename = pdfFiles[f]; reader = new iTextSharp.text.pdf.PdfReader(filename); pageCount = reader.NumberOfPages; } } pdfDoc.Close(); } } catch (Exception ex) { throw ex; } }
public void SaveDataGridViewToPDF(DataGridView Dv, string FilePath) { string folderPath = Environment.CurrentDirectory + "\\Relatório\\"; //"C:\\PDFs\\"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } iTextSharp.text.FontFactory.RegisterDirectories(); iTextSharp.text.Font myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 15, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10f, 10f, 10f, 0f); pdfDoc.Open(); PdfWriter wri = PdfWriter.GetInstance(pdfDoc, new FileStream(FilePath + "Extrato da conta.pdf", FileMode.Create)); pdfDoc.Open(); PdfPTable _mytable = new PdfPTable(Dv.ColumnCount - 4); float[] widths = new float[] { 2.1f, 5f, 1.5f, 1.6f, 1.5f }; _mytable.SetWidths(widths); _mytable.WidthPercentage = 90; //_mytable.DefaultCell.Border = Rectangle.NO_BORDER; _mytable.DefaultCell.BorderColor = new iTextSharp.text.BaseColor(System.Drawing.Color.White); iTextSharp.text.Paragraph ph = new iTextSharp.text.Paragraph("Extrato da conta ", myfont); ph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; pdfDoc.Add(ph); myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); ph = new iTextSharp.text.Paragraph("Conta: " + cmbContas.Text, myfont); ph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; pdfDoc.Add(ph); // adiciona a linha em branco(enter) ao paragrafo ph.Add(new iTextSharp.text.Chunk("\n")); ph = new iTextSharp.text.Paragraph("Período: " + dtDataIni.Text + " até " + dtDataFinal.Text, myfont); pdfDoc.Add(ph); ph = new iTextSharp.text.Paragraph("Dada de emissão: " + DateTime.Now, myfont); pdfDoc.Add(ph); ph = new iTextSharp.text.Paragraph(); // cria um objeto sepatador (um traço) iTextSharp.text.pdf.draw.VerticalPositionMark seperator = new iTextSharp.text.pdf.draw.LineSeparator(); // adiciona o separador ao paragravo ph.Add(seperator); // adiciona a linha em branco(enter) ao paragrafo ph.Add(new iTextSharp.text.Chunk("\n")); // imprime o pagagrafo no documento // pdfDoc.Add(ph); ph.Add(new iTextSharp.text.Chunk("\n")); pdfDoc.Add(ph); myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK); for (int j = 0; j < Dv.Columns.Count; ++j) { if (Dv.Columns[j].HeaderText != "codigo" && Dv.Columns[j].HeaderText != "tipo" && Dv.Columns[j].HeaderText != "codigo_conta" && Dv.Columns[j].HeaderText != "valor") { iTextSharp.text.Phrase p = new iTextSharp.text.Phrase(Dv.Columns[j].HeaderText, myfont); PdfPCell cell = new PdfPCell(p); cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL; cell.BorderWidth = 0; _mytable.AddCell(cell); } } myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); //------------------------- for (int i = 0; i < Dv.Rows.Count; ++i) { for (int j = 0; j < Dv.Columns.Count; ++j) { if (Dv.Columns[j].HeaderText != "codigo" && Dv.Columns[j].HeaderText != "tipo" && Dv.Columns[j].HeaderText != "codigo_conta" && Dv.Columns[j].HeaderText != "valor") { iTextSharp.text.Phrase p = new iTextSharp.text.Phrase();// Dv.Rows[i].Cells[j].Value == null ? null : Dv.Rows[i].Cells[j].Value.ToString(), myfont); PdfPCell cell = new PdfPCell(); if (Dv.Columns[j].HeaderText == "Saldo" || Dv.Columns[j].HeaderText == "Saída/ Débito" || Dv.Columns[j].HeaderText == "Entrada/Crédito") { myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); if (Dv.Columns[j].HeaderText == "Saída/ Débito") { myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.RED); } else if (Dv.Columns[j].HeaderText == "Entrada/Crédito") { myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE); } else if (Dv.Columns[j].HeaderText == "Saldo") { var saldo = Dv.Rows[i].Cells[j].Value == null ? 0 : Convert.ToDouble(Dv.Rows[i].Cells[j].Value); if (saldo < 0 && i == Dv.Rows.Count - 1) { myfont = iTextSharp.text.FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 9, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.RED); } } p = new iTextSharp.text.Phrase(Dv.Rows[i].Cells[j].Value == null ? null : Convert.ToDecimal(Dv.Rows[i].Cells[j].Value.ToString()).ToString("N2"), myfont); cell = new PdfPCell(p); cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT; if (i == 0 || i == Dv.Rows.Count - 1) { cell.BackgroundColor = new iTextSharp.text.BaseColor(System.Drawing.Color.Silver); } } else if (Dv.Columns[j].HeaderText == "Data de lançamento" && Dv.Rows[i].Cells[j + 1].Value.ToString() == "SALDO ANTERIOR" || Dv.Rows[i].Cells[j + 1].Value.ToString() == "SALDO ATUAL CONTA") { p = new iTextSharp.text.Phrase(Dv.Rows[i].Cells[j].Value == null ? null : Convert.ToDateTime(Dv.Rows[i].Cells[j].Value.ToString()).ToString("dd/MM/yyyy"), myfont); cell = new PdfPCell(p); cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; if (i == 0 || i == Dv.Rows.Count - 1) { cell.BackgroundColor = new iTextSharp.text.BaseColor(System.Drawing.Color.Silver); } } else { p = new iTextSharp.text.Phrase(Dv.Rows[i].Cells[j].Value == null ? null : Dv.Rows[i].Cells[j].Value.ToString(), myfont); cell = new PdfPCell(p); cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; if (i == 0 || i == Dv.Rows.Count - 1) { cell.BackgroundColor = new iTextSharp.text.BaseColor(System.Drawing.Color.Silver); } } cell.BorderWidth = 0; // _mytable.DefaultCell.BorderWidth = 0; cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL; _mytable.AddCell(cell); } } } //------------------------ pdfDoc.Add(_mytable); pdfDoc.Close(); System.Diagnostics.Process.Start(FilePath); }
// Background worker public void PDFBackgroundWorker_DoWork_TextPDF(object sender, DoWorkEventArgs e) { int i = 0; int ii = 1; exportFilePath = string.Empty; if (JobType == PDFJobType.TextPDF) { exportFilePath = directoryName + "\\" + FileNoExt + ".pdf"; while (System.IO.File.Exists(exportFilePath)) { exportFilePath = directoryName + "\\" + FileNoExt + "_" + ii + ".pdf"; ii++; } using (FileStream fs = new FileStream(exportFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) { iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.B4); // iTextSharp.text. Document doc = new Document(PageSize.A2); // doc.SetMargins(100, 200, 0, 0); //Document doc = new Document(PageSize.A5, 36, 72, 108, 180); //Document doc = new Document(PageSize.A3.Rotate(),400,0,0,0); //var doc = new Document(new iTextSharp.text.Rectangle(100f, 300f)); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, fs); iTextSharp.text.pdf.BaseFont bfTimes = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.TIMES_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, false); // doc.SetPageSize(PageSize.A1); // doc.SetMargins(76, 0, 0, 0); doc.SetMarginMirroring(false); iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 14, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.CYAN); if (PDFBackgroundWorker.CancellationPending) { e.Cancel = true; PDFBackgroundWorker.ReportProgress(i); return; } using (StreamReader read = new StreamReader(InputFilename)) { string text = read.ReadToEnd(); // AddDocMetaData(); doc.AddTitle(GameTitle); doc.AddSubject(""); doc.AddKeywords(GameTitle + ", " + FileNoExt + " : by Hypermint, "); doc.AddCreator("HLM-Chk"); doc.AddAuthor(GameTitle); doc.AddHeader(FileNoExt, GameTitle); doc.Open(); iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); paragraph.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE; paragraph.Add(text); doc.Add(paragraph); //Paragraph paragraph = new Paragraph(text); doc.Close(); } } } }
/// <summary> /// Constructs a Paragraph with a certain leading, string /// and Font. /// /// </summary> /// <param name="leading">the leading</param><param name="str">a string</param><param name="font">a Font</param> public Paragraph(float leading, string str, iTextSharp.text.Font font);
/// <summary> /// Constructs a Paragraph with a certain string /// and a certain Font. /// /// </summary> /// <param name="str">a string</param><param name="font">a Font</param> public Paragraph(string str, iTextSharp.text.Font font);
// experimentell! public void createPdfFile(string filespec) { iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(0, 0, box.Width, box.Height)); dynamic writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new System.IO.FileStream(filespec, System.IO.FileMode.Create)); dynamic bf = iTextSharp.text.pdf.BaseFont.CreateFont(); doc.Open(); iTextSharp.text.pdf.PdfContentByte over = writer.DirectContent; for (i = 0; i <= p_objects.Count - 1; i++) { RECT r = p_objects[i].GetOuterBounds; if (p_objects[i] is VTextbox) { VTextbox src = p_objects[i]; //ColumnText can contain paraphraphs as well as be abolsutely positioned iTextSharp.text.pdf.ColumnText Col = new iTextSharp.text.pdf.ColumnText(over); //Set the x,y,width,height Col.SetSimpleColumn(r.Left, box.Height - r.Top, r.Right, box.Height - r.Bottom); //Create our paragraph iTextSharp.text.Paragraph P = new iTextSharp.text.Paragraph(); //Create our base font, assumes you have arial installed in the normal location and that CP1252 works with it //Dim BF = BaseFont.CreateFont(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows), "Fonts\arial.ttf"), BaseFont.CP1252, False) //Add two chunks that will be placed side-by-side but with different font weights //P.Add(New iTextSharp.text.Chunk("BOLD TEXT: ", New iTextSharp.text.Font(bf, 10.0, iTextSharp.text.Font.BOLD))) string fontFilespec = Helper.GetFontFilespec(src.Font.FontFamily.Name); iTextSharp.text.Font fnt = default(iTextSharp.text.Font); if (!string.IsNullOrEmpty(fontFilespec)) { fnt = new iTextSharp.text.Font(iTextSharp.text.pdf.BaseFont.CreateFont(fontFilespec, iTextSharp.text.pdf.BaseFont.CP1252, false), src.Font.SizeInPoints, iTextSharp.text.Font.NORMAL); } else { fnt = new iTextSharp.text.Font(bf, src.Font.SizeInPoints, iTextSharp.text.Font.NORMAL); } P.Add(new iTextSharp.text.Chunk(src.Text, fnt)); //Add the paragraph to the ColumnText Col.AddText(P); //Call to stupid Go() method which actually writes the content to the stream. Col.Go(); // //Dim txtbox As New iTextSharp.text.pdf.PdfPCell() //Dim f = New iTextSharp.text.Font(bf) //f.SetColor(0, 0, 0) //over.SetFontAndSize(bf, 10) //over.BeginText() //over.ShowTextAligned(1, src.Text, r.Left, box.Height - r.Bottom, 0) //over.EndText() } else { dynamic img = iTextSharp.text.Image.GetInstance(p_objects[i].GetAsImage, System.Drawing.Imaging.ImageFormat.Png); img.SetAbsolutePosition(r.Left, box.Height - r.Bottom); img.SetDpi(72, 72); //doc.Add(img) over.AddImage(img); } } doc.Close(); }
///******************************************************************************************************* /// <summary> /// Método que exporta la tabla de resultados en el grid a PDF /// </summary> /// <param name="Documento">Objeto al cúal agregaremos el contenido del reporte</param> /// <creo>Juan Alberto Hernández Negrete</creo> /// <fecha_creo>27-nov-2013</fecha_creo> /// <modifico></modifico> /// <fecha_modifico></fecha_modifico> /// <causa_modificacion></causa_modificacion> ///******************************************************************************************************* public void Exportar_Datos_PDF(iTextSharp.text.Document Documento) { bool Es_Footer = false; try { iTextSharp.text.Phrase _frase = null; iTextSharp.text.pdf.PdfPCell _celda = null; iTextSharp.text.FontFactory.RegisterDirectory(@"C:\Windows\Fonts"); //Creamos el objeto de tipo tabla para almacenar el resultado de la búsqueda. iTextSharp.text.pdf.PdfPTable Rpt_Tabla = new iTextSharp.text.pdf.PdfPTable(Grd_Resultado.Columns.Count); //Obtenemos y establecemos el formato de las columnas de la tabla. float[] Ancho_Cabeceras = Obtener_Tamano_Columnas(Grd_Resultado); //Creamos y definimos algunas propiedades que tendrá la fuente que se aplicara a las celdas de la tabla de resultados. iTextSharp.text.Font Fuente_Tabla_Contenido = iTextSharp.text.FontFactory.GetFont("Courier New", 7, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font Fuente_Tabla_Footer = iTextSharp.text.FontFactory.GetFont("Courier New", 9, iTextSharp.text.Font.BOLD); //Establecemos el formato que tendrá la tabla que mostrara el resultado de la búsqueda según el movimiento consultado. Rpt_Tabla.DefaultCell.Padding = 3; Rpt_Tabla.SetWidths(Ancho_Cabeceras); Rpt_Tabla.WidthPercentage = 100; Rpt_Tabla.DefaultCell.BorderWidth = 2; Rpt_Tabla.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; Rpt_Tabla.HeaderRows = 1; // Creamos y establecemos el formato que tendrá el titulo del reporte. iTextSharp.text.Paragraph Titulo = new iTextSharp.text.Paragraph(); Titulo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; Titulo.Font = iTextSharp.text.FontFactory.GetFont("Consolas"); Titulo.Font.SetStyle(iTextSharp.text.Font.BOLD); Titulo.Font.Size = 14; Titulo.Add("Museo de las Momias de Guanajuato"); // Creamos y establecemos el formato que tendrá el subtitulo del reporte. iTextSharp.text.Paragraph Subtitulo = new iTextSharp.text.Paragraph(); Subtitulo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; Subtitulo.Font = iTextSharp.text.FontFactory.GetFont("Consolas"); Subtitulo.Font.SetStyle(iTextSharp.text.Font.BOLD); Subtitulo.Font.Size = 12; Subtitulo.Add("Log de eventos en " + Cmb_Tabla.Text.ToString() + ": " + (Dtp_Fecha_Inicio.Checked.Equals(true) ? Dtp_Fecha_Inicio.Text : "") + " - " + (Dtp_Fecha_Termino.Checked.Equals(true) ? Dtp_Fecha_Termino.Text : "")); // rango de fechas del reporte // fecha actual iTextSharp.text.Phrase Fecha = new iTextSharp.text.Phrase(DateTime.Today.ToString("dd-MMM-yyyy")); Fecha.Font.Size = 11; float[] Anchura_Tabla_Subtitulo = { 90, 10 }; // subtitulo con fecha en una tabla sin bordes (misma línea) iTextSharp.text.pdf.PdfPTable Tabla_Subtitulo = new iTextSharp.text.pdf.PdfPTable(Anchura_Tabla_Subtitulo); Tabla_Subtitulo.WidthPercentage = 100; Tabla_Subtitulo.DefaultCell.Border = iTextSharp.text.pdf.PdfPCell.NO_BORDER; Tabla_Subtitulo.DefaultCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; Tabla_Subtitulo.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT; Tabla_Subtitulo.AddCell(Subtitulo); Tabla_Subtitulo.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; Tabla_Subtitulo.AddCell(Fecha); //Agregamos los nombres de las columnas de la tabla que se imprimira en el reporte. Array.ForEach(Grd_Resultado.Columns.OfType <DataGridViewColumn>().ToArray(), columna => { var cabecera = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase(columna.HeaderText, iTextSharp.text.FontFactory.GetFont("Consolas", 8, iTextSharp.text.Font.BOLD))); cabecera.BackgroundColor = iTextSharp.text.BaseColor.LIGHT_GRAY; cabecera.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; Rpt_Tabla.AddCell(cabecera); }); //Modificamos el tipo de border que tendrá las celdas que mostraran los datos, con respécto al borde que tiene asignado la cabeceras de las columnas. Rpt_Tabla.DefaultCell.BorderWidth = 1; //Agreamos el resultado de la búsqueda de movimientos al tabla que se enviara al reporte. Array.ForEach(Grd_Resultado.Rows.OfType <DataGridViewRow>().ToArray(), fila => { if (fila.Cells[0] != null) { if (fila.Cells[0].Value != null) { if (fila.Cells[0].Value.ToString().ToLower().Contains("totales")) { Es_Footer = true; } else { Es_Footer = false; } } else { Es_Footer = false; } } else { Es_Footer = false; } Array.ForEach(fila.Cells.OfType <DataGridViewCell>().ToArray(), celda => { string texto = string.Empty; if (celda.Value != null) { if (celda.ValueType.Name.Equals("DateTime")) { texto = string.Format("{0:dd MMM yyyy}", celda.Value); } else if (celda.ValueType.Name.Equals("Decimal") && !celda.OwningColumn.HeaderText.Equals("NoCaja")) { texto = string.Format("{0:n}", celda.Value); } else { texto = celda.Value.ToString(); } } if (Es_Footer) { //Establecemos el formato que llevaran las celdas de totales de la tabla del reporte. _frase = new iTextSharp.text.Phrase(texto, Fuente_Tabla_Footer); _celda = new iTextSharp.text.pdf.PdfPCell(_frase); _celda.BackgroundColor = iTextSharp.text.BaseColor.LIGHT_GRAY; } else { //Establecemos el formato que llevaran las celdas de contenido de la tabla del reporte. _frase = new iTextSharp.text.Phrase(texto, Fuente_Tabla_Contenido); _celda = new iTextSharp.text.pdf.PdfPCell(_frase); } if (texto.Contains("$")) { _celda.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; } else { _celda.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; } _celda.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; //Establecemos el valor de la celda. Rpt_Tabla.AddCell(_celda); }); //Indicamos que se completo de editar la fila y completamos la operación. Rpt_Tabla.CompleteRow(); }); // Se agrega el PDFTable al documento. Documento.Add(Titulo); Documento.Add(Tabla_Subtitulo); Documento.Add(new iTextSharp.text.Paragraph("\n")); Documento.Add(Rpt_Tabla); } catch (Exception Ex) { MessageBox.Show(this, Ex.Message, "Error - Método: [Exportar_Datos_PDF]", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CreateDocument() { iProgressChanged(0, "Catalog: Initialise", Progress.State.eInProgress); string fileName = Path.GetFullPath(iDocumentFilename); iTextSharp.text.Document document = null; bool pdf = true; if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked) { document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate()); // landscape } else { document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4); // portrait } try { float fontSizePreset = 10F; float fontSizePresetNumber = 10F; float fontSizeBookmark = 12F; float fontSizePresetLarge = 32F; float fontSizePresetNumberLarge = 48F; iTextSharp.text.Font fontPreset = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePreset, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontPresetNumber = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetNumber, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontBookmark = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizeBookmark, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLUE); iTextSharp.text.Font fontPresetLarge = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetLarge, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); iTextSharp.text.Font fontPresetNumberLarge = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, fontSizePresetNumberLarge, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK); if (Path.GetExtension(fileName) == ".rtf") { iTextSharp.text.rtf.RtfWriter2.GetInstance(document, new FileStream(fileName, FileMode.Create)); pdf = false; } else { iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create)); writer.ViewerPreferences = iTextSharp.text.pdf.PdfWriter.PageLayoutSinglePage; } document.Open(); if (pdf) { document.Add(new iTextSharp.text.Paragraph()); // pdf needs alignment on first page, rtf does not } // TOC bool firstPage = true; string text = ""; if (printSectionCheckedListBox.GetItemChecked(0)) { iProgressChanged(0, "Catalog: TOC", Progress.State.eInProgress); if (iTreeViewPreset.Nodes.Count > 0) { firstPage = false; foreach (TreeNode bookmark in iTreeViewPreset.Nodes) { if (bookmark.Index > 0) { document.Add(new iTextSharp.text.Chunk("\n")); } document.Add(new iTextSharp.text.Phrase(fontSizeBookmark + 2, bookmark.Text, fontBookmark)); document.Add(new iTextSharp.text.Paragraph()); if (bookmark.Nodes.Count > 0) { foreach (TreeNode preset in bookmark.Nodes) { document.Add(new iTextSharp.text.Chunk("0" + preset.Name, fontPresetNumber)); text = preset.Text.Replace("/", " / "); document.Add(new iTextSharp.text.Phrase(fontSizePreset + 2, " - " + text + " (" + preset.Nodes.Count + ")", fontPreset)); document.Add(new iTextSharp.text.Paragraph()); } } } } } // One page per preset (with album covers) if (iTreeViewPreset.Nodes.Count > 0) { int currItem = 0; int totalItems = 0; foreach (TreeNode bookmark in iTreeViewPreset.Nodes) { if (printSectionCheckedListBox.GetItemChecked(bookmark.Index + 1)) { totalItems += bookmark.Nodes.Count; // only add selected sections to total } } foreach (TreeNode bookmark in iTreeViewPreset.Nodes) { if (bookmark.Nodes.Count > 0 && iPresetCount > 0) { if (!printSectionCheckedListBox.GetItemChecked(bookmark.Index + 1)) { // only print selected sections continue; } foreach (TreeNode preset in bookmark.Nodes) { iProgressChanged((++currItem * 100 / totalItems), "Catalog: Page " + currItem + " of " + totalItems, Progress.State.eInProgress); if (!firstPage) { document.NewPage(); } firstPage = false; document.Add(new iTextSharp.text.Chunk("0" + preset.Name, fontPresetNumberLarge)); text = preset.Text.Replace("/", " / "); document.Add(new iTextSharp.text.Phrase(fontSizePresetLarge + 2, " " + text, fontPresetLarge)); document.Add(new iTextSharp.text.Paragraph()); document.Add(new iTextSharp.text.Chunk("\n")); foreach (TreeNode track in preset.Nodes) { TrackMetadata data = (TrackMetadata)track.Tag; if (track.Index == 0) { try { iTextSharp.text.Image albumArt = iTextSharp.text.Image.GetInstance(new Uri(data.AlbumArtPath)); if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked) { // landscape if (iPageLayoutTrackDetailsLandscape.Checked) { // include track details albumArt.Alignment = iTextSharp.text.Image.LEFT_ALIGN | iTextSharp.text.Image.TEXTWRAP; albumArt.IndentationRight = 36; albumArt.ScaleToFit(350, 350); // album art not lined up - use all available space for track details } else { // no track details if (pdf) { albumArt.ScaleToFit(400, 400); } else { albumArt.ScaleToFit(350, 350); // margins handled slightly differently } albumArt.SetAbsolutePosition(221, 32.5f); // all album art lined up in document } } else { // portrait if (iPageLayoutTrackDetailsPortrait.Checked) { // include track details albumArt.Alignment = iTextSharp.text.Image.LEFT_ALIGN; albumArt.ScaleToFit(350, 350); // album art not lined up - use all available space for track details } else { // no track details albumArt.ScaleToFit(525, 525); albumArt.SetAbsolutePosition(35, 108.5f); // all album art lined up in document } } document.Add(albumArt); document.Add(new iTextSharp.text.Chunk("\n")); } catch { // invalid or missing album art } } if (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutTrackDetailsPortrait.Checked) // include track details { string trackInfo = (track.Index + 1).ToString().PadLeft(2, '0'); trackInfo += ". " + data.Title; trackInfo += " - " + data.Artist; trackInfo += " - " + data.Album; trackInfo += " (" + data.Duration; trackInfo += ")"; document.Add(new iTextSharp.text.Phrase(fontSizePreset + 2, trackInfo, fontPreset)); document.Add(new iTextSharp.text.Paragraph()); } } } } } } iProgressChanged(100, "Catalog: Finalise", Progress.State.eInProgress); } catch (Exception exc) { string message = "Unable to create file: " + fileName + Environment.NewLine + exc.Message; if (exc.GetType() == typeof(ThreadAbortException)) { message = "Operation was cancelled by the user" + Environment.NewLine; } Linn.UserLog.WriteLine("Print Failed: " + message); iProgressChanged(0, message, Progress.State.eFail); iProgressChanged(100, null, Progress.State.eComplete); return; } finally { try { document.Close(); } catch (System.IO.IOException) { // document has no pages } } try { if (pdf && iDocumentPagesPerSheet >= kMultiplePagesMin && iDocumentPagesPerSheet <= kMultiplePagesMax) { string newName = Path.GetTempPath() + iHelper.Title + System.Guid.NewGuid().ToString() + "MultiplePagesPresets.pdf"; MultiplePages(iDocumentFilename, newName, iDocumentPagesPerSheet, (iPageLayoutTrackDetailsLandscape.Checked || iPageLayoutAlbumArtOnlyLandscape.Checked)); File.Delete(iDocumentFilename); // delete source file File.Copy(newName, iDocumentFilename); } } catch (Exception e) { if (e.GetType() == typeof(ThreadAbortException)) { string msg = "Operation was cancelled by the user" + Environment.NewLine; Linn.UserLog.WriteLine(msg); iProgressChanged(0, msg, Progress.State.eFail); return; } else { Linn.UserLog.WriteLine("Print (multiple pages) Failed: " + e.Message); } } finally { iProgressChanged(100, null, Progress.State.eComplete); } if (iDocumentPreview) { try { System.Diagnostics.Process.Start(iDocumentFilename); } catch (Exception exc) { string docType = "PDF"; if (!pdf) { docType = "RTF"; } Linn.UserLog.WriteLine("Unable to preview catalog (" + docType + " docuemnt support required): " + exc.Message); MessageBox.Show("Unable to preview catalog: " + docType + " docuemnt support required", "Preview Failed", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } iProgressChanged(0, null, Progress.State.eSuccess); Linn.UserLog.WriteLine("Print complete"); }
private static void AddTextToParagraph(PdfParagraph p, string t, PdfFont f) { p.Add(new PdfChunk(t.Trim(new char[] { '\r', '\n' }), f)); p.Add(PdfChunk.NEWLINE); }
private static Vector1D GetAscenderHeight(iTextSharp.text.Font font) { //Might look weird, but is this way due to error in original implementation return(new Vector1D(font.BaseFont.GetAscentPoint(fullHeightString, font.Size) - font.BaseFont.GetAscentPoint(baseHeightString, font.Size), UnitsOfMeasure.Points)); }
void ExportReport(iTextSharp.text.Document doc, DataTable dt) { iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(2f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1); iTextSharp.text.Chunk linebreak = new iTextSharp.text.Chunk(line); iTextSharp.text.Font black = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 9f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); var logo = new iTextSharp.text.Paragraph() { Alignment = 0 }; logo.Add(new iTextSharp.text.Chunk("Tachyon", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK))); logo.Add(new iTextSharp.text.Chunk("FIX", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156)))); doc.Add(logo); doc.Add(new iTextSharp.text.Chunk(line)); doc.Add(new iTextSharp.text.Paragraph(new iTextSharp.text.Chunk(ConcatStrings("Log List", DateTime.Now.ToString()), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 9f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK))) { Alignment = 0 }); doc.Add(new iTextSharp.text.Paragraph(new iTextSharp.text.Chunk(" ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 9f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK))) { Alignment = 0 }); doc.Add(linebreak); doc.Add(new iTextSharp.text.Paragraph(" ")); var bf = BaseFont.CreateFont(Environment.CurrentDirectory + @"\arial.ttf", BaseFont.IDENTITY_H, true); iTextSharp.text.Font NormalFont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); iTextSharp.text.Font TFont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.GREEN); iTextSharp.text.Font XFont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.RED); PdfPTable table = new PdfPTable(dt.Columns.Count) { WidthPercentage = 100 }; for (int i = 0; i < dt.Columns.Count; i++) { table.AddCell(new PdfPCell() { Phrase = new iTextSharp.text.Phrase(dt.Columns[i].ColumnName), BackgroundColor = iTextSharp.text.BaseColor.GRAY }); } //table.SetWidths(new float[] { 3, 25, 25, 8 }); for (int i = 0; i < dt.Rows.Count; i++) { ReportProgress((i / (double)dt.Rows.Count) * 100, "Exporting Rows..."); DataRow GridRow = dt.Rows[i]; for (int j = 0; j < dt.Columns.Count; j++) { table.AddCell(new iTextSharp.text.Phrase(GridRow.ItemArray[j].ToString(), NormalFont)); } } doc.Add(table); }
/// <summary> /// a megadott file elérési úttal elkészíti a pdf dokumentumot /// </summary> /// <param name="financedAmount"></param> /// <param name="calcValues"></param> /// <param name="pdfFileWithPath"></param> /// <returns></returns> public void CreateLeasingDocument(string financedAmount, System.Collections.Specialized.StringCollection calcValues, string pdfFileWithPath) { iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 36, 36, 36, 36); //marginTop : 72 try { // writer letrehozas iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(pdfFileWithPath, System.IO.FileMode.Create)); // lablec iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new iTextSharp.text.Phrase(), true); footer.Border = iTextSharp.text.Rectangle.NO_BORDER; footer.Alignment = iTextSharp.text.HeaderFooter.ALIGN_CENTER; document.Footer = footer; // dokumentum megnyitas document.Open(); iTextSharp.text.Chapter chapter1 = new iTextSharp.text.Chapter(2); chapter1.NumberDepth = 0; //fejlec kep iTextSharp.text.Image imgHeader = GetHeaderImageFile(); imgHeader.Alignment = iTextSharp.text.Image.ALIGN_LEFT; imgHeader.Alt = "NE VEDD MEG, BÉRELD!"; iTextSharp.text.Table hTable = new iTextSharp.text.Table(1, 1); iTextSharp.text.Cell hCell = new iTextSharp.text.Cell(imgHeader); hTable.AutoFillEmptyCells = true; hTable.TableFitsPage = true; hTable.WidthPercentage = 100; hTable.AddCell(hCell); hTable.Alignment = iTextSharp.text.Table.ALIGN_LEFT; chapter1.Add(hTable); iTextSharp.text.Color defaultTextColor = new iTextSharp.text.Color(0, 0, 128); //uj sor, tavtarto a tabla es a fejleckep kozott chapter1.Add(new iTextSharp.text.Paragraph(" ")); iTextSharp.text.pdf.BaseFont default_ttf = iTextSharp.text.pdf.BaseFont.CreateFont(CompanyGroup.Helpers.ConfigSettingsParser.GetString("FontFile", "c:\\Windows\\Fonts\\calibri.ttf"), iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED); iTextSharp.text.Font titlefont = new iTextSharp.text.Font(default_ttf, 16, iTextSharp.text.Font.BOLDITALIC, defaultTextColor); iTextSharp.text.Font defaultFont = new iTextSharp.text.Font(default_ttf, 15, iTextSharp.text.Font.NORMAL, defaultTextColor); //cimsor iTextSharp.text.Paragraph pgTitle = new iTextSharp.text.Paragraph("Finanszírozási ajánlat", titlefont); chapter1.Add(pgTitle); //tablazat iTextSharp.text.Table table1 = new iTextSharp.text.Table(2, 1); table1.BorderColor = table1.DefaultCellBorderColor = defaultTextColor; table1.Padding = 2; table1.Spacing = 1; table1.AutoFillEmptyCells = true; table1.Alignment = iTextSharp.text.Table.ALIGN_LEFT; table1.WidthPercentage = 80.0f; table1.Widths = new float[] { 60, 20 }; iTextSharp.text.Paragraph tmpParagraph = new iTextSharp.text.Paragraph("A konfiguráció nettó vételára:", defaultFont); iTextSharp.text.Cell cell1 = new iTextSharp.text.Cell(tmpParagraph); cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; table1.AddCell(cell1); tmpParagraph = new iTextSharp.text.Paragraph(financedAmount + " Ft", defaultFont); iTextSharp.text.Cell cell2 = new iTextSharp.text.Cell(tmpParagraph); cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; table1.AddCell(cell2); chapter1.Add(table1); //5 oszlopos tabla iTextSharp.text.Table table2 = new iTextSharp.text.Table(5); table2.BorderColor = defaultTextColor; table2.Padding = 2; table2.Spacing = 1; table2.AutoFillEmptyCells = true; table2.Alignment = iTextSharp.text.Table.ALIGN_LEFT; table2.WidthPercentage = 100.0f; table2.Widths = new float[] { 20, 20, 20, 20, 20 }; //első sor tmpParagraph = new iTextSharp.text.Paragraph("Önerő", defaultFont); cell1 = new iTextSharp.text.Cell(tmpParagraph); cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell1.Header = true; cell1.Colspan = 4; cell1.BorderColor = defaultTextColor; table2.AddCell(cell1); tmpParagraph = new iTextSharp.text.Paragraph("0 Ft", defaultFont); cell2 = new iTextSharp.text.Cell(tmpParagraph); cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell2.BorderColor = defaultTextColor; table2.AddCell(cell2); //második sor //table2.AddCell(""); tmpParagraph = new iTextSharp.text.Paragraph("Deviza: HUF", defaultFont); iTextSharp.text.Cell tmpCell = new iTextSharp.text.Cell(tmpParagraph); tmpCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; tmpCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; tmpCell.BorderColor = defaultTextColor; tmpCell.Rowspan = 2; table2.AddCell(tmpCell); tmpParagraph = new iTextSharp.text.Paragraph("Futamidő hónapokban", defaultFont); cell1 = new iTextSharp.text.Cell(tmpParagraph); cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell1.BorderColor = defaultTextColor; cell1.Colspan = 4; table2.AddCell(cell1); //harmadik sor tmpParagraph = new iTextSharp.text.Paragraph("24", defaultFont); cell2 = new iTextSharp.text.Cell(tmpParagraph); cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell2.BorderColor = defaultTextColor; table2.AddCell(cell2); tmpParagraph = new iTextSharp.text.Paragraph("36", defaultFont); iTextSharp.text.Cell cell3 = new iTextSharp.text.Cell(tmpParagraph); cell3.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell3.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell3.BorderColor = defaultTextColor; table2.AddCell(cell3); tmpParagraph = new iTextSharp.text.Paragraph("48", defaultFont); iTextSharp.text.Cell cell4 = new iTextSharp.text.Cell(tmpParagraph); cell4.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell4.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell4.BorderColor = defaultTextColor; table2.AddCell(cell4); tmpParagraph = new iTextSharp.text.Paragraph("60", defaultFont); iTextSharp.text.Cell cell5 = new iTextSharp.text.Cell(tmpParagraph); cell5.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell5.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell5.BorderColor = defaultTextColor; table2.AddCell(cell5); //negyedik sor tmpParagraph = new iTextSharp.text.Paragraph("Tartós bérlet", defaultFont); cell1 = new iTextSharp.text.Cell(tmpParagraph); cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell1.BorderColor = defaultTextColor; table2.AddCell(cell1); tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(0, calcValues), defaultFont); cell2 = new iTextSharp.text.Cell(tmpParagraph); cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell2.BorderColor = defaultTextColor; table2.AddCell(cell2); tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(1, calcValues), defaultFont); cell3 = new iTextSharp.text.Cell(tmpParagraph); cell3.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell3.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell3.BorderColor = defaultTextColor; table2.AddCell(cell3); tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(2, calcValues), defaultFont); cell4 = new iTextSharp.text.Cell(tmpParagraph); cell4.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell4.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell4.BorderColor = defaultTextColor; table2.AddCell(cell4); tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(3, calcValues), defaultFont); cell5 = new iTextSharp.text.Cell(tmpParagraph); cell5.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT; cell5.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell5.BorderColor = defaultTextColor; table2.AddCell(cell5); //ötödik sor table2.AddCell(""); tmpParagraph = new iTextSharp.text.Paragraph("Nettó havidíjak", defaultFont); cell1 = new iTextSharp.text.Cell(tmpParagraph); cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; cell1.BorderColor = defaultTextColor; cell1.Colspan = 4; table2.AddCell(cell1); //hatodik sor //tmpParagraph = new iTextSharp.text.Paragraph( "A kalkulált díjak biztosítási díjat is tartalmaznak.", defaultFont ); //cell1 = new iTextSharp.text.Cell( tmpParagraph ); //cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; //cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE; //cell1.BorderColor = defaultTextColor; //cell1.Colspan = 5; //table2.AddCell(cell1); chapter1.Add(table2); chapter1.Add(new iTextSharp.text.Paragraph(" ")); //szoveg iTextSharp.text.Font smallFont = new iTextSharp.text.Font(default_ttf, 9, iTextSharp.text.Font.ITALIC, defaultTextColor); iTextSharp.text.Paragraph sText = new iTextSharp.text.Paragraph("HUF alapú finanszírozás, a havi díj az 1 havi Buborhoz kötött", smallFont); chapter1.Add(sText); //uj sor chapter1.Add(new iTextSharp.text.Paragraph(" ")); //szoveg iTextSharp.text.Font bold_10_Font = new iTextSharp.text.Font(default_ttf, 10, iTextSharp.text.Font.BOLD, defaultTextColor); sText = new iTextSharp.text.Paragraph("Ajánlatunkat ajánlati kötöttség nélkül tettük meg!", bold_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("Az ügylet megkötéséhez a refinanszírozó jóváhagyása szükséges.", bold_10_Font); chapter1.Add(sText); //uj sor chapter1.Add(new iTextSharp.text.Paragraph(" ")); ////szoveg //var bold_12_Font = new iTextSharp.text.Font( default_ttf, 12, iTextSharp.text.Font.BOLD, defaultTextColor ); //sText = new iTextSharp.text.Paragraph( "Szerződéskötési díj: 0 Ft", bold_12_Font ); //chapter1.Add(sText); ////uj sor //chapter1.Add(new iTextSharp.text.Paragraph(" ")); //szoveg sText = new iTextSharp.text.Paragraph("A tartós bérlet alapvető jellemzői", bold_10_Font); chapter1.Add(sText); //szoveg iTextSharp.text.Font normal_10_Font = new iTextSharp.text.Font(default_ttf, 10, iTextSharp.text.Font.NORMAL, defaultTextColor); sText = new iTextSharp.text.Paragraph("A bérleti díjakat ÁFA terheli, mely visszaigényelhető", normal_10_Font); sText.IndentationLeft = 50; chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("Az eszköz a bérbeadó könyveiben kerül aktiválásra", normal_10_Font); sText.IndentationLeft = 50; chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("A havi díj költségként elszámolható, csökkentve ezáltal az adóalapot", normal_10_Font); sText.IndentationLeft = 50; chapter1.Add(sText); //uj sor chapter1.Add(new iTextSharp.text.Paragraph(" ")); //szoveg sText = new iTextSharp.text.Paragraph("Ha bármilyen kérdése merülne fel a konstrukciót illetően, forduljon hozzánk bizalommal!", bold_10_Font); chapter1.Add(sText); //uj sor chapter1.Add(new iTextSharp.text.Paragraph(" ")); //szoveg sText = new iTextSharp.text.Paragraph("Kublik Ádám", bold_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("értékesítési vezető", normal_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("HRP Finance", bold_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("Tel.: +36 1 452 46 16", normal_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("mob.: +36 70 452 46 16", normal_10_Font); chapter1.Add(sText); //szoveg sText = new iTextSharp.text.Paragraph("mail: [email protected]", normal_10_Font); chapter1.Add(sText); document.Add(chapter1); } catch (iTextSharp.text.DocumentException documentException) { throw documentException; } catch (System.IO.IOException ioeException) { throw ioeException; } finally { // dokumentum bezarasa document.Close(); } }
private static Vector1D GetDescenderHeight(iTextSharp.text.Font font) { return(new Vector1D(-font.BaseFont.GetDescentPoint(baseHeightString, font.Size), UnitsOfMeasure.Points)); }
public PageEventHelper() { BaseFont bf = BaseFont.CreateFont(Environment.CurrentDirectory + @"\arial.ttf", BaseFont.IDENTITY_H, true); RunDateFont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK); }