2014-05-01 93 views

回答

1

我使用下面的代碼片段。它將.trdx文件反序列化,然後創建一個Report(Telerik.Reporting.Report)實例。此報告實例可以轉換爲pdf。

 System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings(); 
     settings.IgnoreWhitespace = true; 

      //read the .trdx file contents 
      using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(path_to your_trdx_file, settings)) 
      { 
       Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = 
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer(); 

       //deserialize the .trdx report XML contents 
       Telerik.Reporting.Report report = (Telerik.Reporting.Report) 
        xmlSerializer.Deserialize(xmlReader); 

       string mimType = string.Empty; 
       string extension = string.Empty; 
       Encoding encoding = null; 

       // call Render() and retrieve raw array of bytes 
       // write the pdf file 
       byte[] buffer = Telerik.Reporting.Processing.ReportProcessor.Render(
       "PDF", report, null, out mimType, out extension, out encoding); 
       // create a new file on disk and write the byte array to the file 
       FileStream fs = new FileStream(Path_you_need_to_save_the_pdf_file, FileMode.Create); 
       fs.Write(buffer, 0, buffer.Length); 
       fs.Flush(); 
       fs.Close(); 
      } 
0

如果用戶Telerik報告2012或更新需要改變此

enter code here 

XmlReaderSettings設置新= XmlReaderSettings()上面的代碼; settings.IgnoreWhitespace = true;

 //read the .trdx file contents 
     using (
      XmlReader xmlReader = 
       XmlReader.Create(you trdx file path, 
        settings)) 
     { 
      ReportXmlSerializer xmlSerializer = 
       new ReportXmlSerializer(); 

      //deserialize the .trdx report XML contents 
      Report report = (Report)xmlSerializer.Deserialize(xmlReader); 

      Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource 
      { 
       ReportDocument = report 
      }; 
      string mimType = string.Empty; 
      string extension = string.Empty; 
      //Encoding encoding = null; 

      // call Render() and retrieve raw array of bytes 
      // write the pdf file 
      ReportProcessor reportProcessor = new ReportProcessor(); 

      RenderingResult renderingResult = reportProcessor.RenderReport("DOCX", instanceReportSource, null); 
      // create a new file on disk and write the byte array to the file 
      FileStream fs = new FileStream(@"D:\test\Dashboard.DOCX", FileMode.Create); 
      fs.Write(renderingResult.DocumentBytes, 0, renderingResult.DocumentBytes.Length); 
      fs.Flush(); 
      fs.Close(); 
     } 
相關問題