Recent

Author Topic: Pdf Viewer in Pascal  (Read 3055 times)

Tomxe

  • Full Member
  • ***
  • Posts: 134
Pdf Viewer in Pascal
« on: June 09, 2026, 05:00:32 pm »
https://github.com/Xelitan/PDF-Viewer-exporter-in-pure-Free-Pascal-Lazarus-Delphi

Display PDFs:

Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3. ...
  4.   public
  5.     PDF: TXelPDF;
  6.   end;
  7. ...
  8. procedure TForm1.FormCreate(Sender: TObject);
  9. begin
  10.   PDF := TXelPDF.Create(Form1);
  11.   Pdf.Parent := Form1;
  12.   Pdf.Align := alClient;
  13.   Pdf.AutoFit := afWidth; //fit to width of the component
  14.   Pdf.LoadFromFile('test.pdf');
  15. end;
  16.  
  17. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  18. begin
  19.   Pdf.Free;
  20. end;  


Some editing is possible:
Code: Pascal  [Select][+][-]
  1. Doc.DrawRect(0, 50, 600, 200, 80, clRed); //PageNum, Left, Top, Width, Height, Color
  2. Doc.AddJpegImage(PageIndex, JpegBytes, Left, Top, Width, Height);
  3.  
  4. FontRes := Doc.AddFont(FontName, FontSize);
  5. Doc.AddText(PageIndex, 'Test Here', Left, Top, FontRes);

Also removing pages, adding new pages and exporting elements:
Code: Pascal  [Select][+][-]
  1. Doc.ExportImage(PageNumber, ImageNumber, 'out.png');
  2. Doc.ExportJpeg(PageNumber, JpegNumber, 'out.jpg');
  3. PDF.Document.ExportFont(5, 'out.otf'); //5 is the number of the font

Uses GDI+ so currently works only on Windows. Linux support will be added in the future.

kirchfritz

  • Jr. Member
  • **
  • Posts: 76
  • WIN11 LAZ 4.2 FPC 3.2.2
Re: Pdf Viewer in Pascal
« Reply #1 on: June 11, 2026, 11:40:26 am »
Hello tomxe,

trying to compile your PDF Viewer with Lazarus 4.2 FPC 3.2.2 gives the following error message:

(see attachement)



« Last Edit: June 11, 2026, 11:42:27 am by kirchfritz »

Tomxe

  • Full Member
  • ***
  • Posts: 134
Re: Pdf Viewer in Pascal
« Reply #2 on: June 11, 2026, 12:05:23 pm »
Sorry, it would work but it's {$mode delphi} now. I fixed the code, please download the update.

zamtmn

  • Hero Member
  • *****
  • Posts: 689
Re: Pdf Viewer in Pascal
« Reply #3 on: June 11, 2026, 12:10:28 pm »
Please provide a simple application so that we can view the selected pdf and evaluate the library's capabilities?

kirchfritz

  • Jr. Member
  • **
  • Posts: 76
  • WIN11 LAZ 4.2 FPC 3.2.2
Re: Pdf Viewer in Pascal
« Reply #4 on: June 11, 2026, 02:48:12 pm »
Hi tomxe:
using  {mode objfpc} instead of {$mode delphi} lets me successfully compile all your modules.
I already found, how to scroll programatically from page to next/prev page, how to set the zoom level and how to show current pagenumber / total pagenumber.

But: I cant find a way how to rotate pdf-pages clockwise or anti-clockwise.
Does it make sense to wait for this feature?
« Last Edit: June 11, 2026, 02:55:21 pm by kirchfritz »

Tomxe

  • Full Member
  • ***
  • Posts: 134
Re: Pdf Viewer in Pascal
« Reply #5 on: June 11, 2026, 03:52:37 pm »
I added a simple demo - DEMO_PDF.lpr that shows some of the options.
There are no rotations yet but will be added soon.

hedgehog

  • Full Member
  • ***
  • Posts: 133
Re: Pdf Viewer in Pascal
« Reply #6 on: June 14, 2026, 07:57:23 am »
Hi Tomxe.

It looks cool!
I opened the test file
https://github.com/py-pdf/sample-files/blob/main/011-google-doc-document/google-doc-document.pdf
and here's what I noticed:
1. The logo (worm) is drawn with a black background, without transparency.
2. The flags of the countries are missing in the table.
« Last Edit: June 14, 2026, 09:57:22 am by hedgehog »

Dzandaa

  • Hero Member
  • *****
  • Posts: 557
  • From C# to Lazarus
Re: Pdf Viewer in Pascal
« Reply #7 on: June 14, 2026, 11:44:26 am »
Hi,

@Tomxe:

Great Program/Library,

I'm currently looking for a program that would allow me to view a directory with many PDF files
and see their contents simply by clicking on them.

Here are two attached images of a document written in LibreOffice and exported as a PDF:
one from "Sumatra PDF" and the other from "Xelitan PDF"—they are quite similar.

Thank you again.

B->
Regards,
Dzandaa

eldonfsr

  • Hero Member
  • *****
  • Posts: 598
Re: Pdf Viewer in Pascal
« Reply #8 on: June 16, 2026, 03:44:27 pm »
Looks great is print avalible to..

Handoko

  • Hero Member
  • *****
  • Posts: 5559
  • My goal: build my own game engine using Lazarus
Re: Pdf Viewer in Pascal
« Reply #9 on: June 16, 2026, 03:55:42 pm »
Nice.
Unfortunately it is licensed under GPL, closed source can't use it.

Tomxe

  • Full Member
  • ***
  • Posts: 134
Re: Pdf Viewer in Pascal
« Reply #10 on: June 17, 2026, 09:13:20 am »
Unfortunately it is licensed under GPL, closed source can't use it.
Commercial license is available and dirt cheap.

Tomxe

  • Full Member
  • ***
  • Posts: 134
Re: Pdf Viewer in Pascal
« Reply #11 on: June 17, 2026, 09:59:03 am »
Fixed:
1) transparency around the Snake
2) flags now visible
3) resampling instead of resizing of images
4) rotations

CM630

  • Hero Member
  • *****
  • Posts: 1746
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Pdf Viewer in Pascal
« Reply #12 on: June 17, 2026, 11:32:05 am »
I tried a few documents, usually there are issues with some characters. But in the attached file I see only quadrangles.

Also, it it possible to search?
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

Dzandaa

  • Hero Member
  • *****
  • Posts: 557
  • From C# to Lazarus
Re: Pdf Viewer in Pascal
« Reply #13 on: June 17, 2026, 03:27:20 pm »
Hi,

@Tomxe:

Using Windows 10 64bits with Lazarus 4.8 fpc 3.2.2


The library works fine for some files, but sometimes, I have memory leaks
PdfObjects.pas at  Line 105:
Create

PdfCFF.pas at line 434:
Result := Result + w;

Anyway, great job.

B->


Regards,
Dzandaa

Tomxe

  • Full Member
  • ***
  • Posts: 134
Re: Pdf Viewer in Pascal
« Reply #14 on: June 17, 2026, 07:18:20 pm »
Thanks @Dzandaa - fixed.

@CM630 - a bit complicated but should be fixed today/tomorrow.
Searching:
TXelPDf.Search()

 

TinyPortal © 2005-2018