public CreateClientLetterTelerik(string sourcePath, string saveAsFile, CashFlowInformation information, CashFlowDetail detail) { this.sourcePath = sourcePath; SaveAsFile = saveAsFile; this.information = information; this.detail = detail; FillStrings(detail); RadFlowDocument wordDocument = new RadFlowDocument(); provider = new DocxFormatProvider(); try { using (Stream input = File.OpenRead(sourcePath)) { wordDocument = provider.Import(input); } } catch (Exception ex) { throw new Exception($"Das Word-Template konnte nicht geöffnet werden. {ex.Message}"); } editor = new RadFlowDocumentEditor(wordDocument); ReplacePlaceholder(detail); int pos = saveAsFile.LastIndexOf("."); string fileName = saveAsFile.Substring(0, pos) + ".docx"; using (Stream output = File.OpenWrite(fileName)) { provider.Export(editor.Document, output); } string pdfFile = fileName.Replace(".docx", ".pdf"); // cpmversion of a flowdocument to a fixeddocument PdfFormatProvider pdfProvider = new PdfFormatProvider(); RadFixedDocument fixedDocument = pdfProvider.ExportToFixedDocument(editor.Document); // write the fixeddocuement to file Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider fixedProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider(); using (Stream output = File.OpenWrite(pdfFile)) { fixedProvider.Export(fixedDocument, output); } }
public CreateClientLetterTelerik(CashFlowInformation information, int cashFlowNumber, IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; this.information = information; this.cashFlowNumber = cashFlowNumber; provider = new DocxFormatProvider(); ReplaceWordContent(information); }
private void ReplaceWordContent(CashFlowInformation information) { DirectoryInfo directoryInfo = DirectoryHelper.GetWordTemplateDirectory(); string source = Path.Combine(directoryInfo.FullName, information.WordDocument); foreach (CashFlowDetail detail in information.InvestorDetails) { FillStrings(detail); RadFlowDocument wordDocument = new RadFlowDocument(); try { using (Stream input = File.OpenRead(source)) { wordDocument = provider.Import(input); } } catch (Exception ex) { throw new Exception($"Das Word-Template konnte nicht geöffnet werden. {ex.Message}"); } editor = new RadFlowDocumentEditor(wordDocument); ReplacePlaceholder(detail); //add docuemnt to seriesDocument seriesDocument.Merge(editor.Document); // save single file string fileName = DirectoryHelper.FindInvestorCashFlow(detail.Investor.Id, cashFlowNumber); using (Stream output = File.OpenWrite(fileName)) { provider.Export(editor.Document, output); } eventAggregator.GetEvent <StatusBarEvent>().Publish($"Das Ausschüttungsschreiben für {detail.Reference} wurde erstellt."); detail.FileName = fileName; } string seriesFileName = DirectoryHelper.FindFundCashFlow(information.Fund.Id, cashFlowNumber); using (Stream output = File.OpenWrite(seriesFileName)) { provider.Export(seriesDocument.Document, output); } CommonProcesses.StartWord(seriesFileName); }