示例#1
0
 public void CreateDocument(int fontSize)
 {
     try
     {
         // Creates a report document
         // Creates an instance of the PdfWriter
         PdfWriter      writer = new PdfWriter(FilePath);
         ReportDocument Report = new ReportDocument(writer, DocumentPageSizeCode);
         // Adds the header content
         Document doc = new Document(Report);
         // Sets the document font
         FontProvider fontProvider = new FontProvider();
         fontProvider.AddStandardPdfFonts();
         doc.SetFontProvider(fontProvider);
         doc.SetFontFamily(StandardFonts.COURIER);
         doc.Add(new HeaderContentBuilder(DocumentHeader, IncludeReportDate).ReportHeader().SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER));
         // Adds the report body content
         doc.Add(new ReportBodyContentBuilder(ReportData, ColumnsAsDates, fontSize).ReportBody());
         // Adds the report end of record indicator if requested
         if (IncludeEndOfRecordIndicator == true)
         {
             doc.Add(new EndOfRecordIndicatorBuilder().EndOfRecordIndicator().SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER));
         }
         // Closes the report and saves changes
         Report.Close();
     }
     catch (Exception ex)
     {
         throw new ApplicationException("There was an error generating the report document...   " + ex.ToString());
     }
 }
        internal static ConverterProperties InitConverterProperties()
        {
            ConverterProperties converterProperties = new ConverterProperties();

            converterProperties.SetBaseUri(SOURCE_FOLDER);
            FontProvider fontProvider = new FontProvider();

            fontProvider.AddDirectory(RESOURCES);
            fontProvider.AddStandardPdfFonts();
            converterProperties.SetFontProvider(fontProvider);
            return(converterProperties);
        }
示例#3
0
        public void ManipulatePdf(string src, string dest)
        {
            WriterProperties writerProperties = new WriterProperties();

            writerProperties.AddXmpMetadata();

            PdfWriter   pdfWriter = new PdfWriter(dest, writerProperties);
            PdfDocument pdfDoc    = new PdfDocument(pdfWriter);

            pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));

            pdfDoc.SetTagged();
            pdfDoc.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));

            PdfDocumentInfo pdfMetaData = pdfDoc.GetDocumentInfo();

            pdfMetaData.SetAuthor("Samuel Huylebroeck");
            pdfMetaData.AddCreationDate();
            pdfMetaData.GetProducer();
            pdfMetaData.SetCreator("iText Software");
            pdfMetaData.SetKeywords("example, accessibility");
            pdfMetaData.SetSubject("PDF accessibility");

            // Title is derived from html

            // pdf conversion
            ConverterProperties props        = new ConverterProperties();
            FontProvider        fontProvider = new FontProvider();

            fontProvider.AddStandardPdfFonts();
            fontProvider.AddDirectory(SRC);

            // The noto-nashk font file (.ttf extension) is placed in the resources
            props.SetFontProvider(fontProvider);
            // Base URI is required to resolve the path to source files
            props.SetBaseUri(SRC);

            // Setup custom tagworker factory for better tagging of headers
            DefaultTagWorkerFactory tagWorkerFactory = new AccessibilityTagWorkerFactory();

            props.SetTagWorkerFactory(tagWorkerFactory);

            HtmlConverter.ConvertToPdf(new FileStream(src, FileMode.Open), pdfDoc, props);

            pdfDoc.Close();
        }
示例#4
0
        public static void Create(string dest)
        {
            PdfWriter pdfWriter = new PdfWriter(dest);

            PdfDocument pdfDoc = new PdfDocument(pdfWriter);

            // pdf conversion
            ConverterProperties props = new ConverterProperties();
            FontProvider        fp    = new FontProvider();

            fp.AddStandardPdfFonts();
            fp.AddDirectory(@"fonts");//The noto-nashk font file (.ttf extension) is placed in the resources

            props.SetFontProvider(fp);
            props.SetBaseUri(@"fonts");
            //Setup custom tagworker factory for better tagging of headers
            HtmlConverter.ConvertToPdf(@"<h1>Hello</h1><p>world</p>", pdfDoc, props);
            pdfDoc.Close();
        }
        public virtual void StandardPdfFonts()
        {
            String       outFileName = destinationFolder + "standardPdfFonts.pdf";
            String       cmpFileName = sourceFolder + "cmp_standardPdfFonts.pdf";
            FontProvider sel         = new FontProvider();

            sel.AddStandardPdfFonts();
            String      s      = "Hello world!";
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create)));
            Document    doc    = new Document(pdfDoc);

            doc.SetFontProvider(sel);
            Paragraph paragraph = new Paragraph(s);

            paragraph.SetFont("Courier");
            doc.Add(paragraph);
            paragraph = new Paragraph(s);
            paragraph.SetProperty(Property.FONT, "Times-Roman");
            doc.Add(paragraph);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }