コード例 #1
0
        /// <summary>
        /// Basic export function to generate PDF from one element
        /// </summary>
        /// <param name="toExport">element to export</param>
        /// <returns>A PDF Document</returns>
        public PdfDocument Export(Competentie toExport)
        {
            Document prePdf = new Document();

            //Document markup
            DefineStyles(prePdf);
            BuildCover(prePdf, "Competentie: " + toExport.Naam);

            //Here starts the real exporting
            Section sect = prePdf.AddSection();

            CompetentieExportArguments opt = new CompetentieExportArguments()
            {
                ExportAll = true
            };

            CompetentieExporterFactory cef = new CompetentieExporterFactory();

            competentieExporterStrategy = cef.GetStrategy(opt);

            try
            {
                sect = competentieExporterStrategy.Export(toExport, sect);
            }
            catch (Exception e)
            {
                sect.AddParagraph("An error has occured while invoking an export-function on Competentie: " + toExport.Naam + "\n" + e.Message, "error");
            }

            PdfDocumentRenderer rend = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);

            rend.Document = prePdf;
            rend.RenderDocument();
            return(rend.PdfDocument);
        }
コード例 #2
0
        /// <summary>
        /// Basic export function to generate PDF from a list of elements
        /// </summary>
        /// <param name="pack">pack containing elements to export and arguments to specify the format</param>
        /// <returns>A PDF Document</returns>
        public PdfDocument ExportAll(Interfaces.IExportablePack <Competentie> pack)
        {
            Document prePdf = new Document();

            //Document markup
            DefineStyles(prePdf);
            BuildCover(prePdf, "Competentie-Overzicht voor Informatica");
            DefineTableOfContents(prePdf, pack.ToExport);

            //Here starts the real exporting

            CompetentieExporterFactory cef = new CompetentieExporterFactory();

            competentieExporterStrategy = cef.GetStrategy(pack.Options as CompetentieExportArguments);

            foreach (DomainDAL.Competentie c in pack.ToExport)
            {
                Section sect = prePdf.AddSection();
                try
                {
                    sect = competentieExporterStrategy.Export(c, sect);
                }
                catch (Exception e)
                {
                    sect.AddParagraph("An error has occured while invoking an export-function on Competentie: " + c.Naam + "\n" + e.Message, "error");
                }


                //Page numbers (only for multi-export)
                Paragraph p = new Paragraph();
                p.AddPageField();
                sect.Footers.Primary.Add(p);
                sect.Footers.EvenPage.Add(p.Clone());
            }

            PdfDocumentRenderer rend = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);

            rend.Document = prePdf;
            rend.RenderDocument();
            return(rend.PdfDocument);
        }