/** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>Stream</CODE> the writer has to write to. * @param conformanceLevel PDF/A conformance level of a new PDF document * @return a new <CODE>PdfWriter</CODE> * @throws DocumentException on error */ public static PdfAWriter GetInstance(Document document, Stream os, PdfAConformanceLevel conformanceLevel) { PdfDocument pdf = new PdfDocument(); document.AddDocListener(pdf); PdfAWriter writer = new PdfAWriter(pdf, os, conformanceLevel); pdf.AddWriter(writer); return writer; }
/** * Creates new PdfStamperImp. * @param reader reads the PDF * @param os the output destination * @param pdfVersion the new pdf version or '\0' to keep the same version as the original document * @param append * @param conformanceLevel PDF/A conformance level of a new PDF document * @throws DocumentException on error * @throws IOException */ internal PdfAStamperImp(PdfReader reader, Stream os, char pdfVersion, bool append, PdfAConformanceLevel conformanceLevel) : base(reader, os, pdfVersion, append) { ((IPdfAConformance)pdfIsoConformance).SetConformanceLevel(conformanceLevel); PdfAWriter.SetPdfVersion(this, conformanceLevel); ReadPdfAInfo(); }
/** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. * @param document The <CODE>Document</CODE> that has to be written * @param os The <CODE>Stream</CODE> the writer has to write to. * @param conformanceLevel PDF/A conformance level of a new PDF document * @return a new <CODE>PdfWriter</CODE> * @throws DocumentException on error */ public static PdfAWriter GetInstance(Document document, Stream os, PdfAConformanceLevel conformanceLevel) { PdfDocument pdf = new PdfDocument(); document.AddDocListener(pdf); PdfAWriter writer = new PdfAWriter(pdf, os, conformanceLevel); pdf.AddWriter(writer); return(writer); }
private void button3_Click(object sender, EventArgs e) { sss(); return; iTextSharp.text.Document _pdf = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 50, 20, 20, 20); string filePath = Directory.GetCurrentDirectory() + "\\" + Process.GetCurrentProcess().ProcessName + ".pdf"; if (File.Exists(filePath)) { File.Delete(filePath); } FileStream fs = new FileStream(filePath, FileMode.Create); iTextSharp.text.pdf.PdfAWriter _pdfWriter = iTextSharp.text.pdf.PdfAWriter.GetInstance(_pdf, fs, iTextSharp.text.pdf.PdfAConformanceLevel.PDF_A_1B); _pdfWriter.Open(); //iTextSharp.text.pdf.BaseFont _bf = iTextSharp.text.pdf.BaseFont.CreateFont("c:\\windows\\fonts\\SIMYOU.TTF", "Identity-H", false); //iTextSharp.text.Font _font = new iTextSharp.text.Font(_bf); iTextSharp.text.Font _font = iTextSharp.text.FontFactory.GetFont("FreeMonoBold.ttf", iTextSharp.text.pdf.BaseFont.WINANSI, iTextSharp.text.pdf.BaseFont.EMBEDDED, 12); iTextSharp.text.Paragraph paragraph; string _tf = Directory.GetCurrentDirectory() + "\\1.txt"; string[] lines = System.IO.File.ReadAllLines(_tf, Encoding.GetEncoding("utf-8")); foreach (string line in lines) { paragraph = new iTextSharp.text.Paragraph(line, _font); _pdfWriter.Add(paragraph); _pdf.Close(); break; } }