private RadFlowDocument MergeTemplateWithData(IEnumerable mailMergeSource) { RadFlowDocument template = this.CreateMailMergeDocumentTemplate(); RadFlowDocument mergedDocument = template.MailMerge(mailMergeSource); return(mergedDocument); }
private void OnCreateContract() { SetFormattedFields(); Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider(); using (Stream input = File.OpenRead(SelectedTemplate)) { document = provider.Import(input); } // perform Mailmerge List <InternshipContractModel> interns = new List <InternshipContractModel>(); interns.Add(InternshipData); RadFlowDocument resultDocument = document.MailMerge(interns); // create pdf Filename FileInfo fileInfo = new FileInfo(SelectedTemplate); string fileName = $"Offerletter for {InternshipData.FirstName} {InternshipData.LastName}.pdf"; string outputFile = Path.Combine(fileInfo.DirectoryName, fileName); Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfprovider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider(); using (Stream output = File.OpenWrite(outputFile)) { pdfprovider.Export(resultDocument, output); } SelectedFileName = outputFile; }
public byte[] BuildReport(DataCell[,] pitsDesc, DataCell[,] labDataGrid, DataCell[,] fieldDataGrid, string mapImageUrl, List <string> attachedFiles) { ReportDataSource reportDataSource = new ReportDataSource(); m_Document = m_Document.MailMerge(new List <ReportDataSource>() { reportDataSource }); Section section = m_Document.Sections[0]; if (pitsDesc != null) { AddNewHeader(section, "תיאור ממצאי הסקר"); List <Table> pitDataTables = new TableBuilder(pitsDesc).Resolve(m_Document, 0, 100); foreach (Table table in pitDataTables) { section.Blocks.Add(table); section.Blocks.Add(new Paragraph(m_Document)); } } if (labDataGrid != null) { AddNewHeader(section, "תוצאות בדיקת מעבדה"); List <Table> labDataTables = new TableBuilder(labDataGrid).Resolve(m_Document, Convert.ToInt32(ConfigurationManager.AppSettings["labDataRepeaters"]), Convert.ToInt32(ConfigurationManager.AppSettings["tableMax"])); foreach (Table table in labDataTables) { section.Blocks.Add(table); section.Blocks.Add(new Paragraph(m_Document)); } } if (fieldDataGrid != null) { AddNewHeader(section, "תוצאות נתוני שטח"); List <Table> fieldDataTables = new TableBuilder(fieldDataGrid).Resolve(m_Document, Convert.ToInt32(ConfigurationManager.AppSettings["fieldDataRepeaters"]), Convert.ToInt32(ConfigurationManager.AppSettings["tableMax"])); foreach (Table table in fieldDataTables) { section.Blocks.Add(table); section.Blocks.Add(new Paragraph(m_Document)); } } if (mapImageUrl != null) { AddNewHeader(section, "מפה"); CreateImage(mapImageUrl, section); section.Blocks.Add(new Paragraph(m_Document)); } if (attachedFiles != null) { AddNewHeader(section, "קבצים מקושרים"); foreach (string attachedFileUrl in attachedFiles) { CreateImage(attachedFileUrl, section); section.Blocks.Add(new Paragraph(m_Document)); } } DocxFormatProvider formatProvider = new DocxFormatProvider(); byte[] renderedBytes = null; using (MemoryStream ms = new MemoryStream()) { formatProvider.Export(m_Document, ms); renderedBytes = ms.ToArray(); } return(renderedBytes); }