Yes, the base64 string and decode function are OK, my problem is when i try to create the pdf.
I have some type of problem in the following lines:
Main Topics
Browse All TopicsGuys, i got error "Files does not begin with '%PDF-'. when create a file from string base64.
I have a asp source with a pdf coded in string base64, i used a function to decode to binary and when i try to show/create the file i have the error, i think is a charset problem, can you help me please?.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Using notepad to remove the non b64-encoded data, I saved the attached a.b64.txt file (yes - I hate notpad for always adding .txt to anything I save, but I was being lazy).
The using this php command line ...
\php5\php -r "file_put_contents('a.pdf'
I ended up with a.pdf.
Opening a.pdf opens fine!
Both files attached.
Can you save the PDF in ASP so you have a PDF saved by the server and one saved by your browser. Are they the same? This is to test if the issue is the browser or the server.
Can you try using Firefox with Firebug to monitor the headers being sent. Are there any additional headers being sent by the server which you didn't know about?
It looks to me like there is an implicit conversion going on. In your statement:
nGroup = Hex(nGroup)
nGroup = String(6 - Len(nGroup), "0") & nGroup
pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) & _
Chr(CByte("&H" & Mid(nGroup, 3, 2))) & _
Chr(CByte("&H" & Mid(nGroup, 5, 2)))
sOut = sOut & Left(pOut, numDataBytes)
the sOut variable is being created as a string of 16-bit values, rather than the 8-bit characters you need. I'm no guru in VBScript, but I think you need to use the
ChrB
function in there somewhere. Perhaps ...
pOut = ChrB(CByte("&H" & Mid(nGroup, 1, 2))) & _
ChrB(CByte("&H" & Mid(nGroup, 3, 2))) & _
ChrB(CByte("&H" & Mid(nGroup, 5, 2)))
Chr Function
http://msdn.microsoft.com/
(see also the AscB() function)
If that does not work, I suggest (for debugging purposes) breaking that long sequence into assignments of three variables and then concatenating them. Breakpoint in your code to verify that the sOut is being increased in length by only one byte per variable (rather than the two bytes that is currently happening).
-- Dan
My thought was the implicit conversion of the & operator -- it concatenates strings and in a system where "string" means "sequence of 16-bit UNICODE characters" then each one-byte character gets converted to a 2-byte character as the temporary string is constructed for the concatenation.
If that's the case, then even ChrB() might not work.
In this micrsoft blog,
http://blogs.msdn.com/eric
one contributor points out that VBscript simpoly does not support the concept of a string compsed of 9-bit bytes. They offer a number of work-arounds, but so far I haven't seen a simple solution. I'll keep looking...
I think I answered it with http:#a21903460
RQuadling's
Business Accounts
Answer for Membership
by: DanRollinsPosted on 2008-06-28 at 19:16:40ID: 21892719
I can verify that the first eight bytes of the decoded base64 text in the source code file respnsePdf.txt is, indeed:
e.net/demo /base64.ph p
%PDF-1.4
I used the base64 decoder here:
http://makcoder.sourceforg
I cannot vouch for how well the decoder in your source code works. I suggest that you test it fully.