Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Adding Drawing.Bitmap
  FAQ FAQ  Forum Search   Register Register  Login Login

Adding Drawing.Bitmap

 Post Reply Post Reply
Author
Message
Jim Sullivan View Drop Down
Team Player
Team Player


Joined: 10 Nov 05
Location: United States
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jim Sullivan Quote  Post ReplyReply Direct Link To This Post Topic: Adding Drawing.Bitmap
    Posted: 23 Jun 09 at 8:06PM
I'm using ASP.NET and one of my systems generates a Drawing.Bitmap object.  I need to then add that to my PDF.  I tried encoding the bitmap and then using AddImageFromString, but it doesn't seem to work.
 
Has anyone else tried to use an AddImage function to add a bitmap from memory, not from a file?
 

Dim stream As New IO.MemoryStream()

bmp.Save(stream, Drawing.Imaging.ImageFormat.Bmp)

bitmapString = enc.GetString(stream.ToArray())

Dim encoding As New System.Text.ASCIIEncoding

Dim buffer As Byte()

buffer = encoding.GetBytes(bitmapString)

qp.AddImageFromString(buffer, 0)

 
bmp is the drawing.bitmap and enc is a Text.Encoding
Back to Top
Jim Sullivan View Drop Down
Team Player
Team Player


Joined: 10 Nov 05
Location: United States
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jim Sullivan Quote  Post ReplyReply Direct Link To This Post Posted: 24 Jun 09 at 5:30PM
I created a new app so that I could isolate my requrements.  Here's the function:
 

 
        Dim bmp As New Drawing.Bitmap("C:\temp\b.bmp")
        Dim pr As New QuickPDFDLL0712.PDFLibrary(Server.MapPath("~\") + "bin\QuickPDFDLL0713.dll")
        pr.UnlockKey("mykey")
        Dim x As Int32 = pr.AddImageFromFile("C:\temp\a.bmp", 0)
 
        Dim buffer As Byte()
        Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
        bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
        buffer = stream.ToArray
        Dim y As Int32 = pr.AddImageFromString(buffer, 0)
        pr.SelectImage(x)
        pr.DrawImage(50, 100, 300, 100)
        pr.SelectImage(y)
        pr.DrawImage(50, 300, 300, 100)
        pr.SaveToFile("c:\temp\a.pdf")
 
The variable y returns a 0, meaning that it couldn't add the image.
 
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jun 09 at 9:57AM
Originally posted by Jim Sullivan Jim Sullivan wrote:

Dim pr As New QuickPDFDLL0712.PDFLibrary(Server.MapPath("~\") + "bin\QuickPDFDLL0713.dll")

This is probably just an error in your post, but you've listed both QuickPDFDLL0712 and QuickPDFDLL0713 there, which won't work.
Back to Top
Jim Sullivan View Drop Down
Team Player
Team Player


Joined: 10 Nov 05
Location: United States
Status: Offline
Points: 36
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jim Sullivan Quote  Post ReplyReply Direct Link To This Post Posted: 25 Jun 09 at 2:39PM
Well... since I'm using the DLL and the wrapper, it does work.  The 12 one just references the namespace, which I can set to anything I want.  The only time it would cause a problem is if the function call within the DLL were changed.  Or I'd be missing a reference to a new function.  Neither applies in this case.
 
But anyway, I threw this code together in a new project, and my original project has all of the references correct.
Back to Top
deabrew View Drop Down
Newbie
Newbie
Avatar

Joined: 19 Jan 09
Status: Offline
Points: 43
Post Options Post Options   Thanks (0) Thanks(0)   Quote deabrew Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jul 09 at 2:21PM
Jim,

Did you get any further with this?
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 22 Jul 09 at 5:55AM
Hi Jim,

It looks as if you're trying to convert from a byte array to a string and then back to a byte array. The code we've provided below should provide a more direct way.

The ToArray method of the stream class returns a byte array that can be passed directly to the AddImageFromString function.

--------------------------
Dim bitmap As New Bitmap(100, 100)
Dim graphics As Graphics = graphics.FromImage(bitmap)
Dim brush As New SolidBrush(Color.Red)
graphics.FillRectangle(brush, 0, 0, 100, 100)
brush = New SolidBrush(Color.Blue)
graphics.FillEllipse(brush, 20, 20, 60, 60)

Dim ms As New IO.MemoryStream()
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
Dim imageData As Byte() = ms.ToArray()

Dim qp As New QuickPDFDLL0714.PDFLibrary("<path>\QuickPDFDLL0714.dll")

qp.UnlockKey("<Insert License Key>")

' Set the images to be compressed
qp.CompressImages(1)

' Load the image from the byte array
qp.AddImageFromString(imageData, 0)

' Draw the image onto the page
qp.DrawImage(100, 500, 200, 200)

' Save the PDF
qp.SaveToFile("<path>\system.drawing.pdf")
--------------------------

I hope this helps.

Cheers,
- Rowan.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store