RealBasic have several strings type.
There are two string declare types used on Windows :
CString (which is a null terminated ANSI string) and WString (which is a null terminated Wide Char string).
So, you can use also WString. Here is an example using WString.
ThePDFlib is a constant with the full Dll's path.
I think "Byval" is not needed, as RealBasic does it by default. Also RealBasic is supposed to automatically convert Strings to Wtring or CString in Declares. You just need to declare the correct string type and you can use a standard string for your parameters.
#if TargetWin32 // In case we try that on a Mac or a Linux Box....
Dim Test , ImageID as integer
Dim InstanceID as integer
' Dim TheLicenceKey as Wstring = "Your Licence here"
Dim ThePic as Picture
Dim Mb as MemoryBlock
Dim ThePass as string = ""
Dim ThePath as String
Dim DocId as integer
Dim PageCount as Integer = -1
' ==== Declare
Soft Declare Function QuickPDFCreateLibrary Lib ThePDFlib () as integer
Soft Declare Function QuickPDFUnlockKey Lib ThePDFlib ( InstanceID as integer, TheLicenceKey as Wstring ) as integer
Soft Declare Function QuickPDFLoadFromFile Lib ThePDFlib ( InstanceID as integer, ThePath as Wstring, ThePass as WString ) as integer
Soft Declare Function QuickPDFSelectedDocument Lib ThePDFlib ( InstanceID as integer ) as integer
Soft Declare Function QuickPDFPageCount Lib ThePDFlib ( InstanceID as integer ) as integer
Soft Declare Function QuickPDFAddImageFromFile Lib ThePDFlib ( InstanceID as integer, TheFile as WString , Options as integer ) as integer
Soft Declare Function QuickPDFAddImageFromString Lib ThePDFlib ( InstanceID as integer, Source as Ptr , Options as integer ) as integer
Soft Declare Function QuickPDFSelectPage Lib ThePDFlib ( InstanceID as integer , page as integer ) as integer
Soft Declare Function QuickPDFImageHeight Lib ThePDFlib ( InstanceID as integer ) as integer
Soft Declare Function QuickPDFImageWidth Lib ThePDFlib ( InstanceID as integer ) as integer
Soft Declare Function QuickPDFDrawImage Lib ThePDFlib ( InstanceID as integer , Left as double , Top as Double , Width as Double , Height as Double ) as integer
Soft Declare Sub QuickPDFSaveToFile Lib ThePDFlib ( InstanceID as integer, ThePath as Wstring )
Soft Declare Sub QuickPDFReleaseLibrary Lib ThePDFlib ( InstanceID as integer )
' =======
InstanceID = QuickPDFCreateLibrary ()
Test = QuickPDFUnlockKey ( InstanceID, TheLicenceKey )
if InstanceID > -1 then //OK
//Create a simple pic
Dim MyPic as new Picture ( 100 ,100 ,32 )
MyPic.Graphics.ForeColor = &c0000FF
MyPic.Graphics.FillRect ( 0, 0, MyPic.Width , MyPic.Height )
Dim MyStr as string = MyPic.GetData ( picture.FormatPNG )
Dim Mb as MemoryBlock = MyStr
' ===Open a FIle
ThePath = "C:\DEV\PDF\Test.pdf"
Test = QuickPDFLoadFromFile ( InstanceID , ThePath , ThePass )
if Test= 1 then // Doc Opened
' ===Selected Document
DocId = QuickPDFSelectedDocument ( InstanceID )
' ==== Page Count
PageCount = QuickPDFPageCount ( InstanceID )
' ==== Add Image to doc
ImageID = QuickPDFAddImageFromFile ( InstanceID, "C:\DEV\PDF\MyPic.png" , 0 ) //OK
' ===== But I can't get this one to work !
' Test = QuickPDFAddImageFromString ( InstanceID, MyStr , 0 ) // <---------??? OR :
Test = QuickPDFAddImageFromString ( InstanceID, Mb , 0 )
' ==== Select page 1
Test = QuickPDFSelectPage ( InstanceID , 1 )
' ==== Draw Image
if ImageID >0 then // Image added
Dim w , h as integer
w = QuickPDFImageWidth ( InstanceID )
h = QuickPDFImageHeight ( InstanceID )
Test = QuickPDFDrawImage ( InstanceID , 250, 450, w, h )
end
Dim TheNewPath as WString = "C:\DEV\PDF\Test with image.pdf"
QuickPDFSaveToFile ( InstanceID , TheNewPath ) // OK !!!
end //OpenDoc
QuickPDFReleaseLibrary ( InstanceID )
end //InstanceID
#endif
RealBasic have aslo a MemoryBlock Type :
A MemoryBlock object allocates a sequence of bytes in memory and manipulates those bytes directly. A MemoryBlock can be passed in place of a Ptr when used in a Declare call.
So, you can use a memory block to render a page to a string :
Soft Declare Function QuickPDFDARenderPageToString Lib ThePDFlib ( InstanceID as integer, FileHandle as integer , PageRef as integer ,Options as integer, DPI as integer ) as Ptr
Soft Declare Function QuickPDFAnsiStringResultLength Lib ThePDFlib ( InstanceID as integer ) as integer
Dim data as MemoryBlock
data = QuickPDFDARenderPageToString ( InstanceID, FileHandle , PageRef, Options, DPI )
Dim Size as integer
Size = QuickPDFAnsiStringResultLength ( InstanceID )
Dim mb as MemoryBlock
mb = data.StringValue ( 0, size )
ThePic = Picture.FromData ( Mb ) // Pic OK !!!!
But this is weird, as usually something like :
Soft Declare Function QuickPDFDARenderPageToString Lib ThePDFlib ( InstanceID as integer, FileHandle as integer , PageRef as integer ,Options as integer, DPI as integer ) as Ptr
dim m as MemoryBlock = QuickPDFDARenderPageToString(...)
if m <> nil then
//make picture
end if
should have been sufficient ! In fact, the size of the MemoryBlock isn't fixed when it's returned, so one needs to precise the size.
Fred
|