?
Solved

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

Posted on 2008-06-11
15
Medium Priority
?
5,700 Views
Last Modified: 2012-08-14
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
Comment
Question by:KBSLPDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 21764163
Post any relevant code you might have that we can use to troubleshoot your problem.
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 21764208
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
 

Author Comment

by:KBSLPDev
ID: 21764555
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:raterus
ID: 21768243
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
 

Author Comment

by:KBSLPDev
ID: 21816443
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
 
LVL 37

Expert Comment

by:samtran0331
ID: 21816736
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
 

Author Comment

by:KBSLPDev
ID: 21816799
There's about 300 pages on the report. It's only around 233k
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 21816996
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
 

Author Comment

by:KBSLPDev
ID: 21817330
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
 
LVL 37

Expert Comment

by:samtran0331
ID: 21821183
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
 

Author Comment

by:KBSLPDev
ID: 21822447
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
 
LVL 37

Expert Comment

by:samtran0331
ID: 21822503
> 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
 

Author Comment

by:KBSLPDev
ID: 21822563
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
 
LVL 37

Accepted Solution

by:
samtran0331 earned 2000 total points
ID: 21822743
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
 

Author Closing Comment

by:KBSLPDev
ID: 31466343
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question