Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 20, 2019 11:46 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: QuickPdf Library
PostPosted: Sat Jun 23, 2012 9:16 am 
Offline

Joined: Tue Aug 19, 2008 9:13 am
Posts: 143
Location: Paris - France
Greetings all,

I 'm trying to use QuickPdf Library with RS 2011.4.r3.
The dll version is 8.15.
It's my first try with Declare, and it's an hard road....

I did get some simple examples working, ( thanks again to Charles Yeomans for guiding me ), like this one :
( ThePDFlib is a constant with dll's path )

#if TargetWin32

Soft Declare Function QuickPDFCreateLibrary Lib ThePDFlib () as integer
Soft Declare Function QuickPDFUnlockKey Lib ThePDFlib ( InstanceID as integer, TheLicenceKey as Wstring ) as integer
Soft Declare Sub QuickPDFReleaseLibrary Lib ThePDFlib ( InstanceID as integer )
Soft Declare Sub QuickPDFDrawText Lib ThePDFlib ( InstanceID as integer, x as double, y as double , TheText as Wstring )
Soft Declare Sub QuickPDFSaveToFile Lib ThePDFlib ( InstanceID as integer, ThePath as Wstring )

InstanceID = QuickPDFCreateLibrary ()

Dim Test as integer = QuickPDFUnlockKey ( InstanceID, TheLicenceKey )

if Test = 1 then
QuickPDFDrawText(InstanceID, 100, 500, TheText )
QuickPDFSaveToFile(InstanceID, ThePath )
end

QuickPDFReleaseLibrary(InstanceID)

#endif


I struggled some hours to have this declaration working :

char * QuickPDFRenderPageToString(int InstanceID, int DPI, int Page, int Options)

#if TargetWin32
Soft Declare Function QuickPDFRenderPageToString Lib ThePDFlib ( InstanceID as integer , DPI as integer, Page as integer ,Options as integer ) as Ptr

Soft Declare Function QuickPDFAnsiStringResultLength Lib ThePDFlib ( InstanceID as integer ) as integer

Dim data as MemoryBlock
data = QuickPDFRenderPageToString ( InstanceID , DPI, Page , Options )

' ==== Try to get the content as the string
Dim Size as integer
Size = QuickPDFAnsiStringResultLength ( InstanceID )

Dim mb as MemoryBlock
mb = data.StringValue ( 0, size )

return mb
#endif


Not sure if this is the best way, or if this code is secure, but it's working, and I can render PDF documents into pictures...

I'm trying now to add an image to a opened PDF doc, like the example in QuickPdf Library.

While loading a pic from a file, with this declare :

int QuickPDFAddImageFromFile(int InstanceID, wchar_t * FileName, int Options)

#if TargetWin32
Dim Test as integer

Soft Declare Function QuickPDFAddImageFromFile Lib ThePDFlib ( InstanceID as integer, TheFile as WString , Options as integer ) as integer
Test = QuickPDFAddImageFromFile ( InstanceID, TheFile , Options )
return Test
#endif


is now easy, I cant' find a way to add an image from a string, with this dll's function :

int QuickPDFAddImageFromString(int InstanceID, char * Source, int Options)

Extract from the QuickPdf Reference guide :

Description
Adds an image from memory to the selected document.
Once an image has been added to the document it can be drawn on any page multiple times without further increasing the size of the PDF file.
Supported image file types are: BMP, TIFF, JPEG, PNG, GIF, WMF and EMF.
For BMP and TIFF images, the CompressImages function can called before calling this function to compress the image data. Other image types are automatically compressed.

Syntax

DLL
int QuickPDFAddImageFromString(int InstanceID, char * Source, int Options)

Parameters

Source A string containing the image data. In the ActiveX version of the library this string must contain 16-bit characters, only the lower 8-bits of each character will be used.

Options For multi-page TIFF images this parameter specifies the page number to load.
For PNG images:
0 = Load the image as usual
1 = Load the alpha channel as a greyscale image
2 = Load the image and alpha channel (limit alpha to 8-bit)
3 = Load the image (limit image 8-bit/channel)
4 = Load the alpha channel (limit to 8-bit/channel)
5 = Load the image with alpha channel (limit both to 8-bit/channel)
6 = Load the image and alpha channel
For other image types this parameter should be set to 0.

Setting Options to -1 forces TIFF, EMF and WMF images to be loaded using the GDI+ graphics library. Multipage TIFF images can also be loaded using GDI+ by setting the Options parameter to -PageNumber (for example -3 for page 3).

Return values

0 The image data was invalid or the image was in an unsupported format
1 The image was added successfully. The value returned is the ImageID which can be used with functions like SelectImage and DrawImage.



As far as I understand, I'm suppose to pass a pointer to the string containing the picture.

Something like :

Soft Declare Function QuickPDFAddImageFromString Lib ThePDFlib ( InstanceID as integer, Source as Ptr , Options as integer ) as integer

I have tried everything I could think of, using memoryblock, CString, ...
I searched declare here, but I never could have the function returns 1 :(

Does anyone have an idea, or did that previously ?

Any help will be creatly appreciated, I'm getting mad with that one :twisted:

Thanks,
Fred

Here is the sample code :

Dim InstanceID as integer = QPdfInit

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 )


' ===Open the FIle
if ThePath ="" then
ThePath = "C:\DEV\PDF\Test.pdf"
end
Test = QPdfLoadFromFile ( InstanceID, ThePath , ThePass )

if Test= 1 then // Doc Opened
' ===Selected Document
Dim DocId as integer
DocId = QPDFSelectedDocument ( InstanceID )
DocId = DocId

' ==== Page Count
Dim PageCount as Integer = -1
PageCount = QPdfPageCount ( InstanceID )
PageCount = PageCount

' ==== Add Image to doc
ImageID = QPDFAddImageFromFile ( InstanceID, "C:\DEV\PDF\MyPic.png" , 0 ) //OK

Test = QPdfAddImageFromString ( InstanceID, MyStr , 0 ) // <----------------- ???

' ==== Select page 2
Test = QPDFSelectPage ( InstanceID , 2 )

' ==== Draw Image
if ImageID >0 then // Image added
Dim w , h as integer
w = QPDFImageWidth ( InstanceID )
h = QPDFImageHeight ( InstanceID )

Test = QPDFDrawImage ( InstanceID , 250, 450, w, h )
end

Dim TheNewPath as WString = "C:\DEV\PDF\Test with image.pdf"
QPdfSaveToFile ( InstanceID , TheNewPath )

// OK !!!


end //OpenDoc

QPdfRelease ( InstanceID )
end //InstanceID


Dll calls are wrapped into RS functions or methods.
BTW, is that good pratice ?

_________________
RB Studio Entreprise 2011r4, Macbook Pro with Mac OS 10.6.8, Windows XP SP3, MBS 12


Top
 Profile  
Reply with quote  
 Post subject: Re: QuickPdf Library
PostPosted: Tue Jun 26, 2012 1:26 pm 
Offline

Joined: Tue Aug 19, 2008 9:13 am
Posts: 143
Location: Paris - France
Really Guys ?
:roll:

Nobody has an idea ?

Thanks,
Fred

_________________
RB Studio Entreprise 2011r4, Macbook Pro with Mac OS 10.6.8, Windows XP SP3, MBS 12


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group