Пример #1
2
 private void SaveHtmlAsPdf(string fName, string html)
 {
     GlobalConfig cfg = new GlobalConfig();
     SimplePechkin sp = new SimplePechkin(cfg);
     ObjectConfig oc = new ObjectConfig();
     oc.SetCreateExternalLinks(true)
         .SetFallbackEncoding(Encoding.ASCII)
         .SetLoadImages(true)
         .SetAllowLocalContent(true)
         .SetPrintBackground(true);
     
     byte[] pdfBuf = sp.Convert(oc, "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title></title></head><body>" + html + "</body></html>");
     FileStream fs = new FileStream(fName, FileMode.Create, FileAccess.ReadWrite);
     foreach (var byteSymbol in pdfBuf)
         fs.WriteByte(byteSymbol);
     fs.Close();
 }
        private byte[] CreatePDF(HtmlDocument doc)
        {
            // Create global configuration object
            GlobalConfig gc = new GlobalConfig();

            // Set it up using fluent notation
            gc.SetMargins(new Margins(50, 100, 0, 0))
                .SetDocumentTitle("Request")
                .SetPaperSize(PaperKind.A4);

            // Create converter
            IPechkin pechkin = new SimplePechkin(gc);

            // Create document configuration object
            ObjectConfig oc = new ObjectConfig();

            // And set it up using fluent notation
            oc.SetCreateExternalLinks(true)
                .SetFallbackEncoding(Encoding.ASCII)
                .SetZoomFactor(2)
                .SetIntelligentShrinking(true)
                .SetLoadImages(true);

            // Convert document
            return pechkin.Convert(oc, doc.DocumentNode.OuterHtml);
        }