/// <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(Leerlijn toExport) { Document prePdf = new Document(); //Document markup DefineStyles(prePdf); BuildCover(prePdf, "Leerlijn: " + toExport.Naam); //Here starts the real exporting Section sect = prePdf.AddSection(); LeerlijnExportArguments opt = new LeerlijnExportArguments() { ExportAll = true }; LeerlijnExporterFactory lef = new LeerlijnExporterFactory(); leerlijnExporterStrategy = lef.GetStrategy(opt); try { sect = leerlijnExporterStrategy.Export(toExport, sect); } catch (Exception e) { sect.AddParagraph("An error has occured while invoking an export-function on Leerlijn: " + toExport.Naam + "\n" + e.Message, "error"); } PdfDocumentRenderer rend = new PdfDocumentRenderer(false, PdfFontEmbedding.Always); rend.Document = prePdf; rend.RenderDocument(); return(rend.PdfDocument); }
public void TestMultiLeerlijnPdfOutput() { LeerlijnExportArguments args = new LeerlijnExportArguments() { ExportAll = true }; LeerlijnExportablePack pack = new LeerlijnExportablePack(args, data); PdfDocument pdf = les.ExportAll(pack); pdf.Save("D:\\Education\\Proj_blk6\\TestIO\\ll_pdf_FULL.pdf"); }
/// <summary> /// Get a decorator pattern based on given options /// </summary> /// <param name="opt">Pre-defined options</param> /// <returns>Decorator pattern for exporting</returns> public IExporter <DomainDAL.Leerlijn> GetStrategy(LeerlijnExportArguments opt) { //make sure you keep the ExportOptions in Sync with the Stack. That way, you can just use ifs here. IExporter <DomainDAL.Leerlijn> strategy = new LeerlijnPassiveExporter(); opt.ExportNaam = true; //Always Needed, table of contents is filled with this Type[] typeArgs = { typeof(IExporter <DomainDAL.Leerlijn>) }; if (opt.ExportAll || opt.ExportNaam) { Type t = usableTypes["LeerlijnNaamExporter"]; var ctor = t.GetConstructor(typeArgs); if (ctor != null) { object[] parameters = { strategy }; strategy = ctor.Invoke(parameters) as IExporter <DomainDAL.Leerlijn>; } } if (opt.ExportAll || opt.ExportModules) { Type t = usableTypes["LeerlijnModulesExporter"]; var ctor = t.GetConstructor(typeArgs); if (ctor != null) { object[] parameters = { strategy }; strategy = ctor.Invoke(parameters) as IExporter <DomainDAL.Leerlijn>; } } if (opt.ExportAll || opt.ExportCompetenties) { Type t = usableTypes["LeerlijnCompetentiesExporter"]; var ctor = t.GetConstructor(typeArgs); if (ctor != null) { object[] parameters = { strategy }; strategy = ctor.Invoke(parameters) as IExporter <DomainDAL.Leerlijn>; } } //This won't happen. But hey, risky things an' all. if (strategy == null) { strategy = new LeerlijnPassiveExporter(); } return(strategy); }
public FileStreamResult GetLeerlijnenExport() { LeerlijnExportArguments args = new LeerlijnExportArguments() { ExportAll = true }; var data = _unitOfWork.GetRepository <Leerlijn>().GetAll(); var maxSchooljaar = _unitOfWork.GetRepository <Schooljaar>().GetAll().Max(src => src.JaarId); var lastYearData = (from element in data where element.Schooljaar.Equals(maxSchooljaar) select element).ToList(); IExportablePack <Leerlijn> pack = new LeerlijnExportablePack(args, lastYearData); Stream fStream = _leerlijnExporterService.ExportAllAsStream(pack); HttpContext.Response.AddHeader("content-disposition", "attachment; filename=Leerlijnen.pdf"); return(new FileStreamResult(fStream, "application/pdf")); }