예제 #1
0
        public void SendToPDF(string filename, clsFont jfont)
        {
            //New document, 8.5"x11" in landscape orientation.
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.LETTER.Rotate());

            //add metadata
            doc.AddTitle("Font preview for font " + jfont.SelectedFontName());
            doc.AddSubject("font family " + jfont.SelectedFontName());
            doc.AddAuthor("JLION.COM jFONT font preview utility");
            doc.AddCreationDate();

            //create a pdfwriter
            iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create));

            //trap events
            PDFPageEvent pdfevent = new PDFPageEvent();

            writer.PageEvent = pdfevent;

            //create the doc
            doc.Open();
            doc.SetMargins(.75f * 72, .75f * 72, 0, 0);

            for (int currentPage = 0; currentPage < jfont.CountOfPages(); currentPage++)
            {
                //convert image to a pdf image for inclusion in the doc
                System.Drawing.Image jfontimage = jfont.MakeCharList(currentPage);
                //System.Drawing.Image jfontimage = jfont.MakeCharacterSample();
                iTextSharp.text.Image convertedimage = iTextSharp.text.Image.GetInstance(jfontimage, System.Drawing.Imaging.ImageFormat.Bmp);

                //determine size to scale to. PDF is 72 dpi, so 1 point is 1/72.
                System.Drawing.Rectangle PDFImageSize = jfont.ImageSize(72);

                convertedimage.ScaleAbsolute(PDFImageSize.Width, PDFImageSize.Height);

                //Add some blank space at the top of the document
                doc.Add(new Paragraph("Font: " + jfont.SelectedFontName()));
                doc.Add(new Paragraph("Style: " + jfont.SelectedFontStyle()));
                doc.Add(new Paragraph(""));
                doc.Add(new Paragraph(""));
                doc.Add(convertedimage);

                doc.NewPage();
            }

            doc.Close();
        }
예제 #2
0
        public void SendToPDF(string filename, clsFont jfont)
        {
            int countOfPages = _unicodeCharList.CharCodes.Count() / LINES_PER_PAGE; //fifty lines per page.

            //New document, 8.5"x11" in landscape orientation.
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.LETTER);

            //add metadata
            doc.AddTitle("Unicode Character Set for font " + jfont.SelectedFontName());
            doc.AddSubject("font family " + jfont.SelectedFontName());
            doc.AddAuthor("JLION.COM jFONT font preview utility");
            doc.AddCreationDate();

            //create a pdfwriter
            iTextSharp.text.pdf.PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create));

            //trap events
            PDFPageEvent pdfevent = new PDFPageEvent();

            writer.PageEvent = pdfevent;

            //create the doc
            doc.Open();
            doc.SetMargins(.75f * 72, .75f * 72, 0, 0);

            //Create our base font
            string   FontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
            BaseFont baseFont = BaseFont.CreateFont(FontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            iTextSharp.text.Font x = FontFactory.GetFont(jfont.SelectedFontName());

            for (int currentPage = 0; currentPage < countOfPages; currentPage++)
            {
                PdfPTable table = new PdfPTable(5);
                table.AddCell("Char");
                table.AddCell("Dec");
                table.AddCell("Hex");
                table.AddCell("Desc");
                table.AddCell("AltDesc");

                //convert image to a pdf image for inclusion in the doc
                for (int curChar = currentPage * LINES_PER_PAGE; curChar < (currentPage * LINES_PER_PAGE + LINES_PER_PAGE); curChar++)
                {
                    UnicodeCharList.CharEntry oneEntry = _unicodeCharList.CharCodes[curChar];
                    string charString = char.ConvertFromUtf32(Convert.ToInt32(oneEntry.CodeDec)).ToString();

                    Phrase codedChar = new Phrase(charString, x);
                    table.AddCell(codedChar);
                    table.AddCell(oneEntry.CodeDec);
                    table.AddCell(oneEntry.CodeHex);
                    table.AddCell(oneEntry.Desc);
                    table.AddCell(oneEntry.AltDesc);
                }

                doc.Add(table);

                doc.NewPage();
            }

            doc.Close();
        }