示例#1
0
    /// <summary>
    /// 生成PDF格式的采购合同
    /// </summary>
    /// <param name="savePath"></param>
    /// <param name="strHTML"></param>
    public void CreatePDFContract(string fileName, string strHTML)
    {
        string savePath = Server.MapPath("/Download/" + fileName + ".pdf");

        Document  document = new Document(PageSize.A4);
        PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(savePath, FileMode.Create));

        document.Open();

        try
        {
            FontFactory.RegisterFamily("宋体 常规", "simsun", @"c:\windows\fonts\simsun.ttc,0");

            HTMLWorker htmlWorker = new HTMLWorker(document);
            htmlWorker.Parse(new StringReader(strHTML));
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            document.Close();
        }
    }
示例#2
0
        /// <summary>
        /// html转pdf
        /// </summary>
        /// <param name="filePath">文件存储路径</param>
        /// <param name="reportId">报告ID</param>
        /// <param name="uri"></param>
        public static void BaoGaoHtml(string filePath, string reportId, string uri)
        {
            //注册字体(pdf上显示中文必须注册字体)
            FontFactory.RegisterFamily("宋体", "simsun", @"c:\windows\fonts\SIMSUN.TTC,0");
            // FontFactory.RegisterFamily("宋体", "simsun bold", @"c:\windows\fonts\SIMSUN_bold.TTC");

            var           data     = GetReportDetail(reportId, uri);
            StringBuilder sb       = PdfHtml(data);
            Document      document = new Document();

            //设置页面大小是A4纸大小
            document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
            //创建文档
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filePath, FileMode.Create));

            document.Open();
            HTMLWorker html = new HTMLWorker(document);

            //将html转为pdf
            html.Parse(new StringReader(sb.ToString()));
            document.Close();
        }
示例#3
0
        public void getPdfPartitura(Partitura partitura)
        {
            if (!FontFactory.IsRegistered("Night-Braille"))
            {
                FontFactory.RegisterFamily("Night-Braille", "Night-Braille", @"C:\Windows\Fonts");
                FontFactory.RegisterDirectories();
            }
            Font fontBraille = FontFactory.GetFont("Night-Braille", 30, 0);

            if (!FontFactory.IsRegistered("LASSUS"))
            {
                FontFactory.RegisterFamily("LASSUS", "ttfNormal", @"C:\Windows\Fonts");
                FontFactory.RegisterDirectories();
            }
            Font fontPartitura = FontFactory.GetFont("LASSUS", 60, 0);
            Font fontArial     = FontFactory.GetFont("Arial", 15, 1);
            Font fontArial2    = FontFactory.GetFont("Arial", 15, 0);


            Document doc = new Document(iTextSharp.text.PageSize.A4, 20, 20, 20, 20);

            string exeFile  = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
            string exeDir   = Path.GetDirectoryName(exeFile);
            string fullPath = Path.Combine(exeDir, "..\\..\\pdf\\file.pdf");

            FileStream arquivo = new FileStream(fullPath, FileMode.Create);
            PdfWriter  writer  = PdfWriter.GetInstance(doc, arquivo);

            doc.Open();
            doc.AddAuthor("Cleiton de Sousa, Raphael Duarte, Douglas Rodrigues, e DEUS, só ele sabe como isso funciona");
            doc.AddCreator("Partitura Braille");
            doc.AddKeywords("PDF partitura Braille");
            doc.AddTitle(partitura.Titulo);


            Paragraph para = new Paragraph(new Phrase("Partitura: " + partitura.Titulo, fontArial));

            doc.Add(para);
            para = new Paragraph(new Phrase(partitura.TextoPartitura + "=", fontPartitura));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);

            para = new Paragraph(new Phrase("Partitura: " + partitura.Titulo, fontBraille));
            doc.Add(para);
            para = new Paragraph(new Phrase(partitura.BraillePartitura, fontBraille));
            doc.Add(para);

            doc.NewPage();
            para = new Paragraph(new Phrase("Letra da Partitura: " + partitura.Titulo, fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(partitura.LetraPartitura, fontArial2));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase(" ", fontArial));
            doc.Add(para);
            para = new Paragraph(new Phrase("Letra da Partitura em Braille: " + partitura.Titulo, fontBraille));
            doc.Add(para);
            para = new Paragraph(new Phrase(partitura.LetraPartitura, fontBraille));
            doc.Add(para);


            doc.Close();
            arquivo.Close();
            System.Diagnostics.Process.Start(fullPath);
        }