in Education by
I've inherited a legacy application that is supposed to grab an on the fly pdf from a reporting services server. Everything works fine up until the point where you try to open the pdf being returned and adobe acrobat tells you: Adobe Reader could not open 'thisStoopidReport'.pdf' because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded). I've done some initial troubleshooting on this. If I replace the url in the WebRequest.Create() call with a valid pdf file on my local machine ie: @"C:temp/validpdf.pdf") then I get a valid PDF. The report itself seems to work fine. If I manually type the URL to the reporting services report that should generate the pdf file I am prompted for user authentication. But after supplying it I get a valid pdf file. I've replace the actual url,username,userpass and domain strings in the code below with bogus values for obvious reasons. WebRequest request = WebRequest.Create(@"http://x.x.x.x/reportServer?/reports/reportNam&rs:format=pdf&rs:command=render&rc:parameters=blahblahblah"); int totalSize = 0; request.Credentials = new NetworkCredential("validUser", "validPass", "validDomain"); request.Timeout = 360000; // 6 minutes in milliseconds. request.Method = WebRequestMethods.Http.Post; request.ContentLength = 0; WebResponse response = request.GetResponse(); Response.Clear(); BinaryReader reader = new BinaryReader(response.GetResponseStream()); Byte[] buffer = new byte[2048]; int count = reader.Read(buffer, 0, 2048); while (count > 0) { totalSize += count; Response.OutputStream.Write(buffer, 0, count); count = reader.Read(buffer, 0, 2048); } Response.ContentType = "application/pdf"; Response.Cache.SetCacheability(HttpCacheability.Private); Response.CacheControl = "private"; Response.Expires = 30; Response.AddHeader("Content-Disposition", "attachment; filename=thisStoopidReport.pdf"); Response.AddHeader("Content-Length", totalSize.ToString()); reader.Close(); Response.Flush(); Response.End(); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
View the pdf file that you get back in notepad.exe. I suspect that you will see HTML in there. If you call a web page that is a pass through page, that severs up a pdf file. The web request will get back the HTML not the PDF file. If you call a web site that has a pdf file directly, like http://www.somesite.com/file.pdf your code will work. The problem is that you probably have a pass through web page that hides the true location of the pdf file. The way I have gotten around this was to create an ISAPI DLL that allowed you to pass in the parameters it need to determine what pdf file need to be sent back. Than the ISAPI DLL would stream back the pdf with a content type of "application/pdf".

Related questions

0 votes
    In order to create the proper queries I need to be able to run a query against the same datasource ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    I know that the name of the user account can be retrieved from the built in variable User!UserID but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    Mention the benefits of reporting with BW over R/3....
asked Jan 5, 2021 in Technology by JackTerrance
0 votes
    If I want to save a plot to a PDF file, which of the following is a correct way of doing that? (a) ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I want to upload the file pdf to the folder but a file is not saved to a folder. I already read the ... .run(debug=True)``` Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    dev.copy2pdf specifically copy a plot to a PDF file. (a) True (b) False This question was posed to ... learning-in-Data-Science,Data-Science-Lifecycle,Applications-of-Data-Science...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    4. Date and Time are supported as Data Type in Calc. 5. When using functions and formulas in LibreOffice Calo, it ... and send me fast Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    (GCP) Google Cloud Platform ETL functions are supported by which of the following services in GCP? 1) Cloud ... 4) Cloud Dataproc Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    What method should be used to obtain a list of supported operations in REST services? 1. GET 2. DELETE 3. HEAD 4. OPTION...
asked Jun 24, 2021 in Technology by JackTerrance
0 votes
    Which type of comment is not supported in R? (a) Single-line comments (b) Multi-line comments (c ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    A 10 μF capacitor is charged from a 5 volt source through a resistance of 10 kΩ. The charging current offer 35 ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 12, 2021 in Education by JackTerrance
0 votes
    Which platform is R imported to after charting as a PDF? (a) Adobe Illustrator (b) Adobe Photoshop ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    Explain SCD TYPE 3 through mapping....
asked Mar 29, 2021 in Technology by JackTerrance
...