Recent

Author Topic: How do I use/call functions in the DebenuQuickPDF v10.13 DLL?  (Read 443 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 467
How do I use/call functions in the DebenuQuickPDF v10.13 DLL?
« on: December 07, 2024, 10:11:07 pm »
OS: Windows Server 2016.  DLL: DebenuPDFLibrary64DLL1013.dll
Lazarus 3.4 (rev lazarus_3_4) FPC 3.2.2 x86_64-win64-win32/win64

I have never done this before.
I am stuck at how to properly load the library, and also how to use functions in the library.

According to the Getting Started:
("DPLDrawText" and "DPLSaveToFile" are just example function calls to demonstrate)

Code: Pascal  [Select][+][-]
  1. int InstanceID;
  2. InstanceID = DPLCreateLibrary();
  3. if (DPLUnlockKey(InstanceID, "your license key") == 1) {
  4. DPLDrawText(InstanceID, 100, 500, "Hello world");
  5. DPLSaveToFile(InstanceID, "C:\Docs\HelloFromDLL.pdf");
  6. }
  7. DPLReleaseLibrary(InstanceID);
  8.  

Further from the same document: Sending Strings

Code: Pascal  [Select][+][-]
  1. char * Buffer;
  2. char * Content = ...; // pointer to the data
  3. Buffer = DPLCreateBuffer(10000);
  4. DPLAddToBuffer(InstanceID, Buffer, Content, 10000);
  5. DPLStoreCustomDataFromString(InstanceID,
  6. "MyData", Buffer, 1, 0);
  7. DPLReleaseBuffer(InstanceID, Buffer);
  8.  

Further from the same document: Receiving Strings

Code: Pascal  [Select][+][-]
  1. unsigned char * Content;
  2. int ContentLength;
  3. Content = DPLRetrieveCustomDataToString("MyData", 1);
  4. ContentLength = DPLAnsiStringResultLength(// copy the data in Content now
  5.  

This is my own code, so far:

Code: Pascal  [Select][+][-]
  1. unit u_dll_pdf;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, u_gv;
  9.  
  10. type
  11.    TfunStringBack = function(strIn : string) : PChar;  stdcall;
  12.    TfunCreateLibrary = function() : PChar;  stdcall;
  13.  
  14. function GetPgImgStrFromPDF(const fnm: String; const pg, zm: Integer; var pgc: Integer; var img_str: String): Boolean;
  15.  
  16. implementation
  17.  
  18. function GetPgImgStrFromPDF(const fnm: String; const pg, zm: Integer; var pgc: Integer; var img_str: String): Boolean;
  19. var LibHandle: THandle; fncPtr: Pointer;  InstanceID: Integer;  funCreateLibrary: TfunCreateLibrary;
  20. begin
  21.   Result := True;
  22.   try
  23.     LibHandle := LoadLibrary(PChar(GV.RBI.QPDF_lib_fnm));
  24.     if LibHandle = 0 then
  25.       begin
  26.         Result := False;
  27.         Exit;
  28.       end;
  29.  
  30.     fncPtr := GetProcAddress(LibHandle, 'DPLCreateLibrary');
  31.     if not Assigned(fncPtr) then //-- Error! Unknown data.
  32.       begin
  33.         Result := False;
  34.         Exit;
  35.       end;
  36.  
  37.     // Everything is lined up.  Time to call the function
  38.  
  39.   finally
  40.     if LibHandle > 0 then
  41.       FreeLibrary(LibHandle);
  42.   end;
  43. end;
  44.  
  45. end.
  46.  

Ultimately, the function I need to get working is this one:
(I need to get a page from the .pdf file, to an HTML string)
 
Quote
RenderPageToString

Description
This function renders a page from the selected document to a string. The data in the returned
string depends on the Options parameter.

Syntax
Delphi
function TDebenuPDFLibrary1013.RenderPageToString(DPI: Double; Page, Options: Integer): AnsiString;

DLL
char * DPLRenderPageToString(int InstanceID, double DPI, int Page,
int Options);

Parameters
DPI The DPI to use when rendering the page. Values over 300 will cause excessive memory usage.
Page The page number to render

Options 0 = BMP output
1 = JPEG output
2 = WMF output
3 = EMF output
4 = EPS output
5 = PNG output
6 = GIF output
7 = TIFF output
8 = EMF+ output
9 = HTML5 output
10 = TIFF (G4) output

Many thanks to anyone who can get me over this learning curve.


Fibonacci

  • Hero Member
  • *****
  • Posts: 643
  • Internal Error Hunter
Re: How do I use/call functions in the DebenuQuickPDF v10.13 DLL?
« Reply #1 on: December 07, 2024, 10:41:50 pm »
Remove GetPgImgStrFromPDF from implementation section, and in interface section change to

Code: Pascal  [Select][+][-]
  1. function GetPgImgStrFromPDF(const fnm: String; const pg, zm: Integer; var pgc: Integer; var img_str: String): Boolean; stdcall; external 'DebenuPDFLibrary64DLL1013.dll';

Thats all, add more functions and call them

RedOctober

  • Sr. Member
  • ****
  • Posts: 467
Re: How do I use/call functions in the DebenuQuickPDF v10.13 DLL?
« Reply #2 on: December 08, 2024, 02:43:07 am »
I was on the wrong track.

Solution:

  • In the folder "/Import/Delphi"  find the library's .pas file:
DebenuPDFLibraryDLL1013.pas
Place this file in with your project source code.
Put {$MODE Delphi}  at the very top line of this Debenu file.
  • Using the Project Inspector, add this file to the Project
  • In your unit, in the uses clause, add the same .pas file
Classes, SysUtils, DebenuPDFLibraryDLL1013;
  • Then see below for the source code

Code: Pascal  [Select][+][-]
  1. unit u_dll_pdf;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, DebenuPDFLibraryDLL1013;
  9.  
  10. const
  11.   quick_pdf_license_key: WideString = 'YOUR LICENSE KEY'; // 10.13
  12.  
  13. function GetPgImgStrFromPDF(const fnm: String; const pg, zm: Integer; var pgc: Integer; var img_str: AnsiString): Boolean;
  14.  
  15. implementation
  16.  
  17. uses u_gv;
  18.  
  19. function GetPgImgStrFromPDF(const fnm: String; const pg, zm: Integer; var pgc: Integer; var img_str: AnsiString): Boolean;
  20. var
  21.   QwkPDFLib: TDebenuPDFLibraryDLL1013;
  22.   ID: LongInt; key_ok: Integer;
  23. begin
  24.   Result := True;
  25.   QwkPDFLib := nil;
  26.   try
  27.     QwkPDFLib := TDebenuPDFLibraryDLL1013.Create(GV.RBI.QPDF_lib_fnm);
  28.     if not Assigned(QwkPDFLib) then
  29.       Exit;
  30.  
  31.     key_ok := QwkPDFLib.UnlockKey(quick_pdf_license_key);
  32.     if key_ok = 0 then
  33.       Exit;
  34.     QwkPDFLib.LoadFromFile(fnm, '');
  35.     img_str := QwkPDFLib.RenderPageToString(100, 1, 9);
  36.   finally
  37.     QwkPDFLib.Free;
  38.   end;
  39. end;
  40.  
  41. end.
  42.  


The result of the RenderPageToString() call will be a complete HTML document, with a JavaScript function call that uses a bunch of ctx. (canvas) draws and moves and fills, that will render the image in a browser.  Really cool.

THANKS to those who replied, it helped get me onto the right track.



« Last Edit: December 08, 2024, 02:56:42 am by RedOctober »

 

TinyPortal © 2005-2018