private static void SaveAsPdf(XpsDocumentSplicer xpsDocumentSplicer, string outputDirectory) { string tempXpsSavePath = GetTempXpsSavePath(); xpsDocumentSplicer.SaveSplicedXpsDocumentTo(tempXpsSavePath); ConvertXpsToPdf(tempXpsSavePath, outputDirectory); File.Delete(tempXpsSavePath); }
private static void Fill <T>(ref XpsDocumentSplicer xpsDocumentSplicer, IEnumerable <T> dataSourceObjectList) { foreach (T sourceObject in dataSourceObjectList) { if (IsCancellationRequested()) { break; } xpsDocumentSplicer.AddXpsDocumentWith(sourceObject); ReportProgressFor(dataSourceObjectList); } }
private static FileStream GetAsPdfFileStream(XpsDocumentSplicer xpsDocumentSplicer) { string tempXpsSavePath = GetTempXpsSavePath(); string tempPdfSavePath = GetTempPdfSavePath(); xpsDocumentSplicer.SaveSplicedXpsDocumentTo(tempXpsSavePath); ConvertXpsToPdf(tempXpsSavePath, tempPdfSavePath); FileStream pdfFileStream = File.Open(tempPdfSavePath, FileMode.OpenOrCreate); File.Delete(tempPdfSavePath); File.Delete(tempXpsSavePath); return(pdfFileStream); }
public static void CreatePdfReportFromObjectList <T>(ReportProperties reportProperties, IEnumerable <T> dataSourceObjectList, CancellationToken cancellationToken = default, IProgress <double> progressReporter = null) { if (dataSourceObjectList == null) { throw new ArgumentNullException(nameof(dataSourceObjectList)); } _cancellationToken = cancellationToken; _progressReporter = progressReporter; var xpsDocumentSplicer = new XpsDocumentSplicer(reportProperties); Fill(ref xpsDocumentSplicer, dataSourceObjectList); if (IsCancellationRequested()) { return; } SaveAsPdf(xpsDocumentSplicer, reportProperties.OutputDirectory); FinishProgress(); }
public static FileStream GetPdfReportFromObjectList <T>(ReportProperties reportProperties, IEnumerable <T> dataSourceObjectList, CancellationToken cancellationToken = default, IProgress <double> progressReporter = null) { if (dataSourceObjectList == null) { throw new ArgumentNullException(nameof(dataSourceObjectList)); } _cancellationToken = cancellationToken; _progressReporter = progressReporter; var xpsDocumentSplicer = new XpsDocumentSplicer(reportProperties); Fill(ref xpsDocumentSplicer, dataSourceObjectList); if (IsCancellationRequested()) { return(null); } FileStream pdfFileStream = GetAsPdfFileStream(xpsDocumentSplicer); FinishProgress(); return(pdfFileStream); }