Hi all,
I am trying to print an image from my database but I can't seem to find an example of how to do it.
Something like (Pseudocode):
Dim MyImage
Dim MyAreaGroup
Set MyAreaGroup = m_objPage.AddAreaGroup( 400, 300 )
byteImage = m_objDoc.AddRawImageData( "Top.gif", m_objRecordSet("Image1") )
Set MyImage = MyAreaGroup.AddImage( byteImage, 0, 0 )
Can an image be imported from a database?
Thanks, Brian
Image From DB
Re: Image From DB
Support · Feb 10, 2006Hello Brian,
Yes this is no problem. In fact the code you posted should work as long as the "Image1" field is a Image or BLOB data type containing a valid image.
The key is that the AddRawImageData method will return a string which uniquly identifies the image within the document (in this case byteImage will be a string with a value of something like "raw:Top.gif"). That string can then be used anywhere in the document when adding an Image page element just as your example illustrated.
Thanks,
ceTe Software Support Team
Re: Image From DB
Forum member · Feb 13, 2006Thanks for the replay,
But I'm not sure what ImageName is suppose to be? I get the following error on the AddRawImageData line. I tested the field for a valid image using another asp program and it displays ok using "Response.BinaryWrite(rsRecord("Image1"))."
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'm_objDoc.AddRawImageData'
/testbartonweb/Policies_toPDF.asp, line 180
Sub AddImage
Dim objImage, byteImage
Dim MyAreaGroup
Set MyAreaGroup = m_objPage.AddAreaGroup( 400, 300 )
byteImage = m_objDoc.AddRawImageData( "Image1", m_objRecordSet("Image1") ) <-- **** error *****
Set objImage = MyAreaGroup.AddImage( byteImage, 0, 0 )
End Sub
Thanks, Brian
Barton Hospital
Re: Image From DB
Support · Feb 13, 2006Brian,
Well I looked into this a bit more and it turns out that any image data coming out of the RecordSet needs to be accessed using the GetChunk method. So in other words the line that is receiving the error should look something like this:
byteImage = m_objDoc.AddRawImageData( "Image1", m_objRecordSet("Image1").GetChunck(imageSize) )
In the test example we ran here the above did not receive any errors.
Thanks,
ceTe Software Support Team
Re: Image From DB
Forum member · Feb 22, 2006OK, that worked great. Now I want to import my watermark from my database. Here is my code but I get "A drawing error has occured so I'm guessing that background images can only come from files.
byteImage = m_objDoc.AddRawImageData( "Watermark", m_objRecordSet("Watermark").GetChunk(1024) )
Set BackgroundImage = m_objPage.AddBackgroundImage( byteImage)
Thanks again,
Brian
Re: Image From DB
Support · Feb 22, 2006Hello Brian,
Background images can be added from database without any problem. I was able to add one successfully using the same method you used. The output from AddRawImageData can be used as the filepath on an AddImage method or AddBackgroundImage method.
Can you please tell us the exact error you are getting when trying to add the watermark using the AddBackgroundImage method?
Thanks,
ceTe Software Support Team
Re: Image From DB
Forum member · Feb 22, 2006I will look at the code some more to see if I can figure it out before I email you my code. The query is ok so maybe my image is too large. It helps knowing that the code is working on your site so it must be something I'm doing.
Thanks, Brian
Re: Image From DB
Support · Feb 22, 2006Hello Brian,
I just realized after looking at your code, that the number you pass to the GetChunk() method is the number of bytes allowed. So, please make sure that the value in bytes you are passing to the GetChunk() method is equal to or greater than the size of the image in bytes.
Thanks,
ceTe Software Support Team
Re: Image From DB
Forum member · Feb 22, 2006Yep, looks like that's it. It prints but it's acting funny. When I scroll up and down the document the text and image disappears. I think I will be ok when I shrink down the image.
Thanks, Brian