/ / Comment exporter le rapport créé à l'aide de Telerik Reporting (.trdx) au format PDF? - c #, visual-studio, pdf, export, rapport telerik

Comment exporter le rapport créé à l'aide de Telerik Reporting (.trdx) au format PDF? - c #, visual-studio, pdf, export, rapport telerik

J'utilise Telerik Report Designer (autonome) pour concevoir un rapport (.trdx). Comment puis-je l'exporter au format PDF par programme en code C #?

Réponses:

1 pour la réponse № 1

J'ai utilisé l'extrait de code ci-dessous. Il désérialise le fichier .trdx puis crée une instance Report (Telerik.Reporting.Report). Cette instance de rapport peut ensuite être convertie en 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 pour la réponse № 2

Si vous utilisez Telerik Reporting 2012 ou une version plus récente, le code ci-dessus doit être remplacé par ce code.

enter code here

Paramètres XmlReaderSettings = new 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:testDashboard.DOCX", FileMode.Create);
fs.Write(renderingResult.DocumentBytes, 0, renderingResult.DocumentBytes.Length);
fs.Flush();
fs.Close();
}