From: Dooza on
Hi there,
I am using the ASP to PDF component from www.asppdf.com and have an
unusual problem when displaying a blob from the database.

When there is an image stored in my SQL2000 field of type image, and I
use this:

Params = "x=337; y=408; scalex=.33; scaley=.33"
Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
Page.Canvas.DrawImage SigImage, Params

The image gets drawn in the PDF and everything is fine.

If I try to create a PDF using the same record, but where the image
filed is NULL, I get this error:

Persits.PdfManager.1 error '800a002f'

A safe array of bytes is expected as an argument.

So I thought I need to check if the field isn't null before attempting
to draw it onto the canvas, so I tried this:

If LEN(rsMotor("Photo").Value) > 0 Then
'Insert Photo
Params = "x=337; y=408; scalex=.33; scaley=.33"
Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
Page.Canvas.DrawImage SigImage, Params
End if

Using this with an image stored in the field gives me the same error
message, its only when the field is empty that the above code works and
doesn't draw the image on the PDF.

I also tried this:

If NOT(ISNULL(rsMotor("Photo").Value)) Then
'Insert Photo
Params = "x=337; y=408; scalex=.33; scaley=.33"
Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
Page.Canvas.DrawImage SigImage, Params
End if

But still got the same error.

If I don't use any checking code, and have NULL in the image field, I
get the same error. This must be something to do with the binary
content, how can I detect if there is binary content?

Steve
From: "Jon Paal [MSMD]" Jon nospam Paal on
http://databases.aspfaq.com/database/how-do-i-prevent-nulls-in-my-database-from-mucking-up-my-html.html

http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html


From: Dooza on
Jon Paal [MSMD] wrote:
> http://databases.aspfaq.com/database/how-do-i-prevent-nulls-in-my-database-from-mucking-up-my-html.html
>
> http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html

Hi Jon,
Thanks for the pointers, I like the idea of doing it in SQL, as I am
already using a view to get the data to the page.

I am still open to other ideas.

Cheers,

Steve
From: Dooza on
Dooza wrote:
> Jon Paal [MSMD] wrote:
>> http://databases.aspfaq.com/database/how-do-i-prevent-nulls-in-my-database-from-mucking-up-my-html.html
>>
>>
>> http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html
>
> Hi Jon,
> Thanks for the pointers, I like the idea of doing it in SQL, as I am
> already using a view to get the data to the page.
>
> I am still open to other ideas.
>
> Cheers,
>
> Steve

I have gone for a temporary solution, as it seems that as soon as you do
a length check or isnull check on the binary field it becomes unusable.

I have used this in my SQL view:

CASE WHEN (MC.mct_photo IS NULL)
THEN '0' ELSE '1' END AS PhotoCheck

And this on my page:

If rsMotor("PhotoCheck") = 1 Then
'Insert Photo
Params = "x=337; y=408; scalex=.33; scaley=.33"
Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
Page.Canvas.DrawImage SigImage, Params
End if

Does anyone have any experience with using binary data in asp? Am I
right in thinking that the starting position has changed due to the
length check? Is there a way to reset the starting position?

Cheers,

Steve
From: Dave Anderson on
Dooza wrote:
> I have gone for a temporary solution, as it seems that as soon as you
> do a length check or isnull check on the binary field it becomes
> unusable.
> I have used this in my SQL view:
>
> CASE WHEN (MC.mct_photo IS NULL)
> THEN '0' ELSE '1' END AS PhotoCheck
>
> And this on my page:
>
> If rsMotor("PhotoCheck") = 1 Then
> 'Insert Photo
> Params = "x=337; y=408; scalex=.33; scaley=.33"
> Set SigImage = Doc.OpenImageBinary(rsMotor("Photo").Value)
> Page.Canvas.DrawImage SigImage, Params
> End if
>
> Does anyone have any experience with using binary data in asp? Am I
> right in thinking that the starting position has changed due to the
> length check? Is there a way to reset the starting position?

Rather than checking for NULL, use DATALENGTH:
http://msdn2.microsoft.com/en-us/library/ms173486.aspx




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.