Solved

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

Posted on 2008-06-11
15
5,441 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now