Jump to content
We've recently updated our Privacy Statement, available here ×

jasperserver generating a blank PDF with Web Services (C# code)


ivan.krsul

Recommended Posts

I am trying to extract from the jasperserver a report, using Web Services 5.0, a report in PDF format, but I am am getting a blank PDF file.   I am coding in C#/ASP.NET and I managed to get the query to work for all formats except for PDF as follows:

 	// Setup WebClient         WebClient httpclient = new WebClient();        //Basic Auth        httpclient.Credentials = new NetworkCredential("jasperadmin", "jasperadmin");        httpclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");		        // Build resourceDescriptor        string requestXml = System.IO.File.ReadAllText(Server.MapPath("XMLFile.xml"));        // Send PUT		string requestAllResult = "";        requestAllResult = httpclient.UploadString("http://localhost:8080/jasperserver/rest/report/reports/IvanReports/TestReport2?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml);        // Get session cookie        string session = httpclient.ResponseHeaders.Get("Set-Cookie");        // Set session cookie        httpclient.Headers.Add("Cookie", session);        // Extract uuid, filename is always report        XmlDocument doc = new System.Xml.XmlDocument();        doc.LoadXml(requestAllResult);        XmlNode node = doc.DocumentElement.SelectSingleNode("uuid");        string uuid = node.InnerText;        //Build GET URL        string reportUrl = "http://localhost:8080/jasperserver/rest/report/";        reportUrl += uuid;        reportUrl += "?file=report";        // Get report        string report = httpclient.DownloadString(reportUrl);        // Send the report to the user		// I AM ASSUMING THE BUG IS HERE... but I may be mistaken        Response.ContentType = "application/pdf";        Response.AddHeader("Content-Disposition", "attachment; filename=file.pdf");        Response.ClearContent();        byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(report);        Response.OutputStream.Write(bytes, 0, bytes.Length);        Response.Flush();        Response.Close();[/code]
       

The XML I am using is as folows:

<resourcedescriptor isnew="false" name="TestReport2" uristring="/reports/IvanReports/TestReport2" wstype="reportUnit"> </resourcedescriptor>

The report I am trying to extract works well in jasperserver using the Web interface, and I can generate the PDF report there without any trouble.   

Does anyone know why this code is getting a blank PDF for the report?

Ivan

Link to comment
Share on other sites

  • 8 months later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...