[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5850
  • Last Modified:

Getting error when opening PDF - File does not begin with PDF

When opening up a PDF generated by my web app, I get the following error : "File does not begin with '%PDF-'".

Here is more information:
The exact same code works on the server I'm migrating the code from. It also works on a development server
The error only appears only when I select a lot of records, thus making the PDF large. Single out records or shrinking the amount of selected records to render makes the error go away.
I've tried using firefox rather than IE and saving the file locally. The error still appears only when the report is pulling a lot of data.
Development matches production code exactly.
I can recreate the error on multiple client machines.

It seems to be server related but I'm not exactly sure how.

Any thoughts? Please?
0
KBSLPDev
Asked:
KBSLPDev
  • 7
  • 6
  • 2
1 Solution
 
raterusCommented:
Post any relevant code you might have that we can use to troubleshoot your problem.
0
 
samtran0331Commented:
Interestingly, if you google "File does not begin with", there are quite a few results.
http://www.google.com/search?q=File+does+not+begin+with+&rls=com.microsoft:en-us:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7

Seems to be something with the content type...
The second one (on TekTips) seems the most promising, look a few posts down:
"
in the file mime.types...."application/pdf"..
replace this line with this line "application/x-pdf"
"

so if in your code you have something like:
            response.ContentType = "application/pdf"
try changing it to
            response.ContentType = "application/x-pdf"
0
 
KBSLPDevAuthor Commented:
Yes, forgot to mention I tried that too. No joy.

I'll attach a code segment:
  	    Dim rpt As ActiveReport = Nothing	
  	    Try
 
                Select Case Session("intReport")
                    Case 7  'Freeze Date Report
                        rpt = New DotNetNuke.rptFreezeDate
                        rpt.UserData = strPUPName & "|" & strValiationID
		    	'set to view in landscape
 		End Select
                	rpt.PageSettings.Orientation = 2
	                rpt.Run(False)
            Catch eRunReport As Exception
                Response.Write("Report failed to run:\n" + eRunReport.ToString())
            End Try
 
            ' Create a memory stream and export report document to PDF Object
            Dim outStream As MemoryStream = New MemoryStream
            Dim pdf As New DataDynamics.ActiveReports.Export.Pdf.PdfExport
 
            ' Tell the browser this is a PDF document so it will use an appropriate viewer.
            ' changing per issue with pdf display issues ::  Response.ContentType = "application/pdf"
            Response.ContentType = "application/x-pdf"
            Response.AddHeader("content-disposition", "inline; filename=PUPReport.pdf")
 
            pdf.Export(rpt.Document, outStream)
 
            ' Move the postion back to the begining of the stream
            outStream.Seek(0, SeekOrigin.Begin)
 
            ' Write the report document byte array to the requestor:
            Response.BinaryWrite(outStream.ToArray())
            ' end this request/response
            Response.End()

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
raterusCommented:
Not sure the point of this since you're about to end the request,

            ' Move the postion back to the begining of the stream
            outStream.Seek(0, SeekOrigin.Begin)

How about just
outStream.Close

and while your at it, make sure any other code is properly closing connections to the pdf.
0
 
KBSLPDevAuthor Commented:
Did the changes you suggested and still getting the error. On a small set of data, the pdf appears fine. Just when it's larger is when I run into issues. The PDF connection is being closed properly. Otherwise the smaller set wouldn't work.

Next steps?
0
 
samtran0331Commented:
When you say "larger"...how large of a pdf are we talking about?
I use ActiveReports also and haven't had these issues with 30-page reports that are upwards of 6MB in size...
0
 
KBSLPDevAuthor Commented:
There's about 300 pages on the report. It's only around 233k
0
 
samtran0331Commented:
That shouldn't be a problem for AR.
I just compared the code I have to yours and the relevant parts are identical...
I've had to deal with some weird issues with AR in ASP.Net, but I've never seen this error message you're getting.
Just for giggles...try holding down the CTRL key and then clicking the button that starts the report generation...
0
 
KBSLPDevAuthor Commented:
Yes it does start report generation.
Since this works on dev but not on prod, I compared the configs closer and found that prod was somehow using .net 2.x rather than 1.x (Yes 1.x. this is an old dotnetnuke reporting site that requires 1.X).

When i move it back to 1.x, the log in screen comes up but when I successfully authenticate, I get a "Impersonation failure.". Any thoughts?
0
 
samtran0331Commented:
is the app using impersonation?
if no, does the aspnet,NETWORK SERVICE, IUSR_SERVERNAME,IWAM_SERVERNAME accounts have permissions to the app's folder (and any other relevant folders)?
0
 
KBSLPDevAuthor Commented:
Okay. I got passed the impersonation issue as the app pools were a little differnt. I had to change the identity to use local system.  It works now.

NOW we're running on the same .net version. I run the report and get the same issue as with .net 2.0. I'm wondering if there is a timeout issue.. Checking.

Any ideas?
0
 
samtran0331Commented:
> I'm wondering if there is a timeout issue..

With filesizes that small; I doubt it....does the query take a long time to run (even though the report size is small)?
Besides that, I'm at a loss...maybe make sure you have the latest version of AR?
0
 
KBSLPDevAuthor Commented:
I'm thinking the same thing. I timed it and it came back after 120 seconds. Checking web config and web settings for any references. Wondering if the SQL server is timing out by default, as there is no command timeout setting in the web.config.
0
 
samtran0331Commented:
At this point, I"m at a loss, so it would be worth seeing if the problem is in the connecton...push the timeout out farther to see if it is more stable..something along the lines of:

connectionString="Data Source=dotnetdevpc01\sql2000;Initial Catalog=Northwind;Integrated Security=True;Pooling=False;Connect Timeout=180;Connection Lifetime=12;Connection Reset=True;Max Pool Size=1;"
0
 
KBSLPDevAuthor Commented:
That fixed it!!!! I set the connect timeout to 900 and it works like a champ!! Thanks so much for the help!
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now