/// <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(FaseType toExport) { Document prePdf = new Document(); //Document markup DefineStyles(prePdf); BuildCover(prePdf, toExport.Type); //Here starts the real exporting Section sect = prePdf.AddSection(); LessenTabelExportArguments opt = new LessenTabelExportArguments() { ExportAll = true }; LessenTabelExporterFactory ltef = new LessenTabelExporterFactory(); lessenTabelExporterStrategy = ltef.GetStrategy(opt); try { sect = lessenTabelExporterStrategy.Export(toExport, sect); } catch (Exception e) { sect.AddParagraph("An error has occured while invoking an export-function on FaseType: " + toExport.Type + "\n" + e.Message, "error"); } PdfDocumentRenderer rend = new PdfDocumentRenderer(false, PdfFontEmbedding.Always); rend.Document = prePdf; rend.RenderDocument(); return(rend.PdfDocument); }
public FileStreamResult GetLessentabelExport() { LessenTabelExportArguments args = new LessenTabelExportArguments() { ExportAll = true }; var data = _unitOfWork.GetRepository <FaseType>().GetAll(); IExportablePack <FaseType> pack = new LessenTabelExportablePack(args, data); Stream fStream = _lessenTabelExporterService.ExportAllAsStream(pack); HttpContext.Response.AddHeader("content-disposition", "attachment; filename=LessenTabel.pdf"); return(new FileStreamResult(fStream, "application/pdf")); }
public IExporter <FaseType> GetStrategy(LessenTabelExportArguments opt) { //make sure you keep the ExportOptions in Sync with the Stack. That way, you can just use ifs here. IExporter <FaseType> strategy = new LessenTabelPassiveExporter(); opt.ExportNaam = true; //Always Needed, table of contents is filled with this Type[] typeArgs = { typeof(IExporter <FaseType>) }; if (opt.ExportAll || opt.ExportNaam) { Type t = usableTypes["LessenTabelNaamExporter"]; var ctor = t.GetConstructor(typeArgs); if (ctor != null) { object[] parameters = { strategy }; strategy = ctor.Invoke(parameters) as IExporter <FaseType>; } } if (opt.ExportAll || opt.ExportTabellen) { Type t = usableTypes["LessenTabelInhoudExporter"]; var ctor = t.GetConstructor(typeArgs); if (ctor != null) { object[] parameters = { strategy }; strategy = ctor.Invoke(parameters) as IExporter <FaseType>; } } //This won't happen. But hey, risky things an' all. if (strategy == null) { strategy = new LessenTabelPassiveExporter(); } return(strategy); }