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

0

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();

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

ivan.krsul's picture
Joined: Apr 11 2014 - 8:00am
Last seen: 5 years 3 months ago

Hi I have the same problem. I download Blank PDFs.

I'm using Python to send http requests to jasperserver

and my report is containing charts and tables.

does anyone find the solution to this problem?

Thanks,

Assia

assiacpge2011 - 4 years 2 months ago

2 Answers:

0

I was getting blank PDFs from Chrome REST clients I guess because they were messing up with encoding. I tried 'Send and Download' method in Postman and it downloaded a correct PDF. Cheers

Voltron&#039;e's picture
Joined: Feb 21 2013 - 1:20pm
Last seen: 2 years 8 months ago
0

Hi I have the same problem. I download Blank PDFs.

I'm using Python to send http requests to jasperserver

and my report is containing charts and tables.

does anyone find the solution to this problem?

Thanks,

Assia


 

assiacpge2011's picture
Joined: Jan 30 2015 - 12:56pm
Last seen: 3 years 5 months ago
Feedback
randomness