Recent

Author Topic: Porting PDF Viewer from Delphi  (Read 1336 times)

domasz

  • Hero Member
  • *****
  • Posts: 615
Porting PDF Viewer from Delphi
« on: November 11, 2025, 11:31:03 am »
There is a very nice component for Delphi that uses Pdfium. Made by Lasse Markus Rautiainen and Andreas Hausladen.
I tried porting to Lazarus but something is off.

Attached is full source code from 2 repos:
https://github.com/ahausladen/PdfiumLib
https://github.com/TextEditorPro/TTextEditor/
License: MIT

You'll need to put a DLL in x64 directory from:
https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F7242/pdfium-win-x64.tgz
You don't need to install anything.

Lazarus port compiles and runs but renders in a weird way. I don't see any changes in code in how things are rendered between Delphi and Lazarus

LV

  • Sr. Member
  • ****
  • Posts: 389
Re: Porting PDF Viewer from Delphi
« Reply #1 on: November 12, 2025, 11:16:24 am »
There is a very nice component for Delphi that uses Pdfium. Made by Lasse Markus Rautiainen and Andreas Hausladen.
I tried porting to Lazarus but something is off.

Attached is full source code from 2 repos:
https://github.com/ahausladen/PdfiumLib
https://github.com/TextEditorPro/TTextEditor/
License: MIT

You'll need to put a DLL in x64 directory from:
https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F7242/pdfium-win-x64.tgz
You don't need to install anything.

Lazarus port compiles and runs but renders in a weird way. I don't see any changes in code in how things are rendered between Delphi and Lazarus

I gathered the courage to make a few adjustments.  :-[

P.S. I slightly modified LazarusCode.zip above
« Last Edit: November 12, 2025, 11:28:03 am by LV »

domasz

  • Hero Member
  • *****
  • Posts: 615
Re: Porting PDF Viewer from Delphi
« Reply #2 on: November 12, 2025, 11:43:17 am »
Damn, you are good! Seems to be fixed, thanks!

Boleeman

  • Hero Member
  • *****
  • Posts: 1067
Re: Porting PDF Viewer from Delphi
« Reply #3 on: November 15, 2025, 12:38:46 pm »
Also came across Pdfium LCL at

https://github.com/DomenicoMammola/PdfiumPascal

but compilation stops at Uses PdfiumCore  in unit mainfrm2;

Attached is the zip from that github page.

Boleeman

  • Hero Member
  • *****
  • Posts: 1067
Re: Porting PDF Viewer from Delphi
« Reply #4 on: November 15, 2025, 06:21:52 pm »
Got it working with these files.

Can select between LCL, Graphics32, Image32

Annotate did not work.

Need to put pdfium.dll in the example/lcl folder
« Last Edit: November 16, 2025, 04:05:26 am by Boleeman »

domasz

  • Hero Member
  • *****
  • Posts: 615
Re: Porting PDF Viewer from Delphi
« Reply #5 on: November 16, 2025, 09:35:22 pm »
Also came across Pdfium LCL at

https://github.com/DomenicoMammola/PdfiumPascal

That's way worse- it doesn't support continuous scrolling

domasz

  • Hero Member
  • *****
  • Posts: 615
Re: Porting PDF Viewer from Delphi
« Reply #6 on: November 17, 2025, 11:08:24 am »
In PDFium.Control.pas, line 2089:

Code: Pascal  [Select][+][-]
  1. procedure TCustomPDFiumControl.PaintWindow(ADC: HDC);
  2. var
  3.   LIndex: Integer;
  4.   LPage: TPDFPage;
  5.   LBrush: HBrush;
  6. begin
  7.   LBrush := CreateSolidBrush(Color);
  8.   try
  9.     //FillRect(ADC, ClientRect, LBrush); this seems not needed. It draws a weird rectangle visible when scrolling

Boleeman

  • Hero Member
  • *****
  • Posts: 1067
Re: Porting PDF Viewer from Delphi
« Reply #7 on: December 27, 2025, 06:46:26 am »
Found 3 examples (to View, scroll, Zoom, Fill, Weblink, Read, Save pdf form).

It was from kjteng, whch has 4 examples (I could not get example 2 to work):

PDF VCL Control using PDFium

https://github.com/kjteng/PdfiumLib

Some extra files from that Github page:

A pdflib.dpk file (and also Tpdfcontrol.lrs) is also included for those who wish to place the TPdfControl to the component palette in Lazarus. Before installing the dpk, please remember to uncomment the line containing {$DEFINE VCL_PALETTE} in pdfiumctrl.pas. You may also need to delete the files in project\lib\ folder to ensure a clean start. The Example1 (PdfiumLibExample) is also originated from Andreas Hausladen's site, with some minor modification for Lazarus.
« Last Edit: December 27, 2025, 07:51:18 am by Boleeman »

 

TinyPortal © 2005-2018