public virtual void ToPdf(string filePath) { var content = ToString(); var doc = DrawingDimensions.ToPdfDoc(content); var printSv = Ruler?.StartValue ?? 0; var printEv = Ruler?.EndValue ?? 0; var printEpc = Ruler?.GetEpochName() ?? string.Empty; var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); using (var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, fs)) { doc.Open(); var paragraph = new iTextSharp.text.Paragraph(content, iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.COURIER)) { ExtraParagraphSpace = 0F, FirstLineIndent = 0F, IndentationLeft = 0F, IndentationRight = 0F, PaddingTop = 0F, SpacingBefore = 0F, SpacingAfter = 0F }; doc.Add(paragraph); doc.AddTitle(Name); doc.AddAuthor(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); doc.AddSubject($"{nameof(Occidental)} timeline plate for '{Name}' from {printSv} to {printEv} {printEpc}"); doc.AddCreator(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); doc.AddCreationDate(); doc.Close(); } }
public static void CreatePDF(Image image, string filePath, ImageFormat format) { string directoryPath = Path.GetDirectoryName(filePath); string filename = Path.GetFileNameWithoutExtension(filePath); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER); try { var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(Path.Combine(directoryPath, filename) + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(image, format); iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); pic.Border = 1; pic.BorderColor = iTextSharp.text.BaseColor.BLACK; paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; paragraph.Add(pic); document.Add(paragraph); document.NewPage(); } catch (iTextSharp.text.DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } document.Close(); }
private void generarXMLTokens(LinkedList <Token> tokens) { string path = "archivo.xml"; File.WriteAllText(path, ""); iTextSharp.text.Document doc = new iTextSharp.text.Document(); iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream("reporte.pdf", FileMode.Create)); doc.Open(); iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph(); titulo.Font = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA_BOLD, 18f, iTextSharp.text.BaseColor.ORANGE); titulo.Add("REPORTE DE TOKENS"); doc.Add(titulo); doc.Add(new iTextSharp.text.Paragraph("\n")); doc.Add(new iTextSharp.text.Paragraph("\n")); doc.Add(new iTextSharp.text.Paragraph("")); iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(4); table.AddCell("Tokens"); table.AddCell("Lexema"); table.AddCell("Fila"); table.AddCell("Columa"); if (File.Exists(path)) { using (StreamWriter file = File.AppendText(path)) { file.WriteLine("<ListaTokens>"); foreach (Token item in tokens) { table.AddCell(item.getToken()); table.AddCell(item.getValor()); table.AddCell(item.getFila().ToString()); table.AddCell(item.getColumna().ToString()); file.WriteLine( " <Token>\n" + " <Nombre>" + item.getToken() + "</Nombre>\n" + " <Valor>" + item.getValor() + "</Valor>\n" + " <Fila>" + item.getFila() + "</Fila>\n" + " <Columna>" + item.getColumna() + "</Columna>\n" + " </Token>\n"); } file.WriteLine("</ListaTokens>"); Console.WriteLine("si se modifico"); file.Close(); } doc.Add(table); doc.Close(); } /*Process p = new Process(); * p.StartInfo.FileName = path; * p.Start();*/ }
public iTextSharp.text.IElement ToPDF() { iTextSharp.text.Paragraph pg = new iTextSharp.text.Paragraph((iTextSharp.text.Phrase)Phrase.ToPDF()); pg.IndentationLeft = (float)LeftIndent; pg.IndentationRight = (float)Rightindent; return(pg); }
private static void GetInfoPDF(Jądro J, int i, iTextSharp.text.pdf.PdfPTable table, List <string> listawybranychinformacji) { foreach (var item in listawybranychinformacji) { if (item == "Numer Matrycy") { iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.Add(new iTextSharp.text.Phrase("Numer Matrycy")); p.Add(new iTextSharp.text.Phrase(Jądro.NAJLEPSZE.wypiszNRMatrycy(i))); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; if (Jądro.NAJLEPSZE.wypiszNRMatrycy(i) != "") { cell.AddElement(p); table.AddCell(cell); } } if (item == "ID") { iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.Add(new iTextSharp.text.Phrase("ID")); p.Add(new iTextSharp.text.Phrase(Jądro.NAJLEPSZE.wypiszID(i))); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; if (Jądro.NAJLEPSZE.wypiszNRMatrycy(i) != "") { cell.AddElement(p); table.AddCell(cell); } } if (item == "Punkt Zaczepienia") { iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.Add(new iTextSharp.text.Phrase("Punkt Zaczepienia")); p.Add(new iTextSharp.text.Phrase(Jądro.NAJLEPSZE.wypiszPunktZaczepienia(i))); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; if (Jądro.NAJLEPSZE.wypiszNRMatrycy(i) != "") { cell.AddElement(p); table.AddCell(cell); } } if (item == "Wymiary") { iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.Add(new iTextSharp.text.Phrase("Wymiary")); p.Add(new iTextSharp.text.Phrase(Jądro.NAJLEPSZE.wypiszWymiary(i))); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; if (Jądro.NAJLEPSZE.wypiszNRMatrycy(i) != "") { cell.AddElement(p); table.AddCell(cell); } } } }
private void Imprimir_Click(object sender, EventArgs e) { if (dgvDados.RowCount == 0) { MessageBox.Show("Realize a pesquisa previamente"); } else { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PDF files (*.pdf)|*.pdf"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { using (var fileStream = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { var document = new iTextSharp.text.Document(); var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream); document.Open(); var paragraph = new iTextSharp.text.Paragraph("RELATÓRIO DE EMPRÉSTIMOS"); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("DE: " + dtpInicio.Text + " ATÉ: " + dtpFim.Text); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("\n"); document.Add(paragraph); for (int i = 0; i < dgvDados.RowCount; i++) { DateTime data = DateTime.Parse(dgvDados.Rows[i].Cells[6].Value.ToString()); paragraph = new iTextSharp.text.Paragraph(dgvDados.Rows[i].Cells[2].Value.ToString() + " " + dgvDados.Rows[i].Cells[3].Value.ToString() + " " + dgvDados.Rows[i].Cells[4].Value.ToString() + " " + dgvDados.Rows[i].Cells[5].Value.ToString() + " " + data.ToString("d")); paragraph.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; document.Add(paragraph); } document.Close(); System.Diagnostics.Process.Start(saveFileDialog1.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ATENÇÃO"); } } } }
public void Save(string fileName, Func <List <IElementRoot>, List <IElementRoot> > formatFunc = null) { if (formatFunc != null) { formatFunc.Invoke(Paragraphs); } string defaultFontPath = FontUtils.GetFontPath(ReportFactory.FontList, ReportFactory.FontStyle); iTextSharp.text.FontFactory.Register(defaultFontPath); using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) { PageSize currentPageSize = PageSize ?? ReportFactory.PageSize; PageOrientation pageOrientation = PageOrientation ?? ReportFactory.PageOrientation; iTextSharp.text.Rectangle pageSize = currentPageSize.ToRectangle(pageOrientation); using (var document = new iTextSharp.text.Document(pageSize)) { float marginTop = MarginLeft ?? ReportFactory.MarginLeft; float marginRight = MarginLeft ?? ReportFactory.MarginRight; float marginBottom = MarginLeft ?? ReportFactory.MarginBottom; float marginLeft = MarginLeft ?? ReportFactory.MarginLeft; document.SetMargins(marginLeft, marginRight, marginTop, marginBottom); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream); document.Open(); foreach (var para in Paragraphs) { if (para is Table) { iTextSharp.text.pdf.PdfPTable tableSource = para as Table; document.Add(tableSource); } else if (para is Paragraph) { iTextSharp.text.Paragraph paragraph = para as Paragraph; document.Add(paragraph); } } document.Close(); } fileStream.Close(); } }
/// <summary> /// Converts the specified frame into an PDF paragraph. /// </summary> /// <param name="frame">The frame.</param> /// <returns>The paragraph representing the passed frame.</returns> public iTextSharp.text.Paragraph Convert(Frame frame) { try { iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); foreach (iTextSharp.text.IElement pdfElement in MixedContentConverter.GetMixedPdfContent(frame.Content)) { paragraph.Add(pdfElement); } return(paragraph); } catch (Exception) { throw; } }
/// <summary> /// Converts the specified frame into an PDF paragraph. /// </summary> /// <param name="frame">The frame.</param> /// <returns>The paragraph representing the passed frame.</returns> public iTextSharp.text.Paragraph Convert(Frame frame) { try { iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); foreach(iTextSharp.text.IElement pdfElement in MixedContentConverter.GetMixedPdfContent(frame.Content)) { paragraph.Add(pdfElement); } return paragraph; } catch(Exception) { throw; } }
/// <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; } }
/// <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; } }
/// <summary> /// InCorrect answers paragraph /// </summary> private void WriterInCorrectAnswers(iTextSharp.text.Document doc) { iTextSharp.text.Paragraph InCorrectAnswers = new iTextSharp.text.Paragraph(); InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkRed); InCorrectAnswers.Alignment = iTextSharp.text.Element.ALIGN_CENTER; InCorrectAnswers.Add($"\n\n\nInCorrect Answers\n\n"); doc.Add(InCorrectAnswers); InCorrectAnswers.Clear(); foreach (var question in report.InCorrects) { InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.Black); InCorrectAnswers.Alignment = iTextSharp.text.Element.ALIGN_LEFT; InCorrectAnswers.Add(question.Text); doc.Add(InCorrectAnswers); InCorrectAnswers.Clear(); InCorrectAnswers.Alignment = iTextSharp.text.Element.ALIGN_CENTER; foreach (var answer in question.Answers) { if (answer.IsCorrect == "Yes") { InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkGreen); } else if (report.YourAnswers[question.id] == answer.Text) { InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkRed); } else { InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkGray); } InCorrectAnswers.Add(answer.Text); doc.Add(InCorrectAnswers); InCorrectAnswers.Clear(); } } }
/// <summary> /// NoAnswers paragraph /// </summary> private void WriterNoAnswers(iTextSharp.text.Document doc) { iTextSharp.text.Paragraph NoAnswers = new iTextSharp.text.Paragraph(); NoAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.Blue); NoAnswers.Alignment = iTextSharp.text.Element.ALIGN_CENTER; NoAnswers.Add("\n\n\nNo Answers\n\n"); doc.Add(NoAnswers); NoAnswers.Clear(); foreach (var question in report.NoAnswers) { NoAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.Black); NoAnswers.Alignment = iTextSharp.text.Element.ALIGN_LEFT; NoAnswers.Add(question.Text); doc.Add(NoAnswers); NoAnswers.Clear(); NoAnswers.Alignment = iTextSharp.text.Element.ALIGN_CENTER; foreach (var answer in question.Answers) { if (answer.IsCorrect == "Yes") { NoAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.Blue); } else { NoAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkGray); } NoAnswers.Add(answer.Text); doc.Add(NoAnswers); NoAnswers.Clear(); } } }
public static void CreatePDF(string filePath, string destinationfilePath) { string directoryPath = Path.GetDirectoryName(destinationfilePath); string filename = Path.GetFileNameWithoutExtension(destinationfilePath); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER); try { var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(Path.Combine(directoryPath, filename) + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); paragraph.Alignment = iTextSharp.text.Element.ALIGN_LEFT; var extension = Path.GetExtension(filePath); switch (extension.ToLower()) { case ".jpg": case ".bmp": case ".jpeg": case ".gif": case ".png": case ".tiff": iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(Image.FromFile(filePath), GetImageFormat(UserArgs.Configurations.ImageFormat)); pic.Border = 1; pic.BorderColor = iTextSharp.text.BaseColor.BLACK; paragraph.Add(pic); document.Add(paragraph); document.NewPage(); break; case ".txt": paragraph.Add(File.ReadAllText(filePath)); document.Add(paragraph); document.NewPage(); break; case ".htm": case ".html": TextReader reader = new StringReader(File.ReadAllText(filePath)); HTMLWorker worker = new HTMLWorker(document); worker.StartDocument(); worker.Parse(reader); worker.EndDocument(); worker.Close(); break; case ".rtf": string htmlDocument = GetHtmlFromRTF(File.ReadAllText(filePath)); reader = new StringReader(htmlDocument); worker = new HTMLWorker(document); worker.StartDocument(); worker.Parse(reader); worker.EndDocument(); worker.Close(); break; default: paragraph.Add(File.ReadAllText(filePath)); document.Add(paragraph); document.NewPage(); break; } } catch (iTextSharp.text.DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } document.Close(); }
/// <summary> /// 引用iTextSharp.dll导出pdf数据库字典文档 /// </summary> /// <param name="databaseName"></param> /// <param name="tables"></param> public static void ExportPdfByITextSharp(string fileName, string fontPath, string databaseName, List <TableDto> tables) { // TODO 创建并添加文档信息 iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(); pdfDocument.AddTitle(fileName); iTextSharp.text.pdf.PdfWriter pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, new System.IO.FileStream(fileName, System.IO.FileMode.Create)); pdfDocument.Open(); // 打开文档 // TODO 标题 iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("数据库字典文档\n\n", BaseFont(fontPath, 30, iTextSharp.text.Font.BOLD)); title.Alignment = iTextSharp.text.Element.ALIGN_CENTER; pdfDocument.Add(title); iTextSharp.text.Paragraph subTitle = new iTextSharp.text.Paragraph(" —— " + databaseName, BaseFont(fontPath, 20, iTextSharp.text.Font.NORMAL)); subTitle.Alignment = iTextSharp.text.Element.ALIGN_CENTER; pdfDocument.Add(subTitle); // TODO PDF换页 pdfDocument.NewPage(); // TODO 创建添加书签章节 int chapterNum = 1; // TODO 全局字体设置,处理iTextSharp中文不识别显示问题 iTextSharp.text.Font pdfFont = BaseFont(fontPath, 12, iTextSharp.text.Font.NORMAL); // TODO log table iTextSharp.text.Chapter chapter1 = new iTextSharp.text.Chapter(new iTextSharp.text.Paragraph(AppConst.LOG_CHAPTER_NAME, pdfFont), chapterNum); pdfDocument.Add(chapter1); pdfDocument.Add(new iTextSharp.text.Paragraph("\n", pdfFont)); // 换行 CreateLogTable(pdfDocument, pdfFont, tables); // TODO PDF换页 pdfDocument.NewPage(); // TODO overview table iTextSharp.text.Chapter chapter2 = new iTextSharp.text.Chapter(new iTextSharp.text.Paragraph(AppConst.TABLE_CHAPTER_NAME, pdfFont), (++chapterNum)); pdfDocument.Add(chapter2); pdfDocument.Add(new iTextSharp.text.Paragraph("\n", pdfFont)); // 换行 CreateOverviewTable(pdfDocument, pdfFont, tables); // TODO PDF换页 pdfDocument.NewPage(); // TODO table structure // TODO 添加书签章节 iTextSharp.text.Chapter chapter3 = new iTextSharp.text.Chapter(new iTextSharp.text.Paragraph(AppConst.TABLE_STRUCTURE_CHAPTER_NAME, pdfFont), (++chapterNum)); chapter3.BookmarkOpen = true; pdfDocument.Add(chapter3); pdfDocument.Add(new iTextSharp.text.Paragraph("\n", pdfFont)); // 换行 foreach (var table in tables) { string docTableName = table.TableName + " " + (!string.IsNullOrWhiteSpace(table.Comment) ? table.Comment : ""); // TODO 添加书签章节 iTextSharp.text.Section selection = chapter3.AddSection(20f, new iTextSharp.text.Paragraph(docTableName, pdfFont), chapterNum); pdfDocument.Add(selection); pdfDocument.Add(new iTextSharp.text.Paragraph("\n", pdfFont)); // 换行 // TODO 遍历数据库表 // TODO 创建表格 iTextSharp.text.pdf.PdfPTable pdfTable = new iTextSharp.text.pdf.PdfPTable(10); // TODO 添加列标题 pdfTable.AddCell(CreatePdfPCell("序号", pdfFont)); pdfTable.AddCell(CreatePdfPCell("列名", pdfFont)); pdfTable.AddCell(CreatePdfPCell("数据类型", pdfFont)); pdfTable.AddCell(CreatePdfPCell("长度", pdfFont)); pdfTable.AddCell(CreatePdfPCell("小数位", pdfFont)); pdfTable.AddCell(CreatePdfPCell("主键", pdfFont)); pdfTable.AddCell(CreatePdfPCell("自增", pdfFont)); pdfTable.AddCell(CreatePdfPCell("允许空", pdfFont)); pdfTable.AddCell(CreatePdfPCell("默认值", pdfFont)); pdfTable.AddCell(CreatePdfPCell("列说明", pdfFont)); // TODO 添加数据行,循环数据库表字段 foreach (var column in table.Columns) { pdfTable.AddCell(CreatePdfPCell(column.ColumnOrder, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.ColumnName, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.ColumnTypeName, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.Length, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.Scale, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.IsPK, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.IsIdentity, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.CanNull, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.DefaultVal, pdfFont)); pdfTable.AddCell(CreatePdfPCell(column.Comment, pdfFont)); } // TODO 设置表格居中 pdfTable.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; pdfTable.TotalWidth = 520F; pdfTable.LockedWidth = true; pdfTable.SetWidths(new float[] { 50F, 60F, 60F, 50F, 50F, 50F, 50F, 50F, 50F, 50F }); // TODO 添加表格 pdfDocument.Add(pdfTable); // TODO PDF换页 pdfDocument.NewPage(); } // TODO 关闭释放PDF文档资源 pdfDocument.Close(); }
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); }
///******************************************************************************************************* /// <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); } }
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; } }
protected void createPDF(Stream output) { //Construct tempConstruct = myConn.getConstructByID(Convert.ToInt16(Request.QueryString["id"])); Construct tempConstruct = myConn.getConstructByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=construct_" + tempConstruct.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Construct Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Construct Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempConstruct.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Insert tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Insert: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.insert, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Vector tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Vector: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.vector, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.species, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antibiotic Resistance tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //5' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("5' Digest Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite5, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //3' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite3, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Notes tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
public virtual void ToPdf(string filePath) { var content = ToString(); var doc = DrawingDimensions.ToPdfDoc(content); var fs = new System.IO.FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); using (var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, fs)) { doc.Open(); var paragraph = new iTextSharp.text.Paragraph(content, iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.COURIER)) { ExtraParagraphSpace = 0F, FirstLineIndent = 0F, IndentationLeft = 0F, IndentationRight = 0F, PaddingTop = 0F, SpacingBefore = 0F, SpacingAfter = 0F }; doc.Add(paragraph); doc.AddTitle(Name); doc.AddSubject("Timelines"); doc.AddCreator(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name); doc.AddCreationDate(); doc.Close(); } }
protected void createPDF(Stream output) { //Vector tempVector = myConn.getVectorByID(Convert.ToInt16(Request.QueryString["id"])); Vector tempVector = myConn.getVectorByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=vector_" + tempVector.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Vector Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Vector Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempVector.vectorName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Multiple Cloning Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Multiple Cloning Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.multipleCloningSite, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antibiotic Resistance tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Vector Size tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Vector Size: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.vectorSize, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Promoter tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Promoter: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.promoter, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Notes tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
// 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(); } } } }
private void btGerarRelatorio_Click(object sender, EventArgs e) { FileStream arquivo = new FileStream("clientes.txt", FileMode.Open); StreamReader ler = new StreamReader(arquivo); FileStream arquivo1 = new FileStream("festas.txt", FileMode.Open); StreamReader ler1 = new StreamReader(arquivo1); FileStream arquivo2 = new FileStream("contratos.txt", FileMode.Open); StreamReader ler2 = new StreamReader(arquivo2); string linha = " "; string linha1 = " "; string linha2 = " "; string[] dadosDoCliente; string[] dadosDaFesta; string[] dadosDoContrato; int cont = 0; string codigoCliente = " "; string pesquisa = " "; string codigoFesta = " "; if (rBRelatorioCliente.Checked == true) { pesquisa = pesquisaNome.Text.ToUpper(); do { linha = ler.ReadLine(); if (linha != null) { dadosDoCliente = linha.Split('*'); if (dadosDoCliente[1].ToUpper() == pesquisa) { codigoCliente = dadosDoCliente[0]; // Trecho de código baseado no tutorial fornecido pelo NOME DO CARA // Fonte: WWW.COLOCAR O SITE AQUI.COM.BR // Instanciando um FileStream do tipo PDF (criando o arquivo ou abrindo) FileStream filestream = new FileStream("Relatorio_Cliente.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); filestream.Close(); // Zerando os dados do arquivo PDF FileStream filestream1 = new FileStream("Relatorio_Cliente.pdf", FileMode.Truncate, FileAccess.Write, FileShare.None); filestream1.Close(); // Instanciando um FileStream para adicionar textos no arquivo FileStream filestream2 = new FileStream("Relatorio_Cliente.pdf", FileMode.Append, FileAccess.Write, FileShare.None); // Instanciando um documento de texto na biblioteca iTextSharp var relatorio = new iTextSharp.text.Document(); // Instanciando um Writer para escrever no documento var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(relatorio, filestream2); // Abrindo o documento relatorio.Open(); // Determinando a fonte que será utilizada no documento e o tamanho da fonte var fonte = iTextSharp.text.FontFactory.GetFont("Times New Roman", 12); var fonte1 = iTextSharp.text.FontFactory.GetFont("Times New Roman", 14); // Variável utilizada para adicionar imagens e formas em um documento PDF no iTextSharp var contentByte = pdfWriter.DirectContent; // Inserindo imagem no relatorio em pdf (PARA FUNCIONAR TEM QUE ALTERAR O DIRETÓRIO DA IMAGEM) var imagem = iTextSharp.text.Image.GetInstance("C:/Users/Larys/source/repos/Workspace/TP1/Lary321/TP1/_imagens/imagemRelatorioCliente.png"); imagem.ScaleToFit(700, 200); imagem.SetAbsolutePosition(32, 625); imagem.Alignment = iTextSharp.text.Image.ALIGN_CENTER; contentByte.AddImage(imagem); // inserindo os dados da festa no relatorio em pdf var paragrafo = new iTextSharp.text.Paragraph(); paragrafo = new iTextSharp.text.Paragraph("\n\n\n\n\n\n\n\n\n Dados do(a) Cliente", fonte1); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; relatorio.Add(paragrafo); paragrafo = new iTextSharp.text.Paragraph("Código: " + dadosDoCliente[0] + "\nNome: " + dadosDoCliente[1] + "\nEndereço: " + dadosDoCliente[2] + "\nTelefone:" + dadosDoCliente[3] + "\nData de Nascimento: " + dadosDoCliente[4]); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; relatorio.Add(paragrafo); paragrafo = new iTextSharp.text.Paragraph("\nDados da(s) Festa(s) associada(s)", fonte1); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; relatorio.Add(paragrafo); do { linha1 = ler1.ReadLine(); if (linha1 != null) { dadosDaFesta = linha1.Split('*'); { codigoFesta = dadosDaFesta[0]; if (dadosDaFesta[7].Trim() == codigoCliente) { paragrafo = new iTextSharp.text.Paragraph("Código: " + dadosDaFesta[0] + "\nQuantidade de Convidados: " + dadosDaFesta[1] + "\nData: " + dadosDaFesta[2] + "\nDia da Semana: " + dadosDaFesta[3] + "\nHorário: " + dadosDaFesta[4] + "\nTema: " + dadosDaFesta[5] + "\n\n", fonte); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; relatorio.Add(paragrafo); cont++; } } } } while (linha1 != null); paragrafo = new iTextSharp.text.Paragraph("\nDados do(s) Contrato(s) associado(s)", fonte1); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; relatorio.Add(paragrafo); do { linha2 = ler2.ReadLine(); if (linha2 != null) { dadosDoContrato = linha2.Split('*'); { if (dadosDoContrato[6] == codigoFesta) { paragrafo = new iTextSharp.text.Paragraph("Código: " + dadosDoContrato[0] + "\nValor Total: " + dadosDoContrato[1] + "\nDesconto: " + dadosDoContrato[2] + "\nValor Final: " + dadosDoContrato[3] + "\nForma de Pagamento: " + dadosDoContrato[4] + "\nStatus: " + dadosDoContrato[6] + "\n\n", fonte); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; relatorio.Add(paragrafo); cont++; } } } } while (linha1 != null); relatorio.Close(); System.Diagnostics.Process.Start("Relatorio_Cliente.pdf"); pesquisaNome.Clear(); } } } while (linha != null); if (linha == null && cont < 1) { MessageBox.Show("Não existem festas associadas à este(a) cliente!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); pesquisaNome.Clear(); } ler.Close(); arquivo.Close(); ler1.Close(); arquivo1.Close(); } else if (rBRelatorioData.Checked == true) { pesquisa = pesquisaData.Value.Date.ToString("dd/MM/yyyy"); do { linha = ler1.ReadLine(); if (linha != null) { dadosDaFesta = linha.Split('*'); { if (dadosDaFesta[2] == pesquisa) { // Trecho de código baseado no tutorial fornecido pelo NOME DO CARA // Fonte: WWW.COLOCAR O SITE AQUI.COM.BR // Instanciando um FileStream do tipo PDF (criando o arquivo ou abrindo) FileStream filestream3 = new FileStream("Relatorio_Data.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); filestream3.Close(); FileStream filestream4 = new FileStream("Relatorio_Data.pdf", FileMode.Truncate, FileAccess.Write, FileShare.None); filestream4.Close(); // Instanciando um FileStream para adicionar textos no arquivo FileStream filestream5 = new FileStream("Relatorio_Data.pdf", FileMode.Append, FileAccess.Write, FileShare.None); // Instanciando um documento de texto na biblioteca iTextSharp var relatorio = new iTextSharp.text.Document(); // Instanciando um Writer para escrever no documento var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(relatorio, filestream5); // Abrindo o documento relatorio.Open(); // Determinando a fonte que será utilizada no documento e o tamanho da fonte var fonte = iTextSharp.text.FontFactory.GetFont("Times New Roman", 12); var fonte1 = iTextSharp.text.FontFactory.GetFont("Times New Roman", 14); // Variável utilizada para adicionar imagens e formas em um documento PDF no iTextSharp var contentByte = pdfWriter.DirectContent; // Inserindo imagem no relatorio em pdf (PARA FUNCIONAR TEM QUE ALTERAR O DIRETÓRIO DA IMAGEM) var imagem = iTextSharp.text.Image.GetInstance("C:/Users/Larys/source/repos/Workspace/TP1/Lary321/TP1/_imagens/imagemRelatorioData.png"); imagem.ScaleToFit(700, 200); imagem.SetAbsolutePosition(32, 625); imagem.Alignment = iTextSharp.text.Image.ALIGN_CENTER; contentByte.AddImage(imagem); // inserindo os dados da festa no relatorio em pdf var paragrafo = new iTextSharp.text.Paragraph(); paragrafo = new iTextSharp.text.Paragraph("\n\n\n\n\n\n\n\n\n Dados da Festa", fonte1); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; relatorio.Add(paragrafo); paragrafo = new iTextSharp.text.Paragraph("Código: " + dadosDaFesta[0] + "\nQuantidade de Convidados: " + dadosDaFesta[1] + "\nData: " + dadosDaFesta[2] + "\nDia da Semana:" + dadosDaFesta[3] + "\nHorário: " + dadosDaFesta[4] + "\nTema: " + dadosDaFesta[5] + "\nCódigo do Cliente: " + dadosDaFesta[6]); paragrafo.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; relatorio.Add(paragrafo); cont++; relatorio.Close(); System.Diagnostics.Process.Start("Relatorio_Data.pdf"); } } } } while (linha != null); if (linha == null && cont < 1) { MessageBox.Show("Não existem festas marcadas para esta data!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
// 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(); }
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); }
protected void Exportchart(ArrayList chart) { string uid = Session["UserID"].ToString(); MemoryStream msReport = new MemoryStream(); try { document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 82, 72); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, msReport); document.AddAuthor("Test"); document.AddSubject("Export to PDF"); document.Open(); for (int i = 0; i < chart.Count; i++) { iTextSharp.text.Chunk c = new iTextSharp.text.Chunk("Export chart to PDF", iTextSharp.text.FontFactory.GetFont("VERDANA", 15)); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; iTextSharp.text.Image hImage = null; hImage = iTextSharp.text.Image.GetInstance(MapPath(chart[i].ToString())); float NewWidth = 500; float MaxHeight = 400; if (hImage.Width <= NewWidth) { NewWidth = hImage.Width; } float NewHeight = hImage.Height * NewWidth / hImage.Width; if (NewHeight > MaxHeight) { NewWidth = hImage.Width * MaxHeight / hImage.Height; NewHeight = MaxHeight; } float ratio = hImage.Width / hImage.Height; hImage.ScaleAbsolute(NewWidth, NewHeight); document.Add(p); document.Add(hImage); } // close it document.Close(); string filename = "Appraisal Overview for " + Session["Name"].ToString() + ".pdf"; Response.AddHeader("Content-type", "application/pdf"); Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.OutputStream.Write(msReport.GetBuffer(), 0, msReport.GetBuffer().Length); } catch (System.Threading.ThreadAbortException ex) { throw new Exception("Error occured: " + ex); } }
protected void createPDF(Stream output) { //SecondaryAntibody tempAntibody = myConn.getSecondaryAntibodyByID(Convert.ToInt16(Request.QueryString["id"])); SecondaryAntibody tempAntibody = myConn.getSecondaryAntibodyByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=secondary_antibody_" + tempAntibody.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Secondary Antibody Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Antibody Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Antibody Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempAntibody.antibodyName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Concentration tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Concentration: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.concentration, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Excitation tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Excitation: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.excitation, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Host Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Host Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.hostSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Reactive Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Reactive Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.reactiveSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Fluorophore tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Fluorophore: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.fluorophore, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Working Dilution tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.workingDilution, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Lot Number tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Lot Number: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.lotNumber, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antigen tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antigen: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.antigen, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Applications tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Applications: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.applications, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
/// <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(); } }
protected void createPDF(Stream output) { //Construct tempConstruct = myConn.getConstructByID(Convert.ToInt16(Request.QueryString["id"])); Construct tempConstruct = myConn.getConstructByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=construct_" + tempConstruct.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Construct Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Construct Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempConstruct.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Insert tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Insert: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.insert, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Vector tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Vector: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.vector, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.species, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antibiotic Resistance tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //5' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("5' Digest Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite5, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //3' Digest Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite3, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Notes tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempConstruct.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
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); }
protected void createPDF(Stream output) { //PrimaryAntibody tempAntibody = myConn.getPrimaryAntibodyByID(Convert.ToInt16(Request.QueryString["id"])); PrimaryAntibody tempAntibody = myConn.getPrimaryAntibodyByID(int.Parse(txtid.Value)); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=primary_antibody_" + tempAntibody.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Primary Antibody Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempAntibody.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Type tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Type: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.type, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Clone tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Clone: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.clone, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Host Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Host Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.hostSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Reactive Species tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Reactive Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.reactiveSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Concentration tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Concentration: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.concentration, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Working Dilution tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.workingDilution, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Applications tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Applications: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.applications, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Isotype tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Isotype: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.isotype, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antigen tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antigen: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.antigen, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Fluorophore tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Fluorophore: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempAntibody.fluorophore, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
public void Gerador(string idUsuario) { string DataIdUsuario = idUsuario + "_" + DateTime.Now.ToShortDateString().Trim().Replace("/", "") + "_" + DateTime.Now.ToShortTimeString().Trim().Replace(":", "") + ""; var reusltado = _ApiService.GetEmailUsuario(idUsuario).Result; using (var fileStream = new System.IO.FileStream(@"C:\Users\paulo\Downloads\PDFs\RelatorioShield_" + DataIdUsuario + ".pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)) { var document = new iTextSharp.text.Document(); var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream); document.Open(); iTextSharp.text.FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts"); var font = iTextSharp.text.FontFactory.GetFont("Calibri", 14); var paragraph = new iTextSharp.text.Paragraph("DADOS COMPLEMENTARES DA VITIMA", font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("NOME COMPLETO:" + (reusltado.Select(d => d.NomeCompleto).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("CONTATO:" + (reusltado.Select(d => d.Contato).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("CONTATO RECADO:" + (reusltado.Select(d => d.ContatoRecado).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("EMAIL:" + (reusltado.Select(d => d.Email).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("ENDEREÇO:" + (reusltado.Select(d => d.Endereco).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); paragraph = new iTextSharp.text.Paragraph("RG:" + (reusltado.Select(d => d.Rg_CPF).Single()).ToString().ToUpper(), font); paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(paragraph); //paragraph = new iTextSharp.text.Paragraph("Aqui temos um parágrafo centralizado.", font); //paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER; //document.Add(paragraph); //paragraph = new iTextSharp.text.Paragraph("Aqui temos um parágrafo alinhado à direita.", font); //paragraph.Alignment = iTextSharp.text.Element.ALIGN_RIGHT; //document.Add(paragraph); //paragraph = new iTextSharp.text.Paragraph("E, finalmente, aqui temos um parágrafo justificado. Aqui precisamos de mais texto para ver se o texto está realmente sendo justificado! Confira as outras categorias do meu site para artigos relacionados a outras tecnologias de desenvolvimento de software!", font); //paragraph.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; //document.Add(paragraph); // Figuras geométricas. //var contentByte = pdfWriter.DirectContent; //contentByte.Rectangle(100, 530, 180, 110); //contentByte.Stroke(); //contentByte.Circle(400, 580, 50); //contentByte.Stroke(); // Imagem. //var image = iTextSharp.text.Image.GetInstance("penguins.jpg"); //image.ScaleToFit(400, 300); //image.SetAbsolutePosition(80, 200); //contentByte.AddImage(image); document.Close(); //System.Diagnostics.Process.Start("output.pdf"); } }
private void imprimiPDF() { try { //Cria a iTextSharp Table da DataTable iTextSharp.text.pdf.PdfPTable pdfTable = new iTextSharp.text.pdf.PdfPTable(dgvConsulta.ColumnCount); pdfTable.DefaultCell.Padding = 2; pdfTable.WidthPercentage = 100; pdfTable.DefaultCell.BorderWidth = 0; pdfTable.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; //Adiciona a linha do cabeçalho foreach (DataGridViewColumn column in dgvConsulta.Columns) { iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase(column.HeaderText)); cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240); cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; cell.BorderWidth = 0; pdfTable.AddCell(cell); } //Adiciona as linhas foreach (DataGridViewRow row in dgvConsulta.Rows) { foreach (DataGridViewCell cell in row.Cells) { pdfTable.AddCell(cell.Value.ToString()); } } //Exporta para PDF string folderPath = @"\\10.0.3.35\d\Debug\report\RELATÓRIO DE " + frmMenu.lbTitulo.Text + ".pdf"; using (System.IO.FileStream stream = new System.IO.FileStream(folderPath, System.IO.FileMode.Create)) { //Configurando e adicionando os paragrafos iTextSharp.text.Paragraph ph1 = new iTextSharp.text.Paragraph("RELATÓRIO DE " + frmMenu.lbTitulo.Text); ph1.Alignment = iTextSharp.text.Element.ALIGN_CENTER; ph1.Font.SetStyle(5); iTextSharp.text.Paragraph ph2 = new iTextSharp.text.Paragraph(lbDeveloped.Text); //ph2.Alignment = iTextSharp.text.Element.ALIGN_CENTER; iTextSharp.text.Paragraph ph3 = new iTextSharp.text.Paragraph(lbRaf.Text); //ph3.Alignment = iTextSharp.text.Element.ALIGN_CENTER; ph3.Font.SetStyle(1); // 1 - negrito; iTextSharp.text.Paragraph ph4 = new iTextSharp.text.Paragraph(lLemail.Text); //ph4.Alignment = iTextSharp.text.Element.ALIGN_CENTER; iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10); iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(@"\\10.0.3.35\d\Debug\image\logo_nova.JPG"); logo.ScalePercent(0.3f * 100); logo.Alignment = iTextSharp.text.Element.ALIGN_CENTER; pdfDoc.Add(logo); pdfDoc.Add(ph1); //pdfDoc.Add(new iTextSharp.text.Paragraph(" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(new iTextSharp.text.Paragraph("Período.......: " + txtInicio.Text + " à " + txtFim.Text)); pdfDoc.Add(new iTextSharp.text.Paragraph("Usuário.......: " + frmMenu.lbNome.Text)); pdfDoc.Add(new iTextSharp.text.Paragraph("Emitido em.: " + DateTime.Now.ToString())); pdfDoc.Add(ph2); pdfDoc.Add(ph3); pdfDoc.Add(ph4); pdfDoc.Add(new iTextSharp.text.Paragraph(" ")); pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); System.Diagnostics.Process.Start(folderPath); // iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4); // string caminho = Application.StartupPath + @"\Exemplo.pdf"; // iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new System.IO.FileStream(caminho, System.IO.FileMode.Create)); // try // { // doc.SetMargins(30, 30, 70, 70); // doc.AddCreationDate(); // doc.Open(); // iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(brocaFornecedor().ToString()); // par.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED; // par.Add("Teste na criação de um arquivo PDF"); // doc.Add(par); // doc.Close(); // System.Diagnostics.Process.Start(caminho); // } // catch (Exception Ex) // { // MessageBox.Show("Ocorreu um erro ao gerar o PDF - Erro:", Ex.Message); // } //} } } catch (Exception ex) { MessageBox.Show("OPSS.. OCORREU UM ERRO! " + ex.Message); } }
protected void createPDF(Stream output) { //Vector tempVector = myConn.getVectorByID(Convert.ToInt16(Request.QueryString["id"])); Vector tempVector = myConn.getVectorByID(2); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=vector_" + tempVector.id + ".pdf"); iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72); PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); //Page title and spacing iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Vector Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20)); document.Add(pageTitle); iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" "); document.Add(spacing); //Name iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph(); iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Vector Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempVector.vectorName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Multiple Cloning Site tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Multiple Cloning Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.multipleCloningSite, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Antibiotic Resistance tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Vector Size tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Vector Size: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.vectorSize, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Promoter tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Promoter: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.promoter, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); //Notes tempParagraph = new iTextSharp.text.Paragraph(); tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempValue = new iTextSharp.text.Chunk(tempVector.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10)); tempParagraph.Add(tempLabel); tempParagraph.Add(tempValue); document.Add(tempParagraph); document.Close(); }
private void CreateThorPDF() { iTextSharp.text.Document document = new iTextSharp.text.Document(); string docName = "ThorDoc " + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".pdf"; PdfWriter.GetInstance(document, new FileStream(docName, FileMode.Create)); document.Open(); int i = 0; List <TimeItem> timeItemList = new List <TimeItem>(); while (i < session.totalLines) { TextBox project = this.Controls.Find(Constants.project + i, true).FirstOrDefault() as TextBox; TextBox title = this.Controls.Find(Constants.title + i, true).FirstOrDefault() as TextBox; TextBox description = this.Controls.Find(Constants.description + i, true).FirstOrDefault() as TextBox; MaskedTextBox time = this.Controls.Find(Constants.time + i, true).FirstOrDefault() as MaskedTextBox; CheckBox billable = this.Controls.Find(Constants.isBillable + i, true).FirstOrDefault() as CheckBox; CheckBox submitted = this.Controls.Find(Constants.isSubmitted + i, true).FirstOrDefault() as CheckBox; TimeItem timeItem = new TimeItem(); timeItem.project = project.Text; timeItem.description = description.Text; timeItem.isBillable = billable.Checked; timeItem.time = time.Text; timeItem.title = title.Text; timeItem.isCRMSubmitted = submitted.Checked; bool ismatch = false; foreach (TimeItem ti in timeItemList) { if (ti.project == timeItem.project && ti.isBillable == timeItem.isBillable) { ismatch = true; ti.description = timeItem.title + ": " + ti.description + timeItem.description; decimal totalSeconds = ((decimal)(TimeSpan.Parse(ti.time).TotalSeconds) + ((decimal)TimeSpan.Parse(timeItem.time).TotalSeconds)); TimeSpan t = TimeSpan.FromSeconds((double)totalSeconds); ti.time = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds); } } if (ismatch == false) { timeItem.description = timeItem.title + ":" + timeItem.description; timeItemList.Add(timeItem); } i++; } foreach (TimeItem ti in timeItemList) { iTextSharp.text.Paragraph h = new iTextSharp.text.Paragraph(ti.project, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 18, iTextSharp.text.Font.BOLD)); string content = ti.description; if (content.Length > 254) { content = content.Substring(0, 232) + "[FULL DETAILS IN TICKET]"; } iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(content, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12, iTextSharp.text.Font.NORMAL)); iTextSharp.text.Paragraph b = new iTextSharp.text.Paragraph(); if (ti.isBillable == true) { b = new iTextSharp.text.Paragraph("Billable Hours: " + TimeSpan.Parse(ti.time).TotalHours, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12, iTextSharp.text.Font.NORMAL)); } else { b = new iTextSharp.text.Paragraph("Non-Billable Hours: " + TimeSpan.Parse(ti.time).TotalHours, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12, iTextSharp.text.Font.NORMAL)); } document.Add(h); document.Add(p); document.Add(b); } document.Close(); System.Diagnostics.Process.Start(docName); }
private void AddCartaoSUSCompleto(long numeroCartaoSUS) { ISeguranca iseguranca = Factory.GetInstance<ISeguranca>(); if (!iseguranca.VerificarPermissao(((ViverMais.Model.Usuario)Session["Usuario"]).Codigo, "ALTERAR_CARTAO_SUS", Modulo.CARTAO_SUS)) { ClientScript.RegisterClientScriptBlock(typeof(String), "ok", "<script>alert('Você não tem permissão para acessar essa página. Em caso de dúViverMais, entre em contato.');window.location='../Home.aspx';</script>"); return; } MemoryStream MStream = new MemoryStream(); iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(295, 191)); PdfWriter writer = PdfWriter.GetInstance(doc, MStream); //Monta o pdf doc.Open(); iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph(); p.IndentationLeft = -10; p.Font.Color = iTextSharp.text.Color.BLACK; iTextSharp.text.Phrase nome = new iTextSharp.text.Phrase(HiddenNomePaciente.Value + "\n"); //paciente.Nome nome.Font.Size = 8; iTextSharp.text.Phrase nascimento = new iTextSharp.text.Phrase(HiddenDataNascimento.Value + "\t\t" + HiddenMunicipio.Value + "\n"); nascimento.Font.Size = 8; iTextSharp.text.Phrase cartaosus = new iTextSharp.text.Phrase(numeroCartaoSUS + "\n"); cartaosus.Font.Size = 12; PdfContentByte cb = writer.DirectContent; Barcode39 code39 = new Barcode39(); code39.Code = numeroCartaoSUS.ToString(); code39.StartStopText = true; code39.GenerateChecksum = false; code39.Extended = true; iTextSharp.text.Image imageEAN = code39.CreateImageWithBarcode(cb, null, null); iTextSharp.text.Image back = iTextSharp.text.Image.GetInstance(Server.MapPath("img/") + "back_card.JPG"); back.SetAbsolutePosition(0, doc.PageSize.Height - back.Height); iTextSharp.text.Image front = iTextSharp.text.Image.GetInstance(Server.MapPath("img/") + "front_card.JPG"); front.SetAbsolutePosition(0, doc.PageSize.Height - front.Height); iTextSharp.text.Phrase barcode = new iTextSharp.text.Phrase(new iTextSharp.text.Chunk(imageEAN, 36, -45)); barcode.Font.Color = iTextSharp.text.Color.WHITE; p.SetLeading(1, 0.7f); p.Add(cartaosus); p.Add(nome); p.Add(nascimento); p.Add(barcode); doc.Add(p); doc.Add(back); doc.NewPage(); doc.Add(front); doc.Close(); //Fim monta pdf HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=CartaoSUS.pdf"); HttpContext.Current.Response.BinaryWrite(MStream.GetBuffer()); HttpContext.Current.Response.End(); }