示例#1
0
        private void HtmlToPdf(string inputpath, string outputpath)
        {
            Document   pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
            FileStream fs     = new FileStream(outputpath, FileMode.Create);

            PdfWriter.GetInstance(pdfDoc, fs);

            pdfDoc.Open();
            string contents;

            using (StreamReader sr = File.OpenText(inputpath))
            {
                contents = sr.ReadToEnd();
                sr.Close();
            }
            System.Collections.Generic.Dictionary <string, object> providers = new System.Collections.Generic.Dictionary <string, object>();
            // iTextSharp.text.html.simpleparser.HTMLWorker.IMG_BASEURL=@"E:\Sanghamitra\Projects\eGov2\Source Codes\CopRevenueGov2";
            providers.Add(HTMLWorker.IMG_BASEURL, @"E:\Sanghamitra\Projects\eGov2\Source Codes\CopRevenueGov2\Content");

            iTextSharp.text.html.simpleparser.HTMLWorker hw =
                new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc);
            hw.SetProviders(providers);
            hw.Parse(new StringReader(contents));

            pdfDoc.Close();
        }
示例#2
0
        /**
         * Parses an HTML source to a List of Element objects
         * @param reader    the HTML source
         * @param style     a StyleSheet object
         * @param tags      a map containing supported tags and their processors
         * @param providers map containing classes with extra info
         * @return a List of Element objects
         * @throws IOException
         * @since 5.0.6
         */
        public static List <IElement> ParseToList(TextReader reader, StyleSheet style,
                                                  IDictionary <String, IHTMLTagProcessor> tags, Dictionary <String, Object> providers)
        {
            HTMLWorker worker = new HTMLWorker(null, tags, style);

            worker.document = worker;
            worker.SetProviders(providers);
            worker.objectList = new List <IElement>();
            worker.Parse(reader);
            return(worker.objectList);
        }
示例#3
0
        private void HtmlToPdf(string inputpath, string outputpath)
        {
            Document   pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
            FileStream fs     = new FileStream(outputpath, FileMode.Create);

            PdfWriter.GetInstance(pdfDoc, fs);

            pdfDoc.Open();
            string contents;

            contents = inputpath;

            string fontpath = "C:\\WINDOWS\\Fonts\\";

            FontFactory.Register(fontpath + "IDAutomationOCRa.ttf");
            BaseFont customfont = BaseFont.CreateFont(fontpath + "IDAutomationOCRa.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);

            Font       font   = new Font(customfont, 10);
            StyleSheet styles = new StyleSheet();

            styles.LoadTagStyle("p", "font-family", "IDAutomationOCRa");


            //pdfDoc.Add(new Paragraph(contents, font));
            DirectoryInfo Folder      = new DirectoryInfo(COPPaths.COUPON_PATH);
            string        folder_path = Folder.ToString();
            string        dynamicPath = folder_path.Substring(0, folder_path.LastIndexOf("CouponImages"));

            dynamicPath = dynamicPath + "Content";

            System.Collections.Generic.Dictionary <string, object> providers = new System.Collections.Generic.Dictionary <string, object>();

            providers.Add(HTMLWorker.IMG_BASEURL, dynamicPath);
            iTextSharp.text.html.simpleparser.HTMLWorker hw =
                new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc, null, styles);
            hw.SetProviders(providers);
            hw.Parse(new StringReader(contents));

            pdfDoc.Close();
        }
示例#4
0
 /**
  * Parses an HTML source to a List of Element objects
  * @param reader    the HTML source
  * @param style     a StyleSheet object
  * @param tags      a map containing supported tags and their processors
  * @param providers map containing classes with extra info
  * @return a List of Element objects
  * @throws IOException
  * @since 5.0.6
  */
 public static List<IElement> ParseToList(TextReader reader, StyleSheet style,
         IDictionary<String, IHTMLTagProcessor> tags, Dictionary<String, Object> providers) {
     HTMLWorker worker = new HTMLWorker(null, tags, style);
     worker.document = worker;
     worker.SetProviders(providers);
     worker.objectList = new List<IElement>();
     worker.Parse(reader);
     return worker.objectList;
 }