public override List CloneShallow() { ZapfDingbatsList clone = new ZapfDingbatsList(zn); PopulateProperties(clone); return(clone); }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 var SQL = @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c FROM film_country c, film_movie_country mc WHERE c.id = mc.country_id GROUP BY mc.country_id, country ORDER BY c DESC"; // Create a list for the countries List list = new List(List.ORDERED); list.First = 9; // loop over the countries using (var c = AdoDB.Provider.CreateConnection()) { c.ConnectionString = AdoDB.CS; using (DbCommand cmd = c.CreateCommand()) { cmd.CommandText = SQL; c.Open(); using (var r = cmd.ExecuteReader()) { while (r.Read()) { // create a list item for the country ListItem item = new ListItem( string.Format("{0}: {1} movies", r["country"].ToString(), r["c"].ToString() ) ); // Create a list for the movies List movielist = new List(); movielist.ListSymbol= new Chunk("Movie: ", FilmFonts.BOLD); foreach (Movie movie in PojoFactory.GetMovies(r["country_id"].ToString()) ) { ListItem movieitem = new ListItem(movie.MovieTitle); // Create a list for the directors List directorlist = new ZapfDingbatsList(42); foreach (Director director in movie.Directors) { directorlist.Add(String.Format("{0}, {1}", director.Name, director.GivenName )); } movieitem.Add(directorlist); movielist.Add(movieitem); } item.Add(movielist); list.Add(item); } document.Add(list); } } } } }
/** * The ListCssApplier has the capabilities to change the type of the given {@link List} dependable on the css. * This means: <strong>Always replace your list with the returned one and add content to the list after applying!</strong> */ // not implemented: list-style-type:armenian, georgian, decimal-leading-zero. virtual public List Apply(List list, Tag t, HtmlPipelineContext context) { float fontSize = FontSizeTranslator.GetInstance().GetFontSize(t); List lst = list; IDictionary<String, String> css = t.CSS; String styleType; css.TryGetValue(CSS.Property.LIST_STYLE_TYPE, out styleType); BaseColor color = HtmlUtilities.DecodeColor(css.ContainsKey(CSS.Property.COLOR) ? css[CSS.Property.COLOR] : null); if (null == color) color = BaseColor.BLACK; if (null != styleType) { if (Util.EqualsIgnoreCase(styleType, CSS.Value.NONE)) { lst.Lettered = false; lst.Numbered = false; lst.SetListSymbol(""); } else if (Util.EqualsIgnoreCase(CSS.Value.DECIMAL, styleType)) { lst = new List(List.ORDERED); } else if (Util.EqualsIgnoreCase(CSS.Value.DISC, styleType)) { lst = new ZapfDingbatsList(108); lst.Autoindent = false; lst.SymbolIndent = 7.75f; Chunk symbol = lst.Symbol; symbol.SetTextRise(1.5f); Font font = symbol.Font; font.Size = 4.5f; font.Color = color; } else if (Util.EqualsIgnoreCase(CSS.Value.SQUARE, styleType)) { lst = new ZapfDingbatsList(110); ShrinkSymbol(lst, fontSize, color); } else if (Util.EqualsIgnoreCase(CSS.Value.CIRCLE, styleType)) { lst = new ZapfDingbatsList(109); lst.Autoindent = false; lst.SymbolIndent = 7.75f; Chunk symbol = lst.Symbol; symbol.SetTextRise(1.5f); Font font = symbol.Font; font.Size = 4.5f; font.Color = color; } else if (CSS.Value.LOWER_ROMAN.Equals(styleType)) { lst = new RomanList(true, 0); lst.Autoindent = true; SynchronizeSymbol(fontSize, lst, color); } else if (CSS.Value.UPPER_ROMAN.Equals(styleType)) { lst = new RomanList(false, 0); SynchronizeSymbol(fontSize, lst, color); lst.Autoindent = true; } else if (CSS.Value.LOWER_GREEK.Equals(styleType)) { lst = new GreekList(true, 0); SynchronizeSymbol(fontSize, lst, color); lst.Autoindent = true; } else if (CSS.Value.UPPER_GREEK.Equals(styleType)) { lst = new GreekList(false, 0); SynchronizeSymbol(fontSize, lst, color); lst.Autoindent = true; } else if (CSS.Value.LOWER_ALPHA.Equals(styleType) || CSS.Value.LOWER_LATIN.Equals(styleType)) { lst = new List(List.ORDERED, List.ALPHABETICAL); SynchronizeSymbol(fontSize, lst, color); lst.Lowercase = true; lst.Autoindent = true; } else if (CSS.Value.UPPER_ALPHA.Equals(styleType) || CSS.Value.UPPER_LATIN.Equals(styleType)) { lst = new List(List.ORDERED, List.ALPHABETICAL); SynchronizeSymbol(fontSize, lst, color); lst.Lowercase = false; lst.Autoindent = true; } } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.OL)) { lst = new List(List.ORDERED); String type = null; t.Attributes.TryGetValue("type", out type); if (type != null) { if (type.Equals("A")) { lst.Lettered = true; } else if (type.Equals("a")) { lst.Lettered = true; lst.Lowercase = true; } } SynchronizeSymbol(fontSize, lst, color); lst.Autoindent = true; } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.UL)) { lst = new List(List.UNORDERED); ShrinkSymbol(lst, fontSize, color); } if (css.ContainsKey(CSS.Property.LIST_STYLE_IMAGE) && !Util.EqualsIgnoreCase(css[CSS.Property.LIST_STYLE_IMAGE], CSS.Value.NONE)) { lst = new List(); String url = utils.ExtractUrl(css[CSS.Property.LIST_STYLE_IMAGE]); try { Image img = new ImageRetrieve(context.ResourcePath, context.GetImageProvider()).RetrieveImage(url); lst.ListSymbol = new Chunk(img, 0, 0, false); lst.SymbolIndent = img.Width; if (LOG.IsLogging(Level.TRACE)) { LOG.Trace(String.Format(LocaleMessages.GetInstance().GetMessage("html.tag.list"), url)); } } catch (NoImageException e) { if (LOG.IsLogging(Level.ERROR)) { LOG.Error(String.Format(LocaleMessages.GetInstance().GetMessage("html.tag.img.failed"), url), e); } lst = new List(List.UNORDERED); } lst.Autoindent = false; } lst.Alignindent = false; float leftIndent = 0; if (css.ContainsKey(CSS.Property.LIST_STYLE_POSITION) && Util.EqualsIgnoreCase(css[CSS.Property.LIST_STYLE_POSITION], CSS.Value.INSIDE)) { leftIndent += 30; } else { leftIndent += 15; } leftIndent += css.ContainsKey(CSS.Property.MARGIN_LEFT)?utils.ParseValueToPt(css[CSS.Property.MARGIN_LEFT],fontSize):0; leftIndent += css.ContainsKey(CSS.Property.PADDING_LEFT)?utils.ParseValueToPt(css[CSS.Property.PADDING_LEFT],fontSize):0; lst.IndentationLeft = leftIndent; String startAtr = null; t.Attributes.TryGetValue(HTML.Attribute.START, out startAtr); if (startAtr != null) { try { int start = int.Parse(startAtr); lst.First = start; } catch (FormatException exc) { } } return lst; }
/** * The ListCssApplier has the capabilities to change the type of the given {@link List} dependable on the css. * This means: <strong>Always replace your list with the returned one and add content to the list after applying!</strong> */ // not implemented: list-style-type:armenian, georgian, decimal-leading-zero. public List Apply(List list, Tag t, HtmlPipelineContext htmlPipelineContext) { float fontSize = FontSizeTranslator.GetInstance().GetFontSize(t); List lst = list; IDictionary<String, String> css = t.CSS; String styleType; css.TryGetValue(CSS.Property.LIST_STYLE_TYPE, out styleType); if (null != styleType) { if (Util.EqualsIgnoreCase(styleType, CSS.Value.NONE)) { lst.Lettered = false; lst.Numbered = false; lst.SetListSymbol(""); } else if (Util.EqualsIgnoreCase(CSS.Value.DECIMAL, styleType)) { lst = new List(List.ORDERED); SynchronizeSymbol(fontSize, lst); } else if (Util.EqualsIgnoreCase(CSS.Value.DISC, styleType)) { lst = new ZapfDingbatsList(108); ShrinkSymbol(lst, fontSize); } else if (Util.EqualsIgnoreCase(CSS.Value.SQUARE, styleType)) { lst = new ZapfDingbatsList(110); ShrinkSymbol(lst, fontSize); } else if (Util.EqualsIgnoreCase(CSS.Value.CIRCLE, styleType)) { lst = new ZapfDingbatsList(109); ShrinkSymbol(lst, fontSize); } else if (CSS.Value.LOWER_ROMAN.Equals(styleType)) { lst = new RomanList(true, 0); SynchronizeSymbol(fontSize, lst); } else if (CSS.Value.UPPER_ROMAN.Equals(styleType)) { lst = new RomanList(false, 0); SynchronizeSymbol(fontSize, lst); } else if (CSS.Value.LOWER_GREEK.Equals(styleType)) { lst = new GreekList(true, 0); SynchronizeSymbol(fontSize, lst); } else if (CSS.Value.UPPER_GREEK.Equals(styleType)) { lst = new GreekList(false, 0); SynchronizeSymbol(fontSize, lst); } else if (CSS.Value.LOWER_ALPHA.Equals(styleType) || CSS.Value.LOWER_LATIN.Equals(styleType)) { lst = new List(List.ORDERED, List.ALPHABETICAL); SynchronizeSymbol(fontSize, lst); lst.Lowercase = true; } else if (CSS.Value.UPPER_ALPHA.Equals(styleType) || CSS.Value.UPPER_LATIN.Equals(styleType)) { lst = new List(List.ORDERED, List.ALPHABETICAL); SynchronizeSymbol(fontSize, lst); lst.Lowercase = false; } } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.OL)) { lst = new List(List.ORDERED); SynchronizeSymbol(fontSize, lst); } else if (Util.EqualsIgnoreCase(t.Name, HTML.Tag.UL)) { lst = new List(List.UNORDERED); ShrinkSymbol(lst, fontSize); } if (css.ContainsKey(CSS.Property.LIST_STYLE_IMAGE) && !Util.EqualsIgnoreCase(css[CSS.Property.LIST_STYLE_IMAGE], CSS.Value.NONE)) { lst = new List(); String url = utils.ExtractUrl(css[CSS.Property.LIST_STYLE_IMAGE]); iTextSharp.text.Image img = null; try { if (htmlPipelineContext == null) { img = new ImageRetrieve().RetrieveImage(url); } else { try { img = new ImageRetrieve(htmlPipelineContext.GetImageProvider()).RetrieveImage(url); } catch (NoImageProviderException) { if (LOG.IsLogging(Level.TRACE)) { LOG.Trace(String.Format(LocaleMessages.GetInstance().GetMessage("pipeline.html.noimageprovider"), htmlPipelineContext.GetType().FullName)); } img = new ImageRetrieve().RetrieveImage(url); } } lst.ListSymbol = new Chunk(img, 0, 0, false); lst.SymbolIndent = img.Width; if (LOG.IsLogging(Level.TRACE)) { LOG.Trace(String.Format(LocaleMessages.GetInstance().GetMessage("html.tag.list"), url)); } } catch (IOException e) { if (LOG.IsLogging(Level.ERROR)) { LOG.Error(String.Format(LocaleMessages.GetInstance().GetMessage("html.tag.list.failed"), url), e); } lst = new List(List.UNORDERED); } catch (NoImageException e) { if (LOG.IsLogging(Level.ERROR)) { LOG.Error(e.Message, e); } lst = new List(List.UNORDERED); } } lst.Alignindent = false; lst.Autoindent = false; float leftIndent = 0; if (css.ContainsKey(CSS.Property.LIST_STYLE_POSITION) && Util.EqualsIgnoreCase(css[CSS.Property.LIST_STYLE_POSITION], CSS.Value.INSIDE)) { leftIndent += 30; } else { leftIndent += 15; } leftIndent += css.ContainsKey(CSS.Property.MARGIN_LEFT)?utils.ParseValueToPt(css[CSS.Property.MARGIN_LEFT],fontSize):0; leftIndent += css.ContainsKey(CSS.Property.PADDING_LEFT)?utils.ParseValueToPt(css[CSS.Property.PADDING_LEFT],fontSize):0; lst.IndentationLeft = leftIndent; return lst; }
private void button4_Click(object sender, EventArgs e) { //Control ctl = this.dataGridView1; Control ctl = Control.FromHandle(this.dataGridView1.Handle); { Bitmap bt = new Bitmap(ctl.Width, ctl.Height); ctl.DrawToBitmap(bt, new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height)); bt.Save("abc.gif",System.Drawing.Imaging.ImageFormat.Gif); Document document = new Document(PageSize.A4, 10,10, 10,10); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Application.StartupPath + @"\abcd.pdf", FileMode.Create)); writer.ViewerPreferences = (PdfWriter.CenterWindow | PdfWriter.FitWindow | PdfWriter.PageModeUseNone); document.Open(); //使用宋体字体 BaseFont baseFont = BaseFont.CreateFont("C:\\WINDOWS\\FONTS\\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); PdfContentByte cb = writer.DirectContent; Chapter chapter1 = new Chapter(new Paragraph("This is Chapter 1"), 1); Section section1 = chapter1.AddSection(20f, "Section 1.1", 2); Section section2 = chapter1.AddSection(20f, "Section 1.2", 2); Section subsection1 = section2.AddSection(20f, "Subsection 1.2.1", 3); Section subsection2 = section2.AddSection(20f, "Subsection 1.2.2", 3); Section subsubsection = subsection2.AddSection(20f, "Sub Subsection 1.2.2.1", 4); Chapter chapter2 = new Chapter(new Paragraph("This is Chapter 2"), 1); Section section3 = chapter2.AddSection("Section 2.1", 2); Section subsection3 = section3.AddSection("Subsection 2.1.1", 3); Section section4 = chapter2.AddSection("Section 2.2", 2); chapter1.BookmarkTitle = "Changed Title"; chapter1.BookmarkOpen = true; chapter2.BookmarkOpen = false; document.Add(chapter1); document.Add(chapter2); ZapfDingbatsList zlist = new ZapfDingbatsList(49, 15); zlist.Add("One"); zlist.Add("Two"); zlist.Add("Three"); zlist.Add("Four"); zlist.Add("Five"); document.Add(zlist); RomanList romanlist = new RomanList(true, 20); romanlist.IndentationLeft = 30f; romanlist.Add("One"); romanlist.Add("Two"); romanlist.Add("Three"); romanlist.Add("Four"); romanlist.Add("Five"); document.Add(romanlist); PdfPTable table1 = new PdfPTable(3); PdfPCell cell1 = new PdfPCell(new Phrase("Header spanning 3 columns")); cell1.Colspan = 3; cell1.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table1.AddCell(cell1); table1.AddCell(cell1); table1.AddCell("Col 1 Row 2"); table1.AddCell("Col 2 Row 2"); table1.AddCell("Col 3 Row 2"); table1.SetWidths(new int[]{50,100,100}); table1.WidthPercentage = 100f; document.Add(table1); //using it = iTextSharp.text; //PdfPTable table2 = new PdfPTable(3); //table2.AddCell("Cell 1"); //PdfPCell cell2 = new PdfPCell(new it.Phrase("Cell 2", new Font(Font.HELVETICA, 8f, Font.NORMAL, Color.YELLOW))); //cell2.BackgroundColor = new Color(0, 150, 0); //cell2.BorderColor = new Color(255, 242, 0); //cell2.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER; //cell2.BorderWidthBottom = 3f; //cell2.BorderWidthTop = 3f; //cell2.PaddingBottom = 10f; //cell2.PaddingLeft = 20f; //cell2.PaddingTop = 4f; //table2.AddCell(cell2); //table2.AddCell("Cell 3"); //document.Add(table2); System.Drawing.Image img = bt; MemoryStream mem = new MemoryStream(); img.Save(mem, System.Drawing.Imaging.ImageFormat.Gif); byte[] bytes = mem.ToArray(); iTextSharp.text.Image img2 = iTextSharp.text.Image.GetInstance(bytes); iTextSharp.text.Image img3 = iTextSharp.text.Image.GetInstance(bytes); img2.ScalePercent(100f); img3.ScalePercent(100f); img2.SetAbsolutePosition(50f, 400f); img3.SetAbsolutePosition(50f, 400f - img2.Height); //cb.AddImage(img2); //cb.AddImage(img3); cb.BeginText(); float Xleading = 27.5f; float Xdelta = 10f; float Yleading = 27.5f; float Ydelta = 20f; cb.SetLineWidth(4f); cb.MoveTo(Xleading, (842 - Yleading - Ydelta)); cb.LineTo((595f - Xleading), (842f - Yleading - Ydelta)); cb.Stroke(); cb.EndText(); document.NewPage(); //绘制近下方细直线上的文字 cb.BeginText(); BaseFont fbaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(fbaseFont); cb.SetFontAndSize(fbaseFont,15); cb.SetColorFill(BaseColor.LIGHT_GRAY); PdfPCell cell = new PdfPCell(); PdfPTable table = new PdfPTable(5); cell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cell); document.Add(table); document.AddAuthor("ms"); document.AddCreationDate(); document.AddTitle("TEST"); //document.Add(new Paragraph("", font)); //document.Add(new Paragraph(" 你好, PDF !", font)); //document.Add(new Paragraph(" 你好, PDF !", font)); //document.Add(new Paragraph(" 你好, PDF !", font)); cb.ShowTextAligned(Element.ALIGN_LEFT, "一二三 :", 50, 800f, 0); cb.ShowTextAligned(Element.ALIGN_LEFT, "一二三 :", 50, 770f, 0); cb.EndText(); cb.AddImage(img2); document.Close(); } Control.ControlCollection ctls = this.Controls; foreach (Control item in ctls) { item.Enabled = false; //item.Width += 100; } }
public override List CloneShallow() { ZapfDingbatsList clone = new ZapfDingbatsList(zn); PopulateProperties(clone); return clone; }