void WriteAlgorithmBenchmark(iTextSharp.text.Document doc, ISearchAlgorithm <string> algorithm, SearchReport <string> report) { iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1); iTextSharp.text.Chunk linebreak = new iTextSharp.text.Chunk(line); Chunk c = new Chunk(algorithm.Name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 24, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)); c.SetGenericTag(algorithm.Name); doc.Add(new Paragraph(c)); // algorithm description Chunk desc = new Chunk(algorithm.Description, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.ITALIC, iTextSharp.text.BaseColor.BLACK)); doc.Add(new Paragraph(desc)); // algorithm benchmark Chunk time = new Chunk("The algorithm took " + report.ElapsedTime + " to find the goal.", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK)); doc.Add(new Paragraph(time)); // path time = new Chunk("The result path costs " + algorithm.CalculateCost(report.Result), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK)); doc.Add(new Paragraph(time)); // write steps foreach (var step in report.Steps) { WriteAlgorithmStep(doc, step.StepInformation, step.GraphCapture); } doc.NewPage(); }
// --------------------------------------------------------------------------- public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 Phrase phrase; Chunk chunk; foreach (Movie movie in PojoFactory.GetMovies()) { phrase = new Phrase(movie.MovieTitle); chunk = new Chunk("\u00a0"); chunk.SetAnnotation(PdfAnnotation.CreateText( writer, null, movie.MovieTitle, string.Format(INFO, movie.Year, movie.Duration), false, "Comment" )); phrase.Add(chunk); document.Add(phrase); document.Add(PojoToElementFactory.GetDirectorList(movie)); document.Add(PojoToElementFactory.GetCountryList(movie)); } } }
// --------------------------------------------------------------------------- /** * Creates the PDF. * @return the bytes of a PDF file. */ public byte[] CreatePdf() { using (MemoryStream ms = new MemoryStream()) { using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, ms); document.Open(); document.Add(new Paragraph( "This is a list of Kubrick movies available in DVD stores." )); IEnumerable<Movie> movies = PojoFactory.GetMovies(1) .Concat(PojoFactory.GetMovies(4)) ; List list = new List(); string RESOURCE = Utility.ResourcePosters; foreach (Movie movie in movies) { PdfAnnotation annot = PdfAnnotation.CreateFileAttachment( writer, null, movie.GetMovieTitle(false), null, Path.Combine(RESOURCE, movie.Imdb + ".jpg"), string.Format("{0}.jpg", movie.Imdb) ); ListItem item = new ListItem(movie.GetMovieTitle(false)); item.Add("\u00a0\u00a0"); Chunk chunk = new Chunk("\u00a0\u00a0\u00a0\u00a0"); chunk.SetAnnotation(annot); item.Add(chunk); list.Add(item); } document.Add(list); } return ms.ToArray(); } }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter.GetInstance(document, stream).InitialLeading = 16; // step 3 document.Open(); // add the ID in another font Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE); // step 4 using (var c = AdoDB.Provider.CreateConnection()) { c.ConnectionString = AdoDB.CS; using (DbCommand cmd = c.CreateCommand()) { cmd.CommandText = "SELECT country,id FROM film_country ORDER BY country"; c.Open(); using (var r = cmd.ExecuteReader()) { while (r.Read()) { var country = r.GetString(0); var ID = r.GetString(1); document.Add(new Chunk(country)); document.Add(new Chunk(" ")); Chunk id = new Chunk(ID, font); // with a background color id.SetBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); // and a text rise id.SetTextRise(6); document.Add(id); document.Add(Chunk.NEWLINE); } } } } } }
/** * Adds an <CODE>Object</CODE> to the <CODE>List</CODE>. * * @param o the object to add. * @return true if adding the object succeeded */ public override bool Add(Object o) { if (o is ListItem) { ListItem item = (ListItem) o; Chunk chunk = new Chunk(preSymbol, symbol.Font); switch (type ) { case 0: chunk.Append(((char)(first + list.Count + 171)).ToString()); break; case 1: chunk.Append(((char)(first + list.Count + 181)).ToString()); break; case 2: chunk.Append(((char)(first + list.Count + 191)).ToString()); break; default: chunk.Append(((char)(first + list.Count + 201)).ToString()); break; } chunk.Append(postSymbol); item.ListSymbol = chunk; item.SetIndentationLeft(symbolIndent, autoindent); item.IndentationRight = 0; list.Add(item); return true; } else if (o is List) { List nested = (List) o; nested.IndentationLeft = nested.IndentationLeft + symbolIndent; first--; list.Add(nested); return true; } else if (o is String) { return this.Add(new ListItem((string) o)); } return false; }
public void AddLeadText(string text) { iText.Chunk chunck = new iText.Chunk(text); chunck.Font = iText.FontFactory.GetFont(baseFont, leadSize, iText.Font.BOLD, iText.BaseColor.BLACK); iText.Paragraph paragraph = new iText.Paragraph(chunck); document.Add(paragraph); }
public void ApplyForText(PdfContentByte cb, IDictionary<String, String> css, Chunk chunk) { SetStrokeAndFillColor(cb, css); SetStrokeAndFill(cb, css); try { Font font = new Font(Font.FontFamily.COURIER, 6, Font.NORMAL, BaseColor.BLACK); Font font2 = chunk.Font; BaseFont bf2 = font2.BaseFont; //BaseFont bf = ; if (bf2 == null) { cb.SetFontAndSize(font.GetCalculatedBaseFont(false), font2.Size); } else { cb.SetFontAndSize(bf2, font2.Size); } } catch { } }
public void AddTable(List <CellRow> tableRows, float[] cellWidths) { iPdf.PdfPTable table = new iPdf.PdfPTable(cellWidths.Length); for (int i = 0; i < cellWidths.Length; i++) { table.AbsoluteWidths[i] = cellWidths[i]; } table.WidthPercentage = 100F; table.SetWidths(cellWidths); table.SpacingBefore = 10F; table.SpacingAfter = 10F; table.SplitRows = false; table.SplitLate = false; table.DefaultCell.Border = 0; // foreach (CellRow row in tableRows) { for (int i = 0; i < row.CellTexts.Length; i++) { iText.Chunk cellChunk = new iText.Chunk(row.CellTexts[i]); cellChunk.Font = iText.FontFactory.GetFont(baseFont, row.IsRowImportant ? leadSize : normalSize, row.CellBolds[i] ? iText.Font.BOLD : iText.Font.NORMAL); iPdf.PdfPCell cell = new iPdf.PdfPCell(new iText.Phrase(cellChunk)); //cell.Width = (float)(cellWidths[i] * (document.PageSize.Width / 100)); cell.Border = iText.Rectangle.NO_BORDER; cell.NoWrap = false; table.AddCell(cell); } } table.SetWidths(cellWidths); document.Add(table); }
public void AddLineNoEmphasis(string text) { iText.Chunk chunck = new iText.Chunk(text); chunck.Font = iText.FontFactory.GetFont(baseFont, smallSize, iText.Font.NORMAL, iText.BaseColor.BLACK); iText.Paragraph paragraph = new iText.Paragraph(chunck); document.Add(paragraph); }
public override void OnEndPage(PdfWriter writer, Document document) { PdfPTable footer = new PdfPTable(3); footer.SetWidths(new float[] { 88f, 7f, 5f }); footer.WidthPercentage = 100; footer.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin); PdfPCell emptycell = new PdfPCell(); emptycell.Border = 0; footer.AddCell(emptycell); Chunk text = new Chunk(string.Format(GlobalStringResource.PageOfFooter, document.PageNumber), FontFactory.GetFont(FontFactory.HELVETICA, 8)); PdfPCell footerCell = new PdfPCell(new Phrase(text)); footerCell.Border = 0; footerCell.HorizontalAlignment = Element.ALIGN_RIGHT; footer.AddCell(footerCell); PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total)); cell.Border = 0; cell.HorizontalAlignment = Element.ALIGN_LEFT; footer.AddCell(cell); footer.WriteSelectedRows(0, -1, 50, (document.BottomMargin - 10), writer.DirectContent); }
// --------------------------------------------------------------------------- /** * Creates a PDF document. * @param stream Stream for the new PDF document */ public void CreatePdf(Stream stream) { string RESOURCE = Utility.ResourcePosters; // step 1 using (Document document = new Document()) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 Phrase phrase; Chunk chunk; PdfAnnotation annotation; foreach (Movie movie in PojoFactory.GetMovies()) { phrase = new Phrase(movie.MovieTitle); chunk = new Chunk("\u00a0\u00a0"); annotation = PdfAnnotation.CreateFileAttachment( writer, null, movie.MovieTitle, null, Path.Combine(RESOURCE, movie.Imdb + ".jpg"), string.Format("img_{0}.jpg", movie.Imdb) ); annotation.Put(PdfName.NAME, new PdfString("Paperclip")); chunk.SetAnnotation(annotation); phrase.Add(chunk); document.Add(phrase); document.Add(PojoToElementFactory.GetDirectorList(movie)); document.Add(PojoToElementFactory.GetCountryList(movie)); } } }
public static IT.Chunk GetFormattedText(Text text) { IT.Chunk formattedChuck = new IT.Chunk(text.TextContent); formattedChuck.Font = GetFormattedFont(text.Font); return formattedChuck; }
public override iTextSharp.text.IElement GeneratePdfElement() { ChunkStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style; iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(Text, (iText.Font)style.Font); return chunk; }
public void Go() { // GetClassOutputPath() implementation left out for brevity var outputFile = Helpers.IO.GetClassOutputPath(this); using (FileStream stream = new FileStream( outputFile, FileMode.Create, FileAccess.Write)) { Random random = new Random(); StreamUtil.AddToResourceSearch(("iTextAsian.dll")); string chunkText = " 你好世界 你好你好,"; var font = new Font(BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12); using (Document document = new Document()) { PdfWriter.GetInstance(document, stream); document.Open(); Phrase phrase = new Phrase(); Chunk chunk = new Chunk("", font); for (var i = 0; i < 1000; ++i) { var asterisk = new String('*', random.Next(1, 20)); chunk.Append( string.Format("[{0}] {1} ", asterisk, chunkText) ); } chunk.SetSplitCharacter(new CustomSplitCharacter()); phrase.Add(chunk); document.Add(phrase); } } }
// public static SimpleAttendanceList GetInstance(Selection selection, // Rectangle pageSize, // string reportFile) { // // if (instance == null) // instance = new SimpleAttendanceList(selection, pageSize, reportFile); // else { // instance.selection = selection; // instance.reportFile = reportFile; // } // // if (!this.doc.IsOpen()) // this.doc.Open(); // // return instance; // } public override void MakeReport() { // Subtitle = Event name Chunk c = new Chunk(this.selection.Events[0].Name, FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.BOLD)); Paragraph par = new Paragraph(c); par.Alignment = Rectangle.ALIGN_CENTER; this.doc.Add(par); // List Table t = new Table(2); t.Border = 0; t.DefaultCellBorder = 0; Cell cell = new Cell(); cell.HorizontalAlignment = Element.ALIGN_CENTER; t.DefaultCell = cell; // Default cell Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE); cell = new Cell(); Chunk texto = new Chunk("Nombre y Apellido", fuenteTitulo); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk("¿Asistió?", fuenteTitulo); cell.Add(texto); t.AddCell(cell); Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10); Font fuenteSi = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10); fuenteSi.Color = Color.BLUE; Font fuenteNo = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10); fuenteNo.Color = Color.RED; foreach (Person p in this.selection.Persons) { cell = new Cell(); texto = new Chunk(p.Name + " " + p.Surname, fuenteDatos); cell.Add(texto); t.AddCell(cell); cell = new Cell(); if (AttendancesManager.Instance.Attended(p, this.selection.Events[0])) texto = new Chunk("Si", fuenteSi); else texto = new Chunk("No", fuenteNo); cell.Add(texto); t.AddCell(cell); } this.doc.Add(t); }
public void SetUp() { LoggerFactory.GetInstance().SetLogger(new SysoLogger(3)); t = new Tag(null); t.CSS["color"] = "#000000"; t.CSS["font-family"] = "Helvetica"; t.CSS["font-size"] = "12pt"; c = new Chunk("default text for chunk creation"); applier.Apply(c, t); }
public void ResolveDoubleQuotedFontFamily() { Tag t = new Tag(null); t.CSS["color"] = "#000000"; t.CSS["font-family"] = "\"Helvetica\""; t.CSS["font-size"] = "12pt"; Chunk c = new Chunk("default text for chunk creation"); applier.Apply(c, t); Assert.AreEqual("Helvetica", c.Font.Familyname); }
public Text(Chunk chunk, IDictionary<String, String> css, IList<int> dx, IList<int> dy) : base(css) { this.chunk = chunk; this.x = 0; this.y = 0; this.relative = true; this.dx = dx; this.dy = dy; }
virtual public void SetUp() { t = new Tag("root"); sk = new StackKeeper(t); a = new Chunk("a"); sk.Add(a); b = new Chunk("b"); sk.Add(b); c = new Chunk("c"); sk.Add(c); }
public Text(Chunk chunk, float x, float y, IDictionary<String, String> css, IList<int> dx, IList<int> dy) : base(css) { this.chunk = chunk; this.x = x; this.y = y; this.relative = false; this.dx = dx; this.dy = dy; }
private iText.Phrase MakePhrase(string lead, string text) { iText.Chunk leadChunk = new iText.Chunk(lead); leadChunk.Font = iText.FontFactory.GetFont(baseFont, normalSize, iText.Font.BOLD); iText.Chunk textChunck = new iText.Chunk(text); iText.Phrase phrase = new iText.Phrase(); phrase.Add(leadChunk); phrase.Add(textChunck); return(phrase); }
public void ResolveFontSize() { Tag t = new Tag("t"); t.CSS["font-size"] = "12pt"; Chunk c = new Chunk("default text with no styles attached."); c = new ChunkCssApplier().Apply(c, t); Assert.AreEqual(12, c.Font.Size, 0); t.CSS["font-size"] = "18pt"; c = new ChunkCssApplier().Apply(c, t); Assert.AreEqual(18, c.Font.Size, 0); }
public static Paragraph ParaCommonInfoAllBold(string field, string value) { Paragraph pr = new Paragraph(); Phrase phr = new Phrase(); Chunk chk1 = new Chunk(field, FontConfig.BoldFont); Chunk chk2 = new Chunk(value, FontConfig.BoldFont); phr.Add(chk1); phr.Add(chk2); pr.Add(phr); return pr; }
public void ResolveHorizontalAndVerticalScaling() { t.CSS["xfa-font-vertical-scale"] = "75pt"; Assert.AreEqual(1, c.HorizontalScaling, 0); t.CSS["xfa-font-horizontal-scale"] = "75%"; c = applier.Apply(c, t); Assert.AreEqual(0.75f, c.HorizontalScaling, 0); t.CSS["xfa-font-vertical-scale"] = "75%"; c = applier.Apply(c, t); Assert.AreEqual(9, c.Font.Size, 0); Assert.AreEqual(100f / 75f, c.HorizontalScaling, 1e-7); }
public override void DrawItem(PdfWriter pdfWriter, ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter) { if (pdfWriter == null) { throw new ArgumentNullException("pdfWriter"); } if (converter == null) { throw new ArgumentNullException("converter"); } base.DrawItem(pdfWriter,converter); iTextSharp.text.Font font = null; if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point) { font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name, BaseFont.IDENTITY_H, this.StyleDecorator.Font.Size, (int)this.StyleDecorator.Font.Style, this.StyleDecorator.PdfForeColor); } else { font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name, BaseFont.IDENTITY_H, UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point, (int)this.StyleDecorator.Font.Style, this.StyleDecorator.PdfForeColor); } base.Decorate(); PdfContentByte contentByte = base.PdfWriter.DirectContent; CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator,font); ColumnText columnText = new ColumnText(contentByte); iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle(); columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Top - r.Height,pdfFormat.Leading,pdfFormat.Alignment); string formatedText = this.text; if (!String.IsNullOrEmpty(StyleDecorator.FormatString)) { formatedText = StandardFormatter.FormatOutput(this.text,this.StyleDecorator.FormatString, this.StyleDecorator.DataType,String.Empty); } Chunk chunk = new Chunk(formatedText,font); columnText.AddText(chunk); columnText.Go(); }
public Chunk CreateChunk(String text, ChainedProperties props) { Font font = GetFont(props); float size = font.Size; size /= 2; Chunk ck = new Chunk(text, font); if (props.HasProperty("sub")) ck.SetTextRise(-size); else if (props.HasProperty("sup")) ck.SetTextRise(size); ck.SetHyphenation(GetHyphenation(props)); return ck; }
public void ResolveColor() { Assert.AreEqual(BaseColor.BLACK, c.Font.Color); t.CSS["color"] = "#00f"; c = applier.Apply(c, t); Assert.AreEqual(255, c.Font.Color.B, 0); t.CSS["color"] = "#00ff00"; c = applier.Apply(c, t); Assert.AreEqual(255, c.Font.Color.G, 0); t.CSS["color"] = "rgb(255,0,0)"; c = applier.Apply(c, t); Assert.AreEqual(255, c.Font.Color.R, 0); }
internal void AddItemLine(string item, string subItems) { iText.Chunk itemChunck = new iText.Chunk(item); itemChunck.Font = iText.FontFactory.GetFont(baseFont, leadSize, iText.Font.BOLD, iText.BaseColor.BLACK); iText.Chunk subItemsChunck = new iText.Chunk(subItems); subItemsChunck.Font = iText.FontFactory.GetFont(baseFont, normalSize, iText.Font.NORMAL, iText.BaseColor.BLACK); iText.Phrase phrase = new iText.Phrase(); phrase.Add(itemChunck); phrase.Add(subItemsChunck); iText.Paragraph paragraph = new iText.Paragraph(phrase); document.Add(paragraph); }
private void btnPrint_Click(object sender, EventArgs e) { // Create a Document object var document = new Document(PageSize.A4, 50, 50, 25, 25); string file = "Choo.pdf"; // Create a new PdfWriter object, specifying the output stream var output = new MemoryStream(); //var writer = PdfWriter.GetInstance(document, output); var writer = PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create)); // Open the Document for writing document.Open(); var titleFont = FontFactory.GetFont("Arial", 18); var subTitleFont = FontFactory.GetFont("Arial", 14); var boldTableFont = FontFactory.GetFont("Arial", 12); var endingMessageFont = FontFactory.GetFont("Arial", 10); var bodyFont = FontFactory.GetFont("Arial", 12); //document.Add(new Paragraph("Northwind Traders Receipt", titleFont); Paragraph tit = new Paragraph(); Chunk c1 = new Chunk(" Ingresos Diarios \n", titleFont); Chunk c2 = new Chunk("Ciclo Escolar 2012 - 2013 \n"); Chunk c3 = new Chunk("Dia consultado : 25/01/2013"); tit.Add(c1); tit.Add(c2); tit.Add(c3); tit.IndentationLeft = 200f; document.Add(tit); PdfContentByte cb = writer.DirectContent; cb.MoveTo(50, document.PageSize.Height / 2); cb.LineTo(document.PageSize.Width - 50, document.PageSize.Height / 2); cb.Stroke(); var orderInfoTable = new PdfPTable(2); orderInfoTable.HorizontalAlignment = 0; orderInfoTable.SpacingBefore = 10; orderInfoTable.SpacingAfter = 10; orderInfoTable.DefaultCell.Border = 0; orderInfoTable.SetWidths(new int[] { 1, 4 }); orderInfoTable.AddCell(new Phrase("Order:", boldTableFont)); orderInfoTable.AddCell("textorder"); orderInfoTable.AddCell(new Phrase("Price:", boldTableFont)); orderInfoTable.AddCell(Convert.ToDecimal(444444).ToString("c")); document.Add(orderInfoTable); document.Close(); System.Diagnostics.Process.Start(file); }
// --------------------------------------------------------------------------- /** * Creates a Phrase with the name and given name of a director using different fonts. * @param rs the ResultSet containing director records. */ protected override Phrase CreateDirectorPhrase(DbDataReader r) { Phrase director = new Phrase(); Chunk name = new Chunk(r["name"].ToString(), BOLD); name.SetUnderline(0.2f, -2f); director.Add(name); director.Add(new Chunk(",", BOLD)); director.Add(new Chunk(" ", NORMAL)); director.Add( new Chunk(r["given_name"].ToString(), NORMAL) ); director.Leading = 24; return director; }
public void AddLine(string text, bool important) { iText.Chunk chunck = new iText.Chunk(text); if (important) { chunck.Font = iText.FontFactory.GetFont(baseFont, leadSize, iText.Font.BOLD, iText.BaseColor.BLACK); } else { chunck.Font = iText.FontFactory.GetFont(baseFont, normalSize, iText.Font.NORMAL, iText.BaseColor.BLACK); } iText.Paragraph paragraph = new iText.Paragraph(chunck); document.Add(paragraph); }
public static Chunk GetChunk(Properties attributes) { Chunk chunk = new Chunk(); chunk.Font = FontFactory.GetFont(attributes); String value; value = attributes[ElementTags.ITEXT]; if (value != null) { chunk.Append(value); } value = attributes[ElementTags.LOCALGOTO]; if (value != null) { chunk.SetLocalGoto(value); } value = attributes[ElementTags.REMOTEGOTO]; if (value != null) { String page = attributes[ElementTags.PAGE]; if (page != null) { chunk.SetRemoteGoto(value, int.Parse(page)); } else { String destination = attributes[ElementTags.DESTINATION]; if (destination != null) { chunk.SetRemoteGoto(value, destination); } } } value = attributes[ElementTags.LOCALDESTINATION]; if (value != null) { chunk.SetLocalDestination(value); } value = attributes[ElementTags.SUBSUPSCRIPT]; if (value != null) { chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo)); } value = attributes[Markup.CSS_KEY_VERTICALALIGN]; if (value != null && value.EndsWith("%")) { float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f; chunk.SetTextRise(p * chunk.Font.Size); } value = attributes[ElementTags.GENERICTAG]; if (value != null) { chunk.SetGenericTag(value); } value = attributes[ElementTags.BACKGROUNDCOLOR]; if (value != null) { chunk.SetBackground(Markup.DecodeColor(value)); } return chunk; }
// // public static SimplePersonsList GetInstance(Selection selection, // Rectangle pageSize, // string reportFile) { // // if (instance == null) // instance = new SimplePersonsList(selection, pageSize, reportFile); // else { // instance.selection = selection; // instance.reportFile = reportFile; // } // // if (!this.doc.IsOpen()) // this.doc.Open(); // // return instance; // } public override void MakeReport() { Table t = new Table(3); t.Border = 0; t.DefaultCellBorder = 0; Cell cell = new Cell(); cell.HorizontalAlignment = Element.ALIGN_CENTER; t.DefaultCell = cell; // Default cell Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE); cell = new Cell(); Chunk texto = new Chunk("Apellido", fuenteTitulo); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk("Nombre", fuenteTitulo); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk("E-Mail", fuenteTitulo); cell.Add(texto); t.AddCell(cell); Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10); foreach (Person p in this.selection.Persons) { cell = new Cell(); texto = new Chunk(p.Surname, fuenteDatos); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk(p.Name, fuenteDatos); cell.Add(texto); t.AddCell(cell); cell = new Cell(); texto = new Chunk(p.EMail, fuenteDatos); cell.Add(texto); t.AddCell(cell); } this.doc.Add(t); }
public void ResolveVerticalAlign() { Assert.AreEqual(0, c.GetTextRise(), 0); t.CSS["vertical-align"] = "5pt"; c = applier.Apply(c, t); Assert.AreEqual(5, c.GetTextRise(), 0); t.CSS["vertical-align"] = "sub"; c = applier.Apply(c, t); Assert.AreEqual(12, c.Font.Size, 0); Assert.AreEqual(-c.Font.Size/2, c.GetTextRise(), 0); t.CSS["vertical-align"] = "super"; c = applier.Apply(c, t); Assert.AreEqual(12, c.Font.Size, 0); Assert.AreEqual(c.Font.Size/2 + 0.5, c.GetTextRise(), 0); }
void WriteHeader(iTextSharp.text.Document doc) { 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("Graph", 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("SEA", 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)); // add front page doc.Add(new Paragraph(new iTextSharp.text.Chunk("GraphSEA", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 72, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156))))); doc.Add(new Paragraph(new iTextSharp.text.Chunk("Graph Search Algorithms Benchmark Report", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK)))); }
public void SetHeader(DateTime data, string casa, string tipoEvento, string homenageados, int pax, string horario, string cerimonial, string produtor, string contatoProdutor, string assessoria, string contatoAssessoria, string responsavel, string contatoResponsavel, string perfil) { header = new iPdf.PdfPTable(3); header.WidthPercentage = 100F; header.SetWidths(new float[] { 1F, 1F, 1F }); header.SpacingBefore = 10F; header.SpacingAfter = 10F; iText.Chunk headChunk = new iText.Chunk( string.Format("{0} > {1} > {2} > {3}", data.ToString("dd/MM/yyyy"), casa, tipoEvento, homenageados)); headChunk.Font = iText.FontFactory.GetFont(baseFont, leadSize, iText.Font.BOLD); iPdf.PdfPCell headerCell = new iPdf.PdfPCell(new iText.Phrase(headChunk)); headerCell.Colspan = 3; header.AddCell(headerCell); header.AddCell(new iPdf.PdfPCell(MakePhrase("Pax: ", string.Format("{0} +10% ({1})", pax, (int)(pax * 1.1))))); header.AddCell(new iPdf.PdfPCell(MakePhrase("Horário:", horario))); header.AddCell(new iPdf.PdfPCell(MakePhrase("Cerimonial: ", cerimonial))); iPdf.PdfPCell detailCell = new iPdf.PdfPCell(MakePhrase("Observações: ", perfil)); detailCell.Rowspan = 3; header.AddCell(new iPdf.PdfPCell(detailCell)); header.AddCell(new iPdf.PdfPCell(MakePhrase("Produtor(a): ", produtor))); header.AddCell(new iPdf.PdfPCell(MakePhrase("Contato: ", contatoProdutor))); header.AddCell(new iPdf.PdfPCell(MakePhrase("Assessoria: ", assessoria))); if (string.IsNullOrEmpty(contatoAssessoria)) { header.AddCell(new iPdf.PdfPCell(new iText.Phrase(""))); } else { header.AddCell(new iPdf.PdfPCell(MakePhrase("Contato: ", contatoAssessoria))); } header.AddCell(new iPdf.PdfPCell(MakePhrase("Responsável(a): ", responsavel))); header.AddCell(new iPdf.PdfPCell(MakePhrase("Contato: ", contatoResponsavel))); }
public IActionResult OnPostWay4(Venda data) { byte[] result; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { //creating a sample Document iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 30f, 30f, 30f, 30f); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms); doc.Open(); doc.Add(Image.GetInstance(new Uri(_host.WebRootPath + "/images/les_logo.jpg"))); doc.Add(new Chunk("\n")); var b = new iTextSharp.text.Chunk("LES_passagens_aereas"); b.Font.Color = BaseColor.Red; doc.Add(b); var bb = new Table(3); var bh = new Cell("partida"); bh.Header = true; bb.AddCell(bh); bh = new Cell("chegada"); bh.Header = true; bb.AddCell(bh); bh = new Cell("tempo partida"); bh.Header = true; bb.AddCell(bh); for (int i = 0; i < data.Viagems.Count; i++) { bb.AddCell(new Cell(data.Viagems.ElementAt(i).Voo.LO_partida.Nome), i + 1, 0); bb.AddCell(new Cell(data.Viagems.ElementAt(i).Voo.LO_chegada.Nome), i + 1, 1); bb.AddCell(new Cell(data.Viagems.ElementAt(i).Voo.DT_partida.ToString("dd/MM/yyyy HH:mm")), i + 1, 2); } doc.Add(bb); doc.Close(); result = ms.ToArray(); } return(this.File(result, "application/pdf")); }
/// <summary> /// Constructs a ListItem with a certain Chunk. /// </summary> /// <param name="chunk">a Chunk</param> public ListItem(Chunk chunk) : base(chunk) { Role = PdfName.LI; }
public void AddImage(Dictionary <string, string> images) { //if (images.Count == 0) // return; //iPdf.PdfPTable table = new iPdf.PdfPTable(2); //table.SplitLate = true; //table.KeepTogether = true; //table.WidthPercentage = 100F; //table.SetWidths(new float[] { 50F, 50F }); //table.SpacingBefore = 10F; //table.SpacingAfter = 10F; //table.DefaultCell.Border = iText.Rectangle.NO_BORDER; //foreach(string path in images.Keys) //{ // iPdf.PdfPTable imageTable = new iPdf.PdfPTable(1); // imageTable.WidthPercentage = 100F; // imageTable.SetWidths(new float[] { 1F }); // imageTable.SpacingBefore = 2F; // imageTable.SpacingAfter = 2F; // imageTable.SplitLate = true; // iText.Image image = iText.Image.GetInstance(path); // image.Alignment = iText.Image.ALIGN_LEFT; // iPdf.PdfPCell imageCell = new iPdf.PdfPCell(image, true); // imageTable.AddCell(imageCell); // iText.Chunk chunk = new iText.Chunk(images[path]); // chunk.Font = iText.FontFactory.GetFont(baseFont, normalSize, iText.BaseColor.DARK_GRAY); // iPdf.PdfPCell titleCell = new iPdf.PdfPCell(new iText.Phrase(chunk)); // imageTable.AddCell(titleCell); // table.AddCell(imageTable); //} //table.AddCell(""); //document.Add(table); if (images.Count == 0) { return; } foreach (string path in images.Keys) { iPdf.PdfPTable imageTable = new iPdf.PdfPTable(1); imageTable.WidthPercentage = 55F; imageTable.SetWidths(new float[] { 1F }); imageTable.SpacingBefore = 0F; imageTable.SpacingAfter = 0F; imageTable.SplitLate = true; imageTable.KeepTogether = true; imageTable.DefaultCell.Border = iText.Rectangle.NO_BORDER; iText.Image image = iText.Image.GetInstance(path); image.Alignment = iText.Image.ALIGN_LEFT; iPdf.PdfPCell imageCell = new iPdf.PdfPCell(image, true); imageTable.AddCell(imageCell); iText.Chunk chunk = new iText.Chunk(images[path]); chunk.Font = iText.FontFactory.GetFont(baseFont, normalSize, iText.BaseColor.DARK_GRAY); iPdf.PdfPCell titleCell = new iPdf.PdfPCell(new iText.Phrase(chunk)); imageTable.AddCell(titleCell); imageTable.AddCell(" "); document.Add(imageTable); } }
virtual public void PrependingWhitspaces() { Chunk c = new Chunk(_4SPACES); Assert.AreEqual(_4SPACES, c.Content, "difference in string"); }
virtual public void PrependingTab() { Chunk c = new Chunk(_TAB); Assert.AreEqual("4spaces ", c.Content, "difference in string"); }
/// <summary> /// Constructs a Paragraph with a certain Chunk /// and a certain leading. /// </summary> /// <param name="leading">the leading</param> /// <param name="chunk">a Chunk</param> public Paragraph(float leading, Chunk chunk) : base(leading, chunk) { }
/// <summary> /// Constructs a ListItem with a certain Chunk /// and a certain leading. /// </summary> /// <param name="leading">the leading</param> /// <param name="chunk">a Chunk</param> public ListItem(float leading, Chunk chunk) : base(leading, chunk) { Role = PdfName.LI; }
/// <summary> /// Constructs a ListItem with a certain Chunk. /// </summary> /// <param name="chunk">a Chunk</param> public ListItem(Chunk chunk) : base(chunk) { }
/// <summary> /// Constructs a ListItem with a certain Chunk /// and a certain leading. /// </summary> /// <param name="leading">the leading</param> /// <param name="chunk">a Chunk</param> public ListItem(float leading, Chunk chunk) : base(leading, chunk) { }
/// <summary> /// Constructs an Anchor with a certain Chunk. /// </summary> /// <param name="chunk">a Chunk</param> public Anchor(Chunk chunk) : base(chunk) { }
/// <summary> /// Constructs a Paragraph with a certain Chunk. /// </summary> /// <param name="chunk">a Chunk</param> public Paragraph(Chunk chunk) : base(chunk) { }
/// <summary> /// Constructs an Anchor with a certain Chunk /// and a certain leading. /// </summary> /// <param name="leading">the leading</param> /// <param name="chunk">a Chunk</param> public Anchor(float leading, Chunk chunk) : base(leading, chunk) { }
private void bntSavePdf_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog() { FileName = comboBox1.Text + ".pdf", ValidateNames = true }) { if (sfd.ShowDialog() == DialogResult.OK) { iTextSharp.text.Rectangle bussinessCard = new iTextSharp.text.Rectangle(241, 156); Document doc = new Document(PageSize.A7); doc.SetMargins(14.2f, 0, 0, 0); //doc.SetMargins(14.5f, 14, 0, 0); doc.SetPageSize(bussinessCard); iTextSharp.text.Font font_01 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gill Sans.ttf", 9, BaseColor.BLACK); font_01.BaseFont.IsEmbedded(); iTextSharp.text.Font font_02 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gill Sans.ttf", 7, BaseColor.BLACK); font_02.BaseFont.IsEmbedded(); iTextSharp.text.Font font_03 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gnl____.ttf", 7, BaseColor.BLACK); font_03.BaseFont.IsEmbedded(); iTextSharp.text.Font font_04 = FontFactory.GetFont("C:\\Windows\\Fonts\\Gnl____.ttf", 5, BaseColor.BLACK); font_04.BaseFont.IsEmbedded(); iTextSharp.text.Chunk C00 = new iTextSharp.text.Chunk(" ", font_01); iTextSharp.text.Chunk C01 = new iTextSharp.text.Chunk(tbName.Text + " ", font_01); iTextSharp.text.Chunk C02 = new iTextSharp.text.Chunk(tbTitle.Text + " ", font_02); iTextSharp.text.Chunk C03 = new iTextSharp.text.Chunk(tbQuaifications.Text + " ", font_02); iTextSharp.text.Chunk C04 = new iTextSharp.text.Chunk(tbTelephone.Text + " ", font_03); iTextSharp.text.Chunk C05 = new iTextSharp.text.Chunk(tbMobile.Text + " ", font_03); iTextSharp.text.Chunk C06 = new iTextSharp.text.Chunk(tbEmail.Text + " ", font_03); iTextSharp.text.Chunk C07 = new iTextSharp.text.Chunk(tbComName.Text, font_04); iTextSharp.text.Chunk C08 = new iTextSharp.text.Chunk(tbRegNo.Text, font_04); iTextSharp.text.Chunk C09 = new iTextSharp.text.Chunk(tbOffice.Text, font_03); iTextSharp.text.Chunk C10 = new iTextSharp.text.Chunk(tbStreet.Text, font_03); iTextSharp.text.Chunk C11 = new iTextSharp.text.Chunk(tbArea.Text, font_03); iTextSharp.text.Chunk C12 = new iTextSharp.text.Chunk(tbRegion.Text, font_03); iTextSharp.text.Chunk C13 = new iTextSharp.text.Chunk(tbPostalCode.Text, font_03); iTextSharp.text.Chunk C14 = new iTextSharp.text.Chunk(tbWeb.Text, font_03); Paragraph pa00 = new iTextSharp.text.Paragraph(); pa00.Add(C00); Paragraph pa01 = new iTextSharp.text.Paragraph(); pa01.Add(C01); pa01.SpacingBefore = 37.5f; Paragraph pa02 = new iTextSharp.text.Paragraph(); pa02.Add(C02); pa02.SpacingBefore = -7f; Paragraph pa03 = new iTextSharp.text.Paragraph(); pa03.Add(C03); pa03.SpacingBefore = -7f; Paragraph pa04 = new iTextSharp.text.Paragraph(); pa04.Add(C04); pa04.SpacingBefore = 1.6f; Paragraph pa05 = new iTextSharp.text.Paragraph(); pa05.Add(C05); pa05.SpacingBefore = -6.9f; Paragraph pa06 = new iTextSharp.text.Paragraph(); pa06.Add(C06); pa06.SpacingBefore = -6.9f; Paragraph pa07 = new iTextSharp.text.Paragraph(); pa07.Add(C07); pa07.SpacingBefore = -3f; Paragraph pa08 = new iTextSharp.text.Paragraph(); pa08.Add(C08); pa08.SpacingBefore = 11f; Paragraph pa09 = new iTextSharp.text.Paragraph(); pa09.Add(C09); pa09.SpacingBefore = -74f; pa09.IndentationLeft = 127f; Paragraph pa10 = new iTextSharp.text.Paragraph(); pa10.Add(C10); pa10.SpacingBefore = -7f; pa10.IndentationLeft = 127f; Paragraph pa11 = new iTextSharp.text.Paragraph(); pa11.Add(C11); pa11.IndentationLeft = 127f; pa11.SpacingBefore = -7f; Paragraph pa12 = new iTextSharp.text.Paragraph(); pa12.Add(C12); pa12.IndentationLeft = 127f; pa12.SpacingBefore = -7f; Paragraph pa13 = new iTextSharp.text.Paragraph(); pa13.Add(C13); pa13.IndentationLeft = 127f; pa13.SpacingBefore = -7f; Paragraph pa14 = new iTextSharp.text.Paragraph(); pa14.Add(C14); pa14.IndentationLeft = 127f; pa14.SpacingBefore = 11f; iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("Logo.jpg"); logo.Alignment = iTextSharp.text.Image.UNDERLYING; logo.ScaleAbsolute(241, 156); logo.SetAbsolutePosition(0, 0); try { PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create)); doc.Open(); if (checkBox1.Checked) { doc.Add(logo); } //doc.Add(logo); doc.Add(pa00); doc.Add(pa01); doc.Add(pa02); doc.Add(pa03); doc.Add(pa04); doc.Add(pa05); doc.Add(pa06); doc.Add(pa07); //doc.Add(pa08); doc.Add(pa09); doc.Add(pa10); doc.Add(pa11); doc.Add(pa12); doc.Add(pa13); doc.Add(pa08); //doc.Add(logo); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { doc.Close(); } } } }
public void VeriCekme() { int kayitSayisi = -1; baglanti = new SqlConnection(@"server=.\SQLEXPRESS;database=SoruBankasi;Trusted_Connection=yes"); a = Convert.ToInt32(textBox1.Text); Random rnd = new Random(); SqlCommand cmd = new SqlCommand("select count(*) from Soru", baglanti); baglanti.Open(); kayitSayisi = Convert.ToInt32(cmd.ExecuteScalar()); baglanti.Close(); int[] sayilar = new int[a]; for (int i = 0; i < a; i++) { int x = rnd.Next(1, kayitSayisi + 1); if (!sayilar.Contains(x)) { sayilar[i] = x; } else { while (true) { int yenix = rnd.Next(1, kayitSayisi + 1); if (!sayilar.Contains(yenix)) { sayilar[i] = yenix; break; } } } } baglanti = new SqlConnection(@"server=.\SQLEXPRESS;database=SoruBankasi;Trusted_Connection=yes"); baglanti.Open(); cmd = new SqlCommand("Select *From Soru", baglanti); dr = cmd.ExecuteReader(); baglanti.Close(); BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.EMBEDDED); iTextSharp.text.Font text = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL); iTextSharp.text.Document list = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 10f, 0f); iTextSharp.text.Paragraph prag = new iTextSharp.text.Paragraph(); iTextSharp.text.Document list1 = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 10f, 0f); iTextSharp.text.Chunk c = new iTextSharp.text.Chunk(); PdfWriter.GetInstance(list, new FileStream("C:Çıktı.Pdf", FileMode.Create)); PdfWriter.GetInstance(list1, new FileStream("C:CevapAnahtarı.Pdf", FileMode.Create)); //Ekleyeceğimiz resmi Image nesnemize atıyoruz. iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("Koala.jpg"); iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance("Header.png"); img1.SpacingBefore = 10f; img1.SpacingAfter = 1f; img1.ScaleToFit(300, 100); img1.Alignment = Element.ALIGN_CENTER; img.Alignment = Element.ALIGN_CENTER; prag.IndentationLeft = 15; //Boyutlandırma için ScaleToFit() methodunu ya da ScalePercent() methodunu kullanabiliriz. img.ScaleToFit(200, 100); prag.Add(c); PdfPTable pdfTableBlank = new PdfPTable(1); //Footer Section PdfPTable pdfTableFooter = new PdfPTable(1); pdfTableFooter.DefaultCell.BorderWidth = 0; pdfTableFooter.WidthPercentage = 100; pdfTableFooter.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; //Chunk cnkFooter = new Chunk("DEMO ENTERPRISE", FontFactory.GetFont("Times New Roman")); ////cnkFooter.Font.SetStyle(1); //cnkFooter.Font.Size = 10; //pdfTableFooter.AddCell(new Phrase(cnkFooter)); //End Of Footer Section //pdfTableBlank.AddCell(new Phrase(" ")); pdfTableBlank.DefaultCell.Border = 0; PdfPTable pdfTable1 = new PdfPTable(1);//Here 1 is Used For Count of Column PdfPTable pdfTable2 = new PdfPTable(1); PdfPTable pdfTable3 = new PdfPTable(2); //Font Style System.Drawing.Font fontH1 = new System.Drawing.Font("Currier", 16); //pdfTable1.DefaultCell.Padding = 5; pdfTable1.WidthPercentage = 50; pdfTable1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; pdfTable1.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER; //pdfTable1.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(64, 134, 170); pdfTable1.DefaultCell.BorderWidth = 0; //pdfTable1.DefaultCell.Padding = 5; pdfTable2.WidthPercentage = 80; pdfTable2.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; pdfTable2.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER; //pdfTab2e1.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(64, 134, 170); pdfTable2.DefaultCell.BorderWidth = 0; pdfTable3.DefaultCell.Padding = 1; pdfTable3.WidthPercentage = 50; pdfTable3.DefaultCell.BorderWidth = 0.0f; Chunk c1 = new Chunk("Sakarya Üniversitesi", FontFactory.GetFont("Times New Roman")); c1.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0); c1.Font.SetStyle(0); c1.Font.Size = 14; Phrase p1 = new Phrase(); p1.Add(c1); pdfTable1.AddCell(p1); Chunk c2 = new Chunk("Bilgisayar ve Bilişim Bilimleri Fakültesi", FontFactory.GetFont("Times New Roman")); c2.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0); c2.Font.SetStyle(0);//0 For Normal Font c2.Font.Size = 11; Phrase p2 = new Phrase(); p2.Add(c2); pdfTable2.AddCell(p2); Chunk c3 = new Chunk(comboBox3.Text + " Dersi", FontFactory.GetFont("Times New Roman")); c3.Font.Color = new iTextSharp.text.BaseColor(0, 0, 0); c3.Font.SetStyle(0); c3.Font.Size = 11; Phrase p3 = new Phrase(); p3.Add(c3); pdfTable2.AddCell(p3); //pdfTable3.AddCell(new Phrase("Adı Soyadı: ")); //pdfTable3.AddCell(new Phrase("")); //pdfTable3.AddCell(new Phrase("Numara: ")); //pdfTable3.AddCell(new Phrase("")); //pdfTable3.AddCell(new Phrase("Grup :")); //pdfTable3.AddCell(new Phrase("")); //pdfTable3.AddCell(new Phrase(" Imza :")); //pdfTable3.AddCell(new Phrase("")); list.Open(); prag.Add(pdfTable1); prag.Add(pdfTable2); prag.Add(pdfTableBlank); prag.Add(pdfTable3); prag.Add(new Phrase("Adı Soyadı: \n")); prag.Add(new Phrase("")); prag.Add(new Phrase("Numara: \n")); prag.Add(new Phrase("")); prag.Add(new Phrase("Grup :\n")); prag.Add(new Phrase("")); prag.Add(new Phrase("Imza :\n")); prag.Add(new Phrase("")); prag.Add(pdfTableFooter); //Çerçeve vermek için aşağıdaki özelliklerini kullanabiliriz. //img.Border = iTextSharp.text.Rectangle.BOX; //img.BorderColor = iTextSharp.text.BaseColor.BLACK; //img.BorderWidth = 5f; //Sonrasında diğer nesnelerdeki gibi Document içine yada Paragraph içerisine ekleyebiliriz. // for (int i = 0; i < a; i++) { baglanti.Open(); list.Open(); list1.Open(); list.Add(img1); cmd = new SqlCommand("SELECT Soru FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string soru = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevap FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevap = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevapA FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevapA = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevapB FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevapB = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevapC FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevapC = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevapD FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevapD = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); cmd = new SqlCommand("SELECT cevapE FROM Soru WHERE SoruID='" + sayilar[i] + "'"); cmd.Connection = baglanti; string cevapE = cmd.ExecuteScalar().ToString(); baglanti.Close(); baglanti.Open(); //cmd =new SqlCommand("select soruResmi from Soru where soruID='"+sayilar[i]+"'",baglanti); //string resimb = cmd.ExecuteScalar().ToString(); //byte[] resima = Convert.ToString(resimb); baglanti = new SqlConnection(@"server=.\SQLEXPRESS;database=SoruBankasi;Trusted_Connection=yes"); SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT soruResmi FROM Soru WHERE SoruID ='" + sayilar[i] + "'", baglanti)); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 1) { //Byte[] data = new Byte[0]; byte[] Resim = (dataSet.Tables[0].Rows[0]["soruResmi"]) as byte[] ?? null; if (Resim != null) { //data = (Byte[])(dataSet.Tables[0].Rows[0]["soruResmi"]); MemoryStream mem = new MemoryStream(Resim); pictureBox1.Image = System.Drawing.Image.FromStream(mem); pictureBox1.Image.Save(@"C:'" + i + "'.jpeg", ImageFormat.Jpeg); iTextSharp.text.Image soruresmi = iTextSharp.text.Image.GetInstance("'" + i + "'.jpeg"); soruresmi.ScaleToFit(300, 150); soruresmi.Alignment = Element.ALIGN_CENTER; prag.Add(soruresmi); } pictureBox1.Hide(); } baglanti.Close(); //list.Add(new Paragraph("Sakarya Üniversitesi")); //prag.Add(img); prag.Add(new Paragraph(i + 1 + ".Soru: " + soru)); list1.Add(new Paragraph(i + 1 + ".Soru: " + soru)); list1.Add(new Paragraph("Cevap:" + cevap)); list1.Add(new Paragraph("\n")); if (cevapA != "") { prag.Add(new Paragraph("A) " + cevapA)); } if (cevapB != "") { prag.Add(new Paragraph("B) " + cevapB)); } if (cevapC != "") { prag.Add(new Paragraph("C) " + cevapC)); } if (cevapD != "") { prag.Add(new Paragraph("D) " + cevapD)); } if (cevapE != "") { prag.Add(new Paragraph("E) " + cevapE)); } prag.Add(new Paragraph("\n")); //if ((i+1)%5== 0) //{ // list.NewPage(); //} } list.Add(prag); list.Close(); list1.Close(); baglanti.Close(); //cmd.Parameters.AddWithValue("@soruID", Convert.ToInt32(textBox1.Text)); //con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=sirket.accdb"); //con.Open(); //cmd = new OleDbCommand("Select * From personel", con); //dr = cmd.ExecuteReader(); //while (dr.Read()) //{ // ListViewItem item = new ListViewItem(dr["PId"].ToString()); // item.SubItems.Add(dr["PAd"].ToString()); // item.SubItems.Add(dr["PSoyad"].ToString()); //www.ahmetcansever.com // item.SubItems.Add(dr["PTelefon"].ToString()); // listView1.Items.Add(item); //} //con.Close(); }
public void Go() { // GetClassOutputPath() implementation left out for brevity var outputFile = Helpers.IO.GetClassOutputPath(this); using (FileStream stream = new FileStream( outputFile, FileMode.Create, FileAccess.Write)) { string chunkText = "FirstName LastName (2016-01-13 11:13)"; Random random = new Random(); var font = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); using (Document document = new Document()) { PdfWriter.GetInstance(document, stream); document.Open(); Phrase phrase = new Phrase(); for (var i = 0; i < 1000; ++i) { var asterisk = new String('*', random.Next(1, 20)); Chunk chunk = new Chunk( string.Format("[{0}] {1}", asterisk, chunkText), font ); chunk.SetSplitCharacter(new CustomSplitCharacter()); phrase.Add(chunk); } document.Add(phrase); } } }
// --------------------------------------------------------------------------- /** * Manipulates a PDF file src with the file dest as result * @param src the original PDF */ public byte[] ManipulatePdf(byte[] src) { // Create a table with named actions Font symbol = new Font(Font.FontFamily.SYMBOL, 20); PdfPTable table = new PdfPTable(4); table.DefaultCell.Border = Rectangle.NO_BORDER; table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; Chunk first = new Chunk( ((char)220).ToString() , symbol); first.SetAction(new PdfAction(PdfAction.FIRSTPAGE)); table.AddCell(new Phrase(first)); Chunk previous = new Chunk( ((char)172).ToString(), symbol); previous.SetAction(new PdfAction(PdfAction.PREVPAGE)); table.AddCell(new Phrase(previous)); Chunk next = new Chunk( ((char)174).ToString(), symbol); next.SetAction(new PdfAction(PdfAction.NEXTPAGE)); table.AddCell(new Phrase(next)); Chunk last = new Chunk( ((char)222).ToString(), symbol); last.SetAction(new PdfAction(PdfAction.LASTPAGE)); table.AddCell(new Phrase(last)); table.TotalWidth = 120; // Create a reader PdfReader reader = new PdfReader(src); using (MemoryStream ms = new MemoryStream()) { // Create a stamper using (PdfStamper stamper = new PdfStamper(reader, ms)) { // Add the table to each page PdfContentByte canvas; for (int i = 0; i < reader.NumberOfPages; ) { canvas = stamper.GetOverContent(++i); table.WriteSelectedRows(0, -1, 696, 36, canvas); } } return ms.ToArray(); } }
public void PageEventTest01() { String fileName = "pageEventTest01.pdf"; MemoryStream baos = new MemoryStream(); Document doc = new Document(PageSize.LETTER, 144, 144, 144, 144); PdfWriter writer = PdfWriter.GetInstance(doc, baos); writer.PageEvent = new MyEventHandler(); writer.SetTagged(); doc.Open(); Chunk c = new Chunk("This is page 1"); doc.Add(c); doc.Close(); File.WriteAllBytes(OUTPUT_FOLDER + fileName, baos.ToArray()); baos.Close(); // compare CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + fileName, TEST_RESOURCES_PATH + fileName, OUTPUT_FOLDER, "diff"); if (errorMessage != null) { Assert.Fail(errorMessage); } }