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 > Sample Code
  New Posts New Posts RSS Feed - Using QPL8.xx with RealBasic, RealStudio
  FAQ FAQ  Forum Search   Register Register  Login Login

Using QPL8.xx with RealBasic, RealStudio

 Post Reply Post Reply
Author
Message
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Topic: Using QPL8.xx with RealBasic, RealStudio
    Posted: 23 Jun 12 at 9:00AM

The RealBasic type of CString uses 8bit characters therefore we need to used the 'A' functions to pass and return the 8bit strings as a CSTRING.  The standard QPL functions use Unicode strings.

If a QPL function passes or returns a CSTRING then you need to add an 'A' to the function name to use the 8bit version.

  QuickPDFUnlockKeyA
  QuickPDFLoadFromFileA
  QuickPDFSaveToFileA
  ...  + more

Andrew

----------------------------------------------------------------------

Sub Action()
  const DLL_NEW = "QuickPDFDLL0816.dll"
needed
  dim filename as string = "f:\users\andrew\downloads\realstudio.pdf"                                                            
  
  dim result,instance as Integer
  
  DECLARE FUNCTION QuickPDFCreateLibrary  LIB DLL_NEW  AS integer
  DECLARE FUNCTION QuickPDFUnlockKeyA      LIB  DLL_NEW  ( BYVAL iInstanceID AS integer, sLicenseKey AS cstring) AS integer
  DECLARE FUNCTION QuickPDFLibraryVersionA  LIB  DLL_NEW  ( BYVAL iInstanceID AS integer) AS CSTRING
  DECLARE FUNCTION QuickPDFSaveToFileA      LIB  DLL_NEW  ( BYVAL iInstanceID AS integer, sFileName AS CSTRING) AS integer
  DECLARE FUNCTION QuickPDFDrawTextA        LIB  DLL_NEW  ( BYVAL iInstanceID AS integer, BYVAL dXPos AS DOUBLE, BYVAL dYPos AS DOUBLE, sText AS cstring ) AS integer
  DECLARE FUNCTION QuickPDFReleaseLibrary LIB  DLL_NEW ( BYVAL iInstanceID AS integer) AS integer
  '
  
  Instance = QuickPDFCreateLibrary( )
  
  MsgBox "Instance=" + str(instance)
  msgbox "Quick PDF Library Ver. " + QuickPDFLibraryVersionA( Instance )
  
  result=QuickPDFUnlockKeyA (instance,"<insert your key here>")
  
  if result=1 then
    '**create PDF
    result= QuickPDFDrawTextA (instance,100, 500, "Hello from Real Studio")
    result = QuickPDFSaveToFileA (instance,filename)
    result = QuickPDFReleaseLibrary (instance)
    
    '**display PDF with default PDF Viewer
    GetFolderItem(filename).Launch
    
  else
    MsgBox "invalid licence"
  end
Back to Top
Fred_RealStudio View Drop Down
Beginner
Beginner


Joined: 26 Jun 12
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fred_RealStudio Quote  Post ReplyReply Direct Link To This Post Posted: 26 Jun 12 at 9:06PM

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

Back to Top
Fred_RealStudio View Drop Down
Beginner
Beginner


Joined: 26 Jun 12
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Fred_RealStudio Quote  Post ReplyReply Direct Link To This Post Posted: 26 Jun 12 at 9:07PM

In the previous example, you can see I can't get QuickPDFAddImageFromString working….


Any idea would be greatly appreciated.


Thanks, 

Fred

Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 02 Jul 12 at 9:15AM
Here is Fred's working code for AddImageFromString

When using the FromString functions with the DLL require the use of the following functions - QPDFCreateBuffer,  QPDFAddToBuffer QPDFReleaseBuffer 

In C# and VB.NET this code is already included in the .CS and .VB include files.  With other environments like RealBasic and other libraries you need to use the Buffer functions.

// ----------------------------------------------------------------------

  Soft Declare Function QuickPDFCreateBuffer Lib ThePDFlib ( InstanceID 
as integer , BufferLength as integer ) as integer
  Soft Declare Function QuickPDFAddToBuffer Lib ThePDFlib ( InstanceID 
as integer , BufferId as integer , Source as Ptr , SourceLength as 
integer ) as integer
  Soft Declare Function QuickPDFAddImageFromString Lib ThePDFlib ( 
InstanceID as integer,    TheSource as Integer  , Options as integer ) 
as integer
  Soft Declare Function QuickPDFReleaseBuffer Lib ThePDFlib ( 
InstanceID as integer , BufferId as integer ) as integer

Dim BufferID , Test , ImageID as integer
BufferID = QPDFCreateBuffer ( InstanceID , Mb.Size )
if BufferID <> 0 then // OK
    Test = QPDFAddToBuffer ( InstanceID , BufferID , Mb, Mb.size )
    ImageID = QPdfAddImageFromString_ ( InstanceID,  BufferID , Options 
) //0 )
    Test = QPDFReleaseBuffer ( InstanceID,  BufferID )
    ' === Test should be egal to 1 ? -> always 0

else
    ImageID = 0
end

return ImageID
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