It doesn't say the first byte is %,
It says the file does not start with %PDF-
The buffer of the MemoryStream has a %PDF- as its first 5 characters but
none of the buffer is being sent to Response.OutputStream.
What I don't understand is why not.
Thanks,
Dan
robert engels wrote:
> How can it be 0 length if the first byte is a % ?
>
> On Dec 29, 2006, at 3:53 PM, Daniel Essin wrote:
>
>> The pdf is a 0 length file. There's probably no point in attaching it.
>>
>> Thanks. What next?
>> Dan
>>
>> robert engels wrote:
>>> Why don't you attach the pdf file?
>>>
>>> On Dec 28, 2006, at 6:21 PM, Daniel Essin wrote:
>>>
>>>> Daniel Essin wrote:
>>>> OK let me start over again. I was reading the dump incorrectly
>>>> and the
>>>> first byte is a %
>>>>
>>>> So all I have is the problem that the code produces a stream that,
>>>> when
>>>> received by acrobat, results in a message that says "File does not
>>>> begin
>>>> with '%PDF-'."
>>>>
>>>> This is the code:
>>>> HttpResponse resp = this.Response;
>>>> Document document = new Document();
>>>> System.IO.MemoryStream baos = new MemoryStream();
>>>> PdfWriter.GetInstance(document, baos);
>>>> resp.AppendHeader("Content-Length", baos.Length.ToString());
>>>> document.Open();
>>>> document.Add(new Paragraph("Hello World"));
>>>> document.Add(new Paragraph(DateTime.Now.ToLongTimeString()));
>>>> document.Close();
>>>> resp.ContentType = "application/pdf";
>>>> resp.Write(baos.ToArray());
>>>> resp.Flush();
>>>>
>>>>
>>>>> Daniel Essin wrote:
>>>>> I'll try putting these at the top.
>>>>>
>>>>> I think I figured out how to set the content length:
>>>>> resp.AppendHeader("Content-Length", baos.Length.ToString());
>>>>>
>>>>> Acrobat still complains that the data it is receiving does not
>>>>> begin
>>>>> with %PDF-
>>>>>
>>>>> The dump of the byte array still says it begins
>>>>> with 7PDF-
>>>>>
>>>>> Help, please,
>>>>> Dan
>>>>>
>>>>>> Paulo Soares wrote:
>>>>>>> Don't forget to set the content length.
>>>>>>>
>>>>>>> Paulo
>>>>>>>
>>>>>>> ----- Original Message -----
>>>>>>> From: "Daniel Essin" <[EMAIL PROTECTED]>
>>>>>>> To: <[email protected]>
>>>>>>> Sent: Thursday, December 28, 2006 10:31 PM
>>>>>>> Subject: [iText-questions] ByteArrayOutputStream
>>>>>>>
>>>>>>>
>>>>>>>> I'm trying to use iTextSharp to work through the examples in
>>>>>>>> Chapter 17 of
>>>>>>>> the
>>>>>>>> book. The first example worked perfectly. The second example of
>>>>>>>> writing to
>>>>>>>> the
>>>>>>>> response object through a ByteArrayOutputStream fails. It fails
>>>>>>>> because
>>>>>>>> Acrobat
>>>>>>>> complains that the stream should begin %PDF-.
>>>>>>>>
>>>>>>>> By examining the contents of the stream in the debugger, the
>>>>>>>> reason
>>>>>>>> becomes
>>>>>>>> clear. The first character of the stream is a 7 instead of a %.
>>>>>>>> I have no
>>>>>>>> clue
>>>>>>>> why and would appreciate some guidance.
>>>>>>>>
>>>>>>>> The code is:
>>>>>>>> HttpResponse resp = this.Response;
>>>>>>>> Document document = new Document();
>>>>>>>> System.IO.MemoryStream baos = new MemoryStream();
>>>>>>>> PdfWriter.GetInstance(document, baos);
>>>>>>>> document.Open();
>>>>>>>> document.Add(new Paragraph("Hello World"));
>>>>>>>> document.Add(new
>>>>>>>> Paragraph(DateTime.Now.ToLongTimeString()));
>>>>>>>> document.Close();
>>>>>>>> resp.ContentType = "application/pdf";
>>>>>>>> resp.Write(baos.ToArray());
>>>>>>>> resp.Flush();
>>>>>>>>
>>>>>>>> Thank you,
>>>>>>>> Dan Essin
>>>>>>>>
>>>>>>>>
>>>>>>>> ----------------------------------------------------------------
>>>>>>>> --
>>>>>>>> -------
>>>>>>>> Take Surveys. Earn Cash. Influence the Future of IT
>>>>>>>> Join SourceForge.net's Techsay panel and you'll get the chance
>>>>>>>> to share
>>>>>>>> your
>>>>>>>> opinions on IT & business topics through brief surveys - and
>>>>>>>> earn cash
>>>>>>>> http://www.techsay.com/default.php?
>>>>>>>> page=join.php&p=sourceforge&CID=DEVDEV
>>>>>>>> _______________________________________________
>>>>>>>> iText-questions mailing list
>>>>>>>> [email protected]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>>>>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>>>>> -----------------------------------------------------------------
>>>>>>> --
>>>>>>> ------
>>>>>>> Take Surveys. Earn Cash. Influence the Future of IT
>>>>>>> Join SourceForge.net's Techsay panel and you'll get the chance
>>>>>>> to share your
>>>>>>> opinions on IT & business topics through brief surveys - and
>>>>>>> earn cash
>>>>>>> http://www.techsay.com/default.php?
>>>>>>> page=join.php&p=sourceforge&CID=DEVDEV
>>>>>>> _______________________________________________
>>>>>>> iText-questions mailing list
>>>>>>> [email protected]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>>>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>>>>>
>>>>>> Sorry for being a bit dense but - could you please give me a hint
>>>>>> as to
>>>>>> the property name? I can't find any property of resp called
>>>>>> content length/
>>>>>>
>>>>>> Dan
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------
>>>>>> --
>>>>>> -----
>>>>>> Take Surveys. Earn Cash. Influence the Future of IT
>>>>>> Join SourceForge.net's Techsay panel and you'll get the chance to
>>>>>> share your
>>>>>> opinions on IT & business topics through brief surveys - and earn
>>>>>> cash
>>>>>> http://www.techsay.com/default.php?
>>>>>> page=join.php&p=sourceforge&CID=DEVDEV
>>>>>> _______________________________________________
>>>>>> iText-questions mailing list
>>>>>> [email protected]
>>>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>>>>
>>>>> -------------------------------------------------------------------
>>>>> --
>>>>> ----
>>>>> Take Surveys. Earn Cash. Influence the Future of IT
>>>>> Join SourceForge.net's Techsay panel and you'll get the chance to
>>>>> share your
>>>>> opinions on IT & business topics through brief surveys - and earn
>>>>> cash
>>>>> http://www.techsay.com/default.php?
>>>>> page=join.php&p=sourceforge&CID=DEVDEV
>>>>> _______________________________________________
>>>>> iText-questions mailing list
>>>>> [email protected]
>>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>>>
>>>> --------------------------------------------------------------------
>>>> --
>>>> ---
>>>> Take Surveys. Earn Cash. Influence the Future of IT
>>>> Join SourceForge.net's Techsay panel and you'll get the chance to
>>>> share your
>>>> opinions on IT & business topics through brief surveys - and earn
>>>> cash
>>>> http://www.techsay.com/default.php?
>>>> page=join.php&p=sourceforge&CID=DEVDEV
>>>> _______________________________________________
>>>> iText-questions mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>
>>> ---------------------------------------------------------------------
>>> ----
>>> Take Surveys. Earn Cash. Influence the Future of IT
>>> Join SourceForge.net's Techsay panel and you'll get the chance to
>>> share your
>>> opinions on IT & business topics through brief surveys - and earn
>>> cash
>>> http://www.techsay.com/default.php?
>>> page=join.php&p=sourceforge&CID=DEVDEV
>>> _______________________________________________
>>> iText-questions mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>>
>>
>> ----------------------------------------------------------------------
>> ---
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to
>> share your
>> opinions on IT & business topics through brief surveys - and earn cash
>> http://www.techsay.com/default.php?
>> page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/