RichTextFormatter textFormatter; //Easier to cache public void CreateDocument(string name, int pageAmount, double width, double height) { PDFHolder documentClass = new PDFHolder(); // Create an empty page for (int i = 0; i < pageAmount; i++) { PdfPage page = documentClass.document.AddPage(); page.Size = PageSize.A4; documentClass.graphicsList.Add(XGraphics.FromPdfPage(page)); } textFormatter = new RichTextFormatter(); documents[name] = documentClass; }
public UserControl1(CaseObject caseObj) { m_CaseObj = caseObj; InitializeComponent(); foreach (DataAttachment attachment in m_CaseObj.attachments.GetManifestAttachments()) { try { if (!Directory.Exists(TempDir)) { Directory.CreateDirectory(TempDir); } String filename = TempDir + attachment.attachmentId; if (File.Exists(filename)) { File.Delete(filename); } using (MemoryStream ms = new MemoryStream(attachment.attachmentData.GetBuffer())) { FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); fs.Write(ms.ToArray(), 0, (int)ms.Length); fs.Close(); } PDFHolder pf = new PDFHolder(); pf.LoadPDF(filename); WindowsFormsHost wfh = new WindowsFormsHost(); wfh.Child = pf; TabItem ti1 = new TabItem(); ti1.Header = attachment.attachmentId; ti1.Content = wfh; ManifestTab.Items.Add(ti1); } catch (Exception ex) { //TODO: Log Message here. } } }
private void GenerateReport(IEnumerable data, String path, String ExportFormat) { try { LocalReport report = new LocalReport(); ReportDataSource ds = new ReportDataSource("CaseListDataSet", data); report.DataSources.Add(ds); report.ReportPath = path; report.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted)); Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtention; if (ExportFormat == "PDF") { //export report to PDF byte[] bytes = report.Render( "PDF", null, out mimeType, out encoding, out filenameExtention, out streamids, out warnings); using (FileStream fs = new FileStream("Report.pdf", FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); } PDFHolder pf = new PDFHolder(); System.Windows.Forms.Integration.WindowsFormsHost wh = new System.Windows.Forms.Integration.WindowsFormsHost(); wh.Child = pf; Window pdfWin = new Window(); pdfWin.Content = wh; pdfWin.Show(); pf.LoadPDF("Report.pdf"); } else if (ExportFormat == "Export") { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.FileName = "Report"; saveFileDlg.Filter = "Excel Worksheets|*.xls"; saveFileDlg.DefaultExt = ".xls"; Nullable <bool> result = saveFileDlg.ShowDialog(); if (result == true) { //export report to excel worksheet byte[] bytes = report.Render( "Excel", null, out mimeType, out encoding, out filenameExtention, out streamids, out warnings); using (FileStream fs = new FileStream(saveFileDlg.FileName, FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); } } } report.Dispose(); } catch (Exception exp) { log.PrintInfoLine("GenerateReport Exception: " + exp); } }