So I have been successfully creating PDFs with my code for a while now and all of a sudden I started getting the "File name does not begin with '%PDF-'" error when I call MyDocument.DrawToWeb(True).
If I save the file instead of using the DrawToWeb(), the PDF will open fine, and if I open it in Notepad it clearly starts with %PDF-. Also, If I don't open the PDF and just send it via FireMail, then the PDF also opens just fine. All of these methods use the same code to generate the file, so I know there is nothing actually wrong with the PDF, so I figure it must be IE. However, if I save the file to disk and then choose to open it in IE, then it still displays correctly, and it also errors in Firefox.
However, if I create a new page and create a PDF with some text in it then it works, which makes me think its my code, but why would it only not work for DrawToWeb()?????
Any Ideas?
File name does not begin with '%PDF-'
Re: File name does not begin with '%PDF-'
Forum member · Mar 31, 2008Ok, well it turns out the javascript that was at the top of my .aspx page is being appended to the PDF file, not sure why it is doing that, or why it worked before, and not now.
It appears that the quotes in the script tag is what is killing it, if I remove the quotes from the <script language="javascript"> tag, then it works fine, if I leave the quotes in, it dies.
Anyone know of away to get this to not append the javascript to the file? Its working now, but it shouldn't be including the script in the PDF file.
Re: File name does not begin with '%PDF-'
Support · Mar 31, 2008Hello,
Can you try adding the below line of code immediately after the DrawToWeb() method and see if that helps. Adding the below line will prevent any stray contents from being output after the PDF stream is drawn.
Visible = False
Thanks,
ceTe Software Support Team
Re: File name does not begin with '%PDF-'
Forum member · Mar 31, 2008Using Visible = False didn't work, but I put Response.Clear() before I declared the MyDocument, and the javascript doesn't show up!! Thanks for the idea!!