Recent

Author Topic: PDF viewer  (Read 2229 times)

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
PDF viewer
« on: December 12, 2019, 06:50:39 pm »
Hi guys,
Is there an easy way or an LCL component to view a pdf file within lazarus application.
 The purpose of this is that I have to print many pdf documents but from
my lazarus application, not from the windows explorer.
Many thanks

wp

  • Hero Member
  • *****
  • Posts: 7240
Re: PDF viewer
« Reply #1 on: December 12, 2019, 10:54:26 pm »
Some kind of overkill, but I tested it and it is working: you could embed the Chrome browser in your form which can display pdf files.
  • Install CEF4Delphi from Online-Package-Manager -- in spite of its name, this package also works with Lazarus.
  • Get yourself the CEF library from http://opensource.spotify.com/cefbuilds/index.html (you must select the version which matches the version of CEF4Delphi, 73.1.12 -- for my Win32 Lazarus I downloaded http://opensource.spotify.com/cefbuilds/cef_binary_73.1.12%2Bgee4b49f%2Bchromium-73.0.3683.75_windows32_minimal.tar.bz2). I never worked with this library, and there's probaby a better way, but for a quick test I just copied the contents of the "Release" and "Resources" folder into the output directory of my test project.
  • There's quite a lot of examples, but they are still for Delphi -- I converted the SimpleBrowser to Lazarus and am attaching the converted project.
  • This project compiles and runs fine. I can enter the path to a local pdf file in the address bar, and it is displayed correctly. After some investigation, you certainly can make it even print the displayed file, but I did not test this.
Alternatively, there is also an fpCEF package (https://wiki.freepascal.org/fpCEF3, https://github.com/dliw/fpCEF3) - I did not test it, it seems to contain ready-to-use Lazarus examples.

P.S.
Read the fpCEF wiki -- you will get many ideas from it.
« Last Edit: December 12, 2019, 11:26:24 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: PDF viewer
« Reply #2 on: December 12, 2019, 11:31:08 pm »
Many thanks wp for your so neat reply.

Your steps sound enough to follow them and  thank you for the attachment as well.
I will give this a thorough try.
On the other hand, and for a moment I thought viewing or sending local pdf file to
a peinter is straightforward! Apprently,  it is not that easy.

wp

  • Hero Member
  • *****
  • Posts: 7240
Re: PDF viewer
« Reply #3 on: December 13, 2019, 12:23:23 am »
Now I also tested fpCEF, and it is working too. Just follow the steps of the wiki. The only important thing is that the correct CEF binaries must be used; the fpCEF version in the github requires v3.3029 as displayed in the package title.

A less bulky solution might be Google's pdfiumlib discussed in https://forum.lazarus.freepascal.org/index.php/topic,39589.msg272268.html#msg272268.

Unfortunately, the sources in https://github.com/ahausladen/PdfiumLib are still for Delphi only, and I did not manage to make them compile under Lazarus - but I do not want to dig into this too deeply and probably gave up too soon. If you are more successful than me it would be nice if you could upload your result here.
« Last Edit: December 13, 2019, 12:42:03 am by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: PDF viewer
« Reply #4 on: December 13, 2019, 05:54:42 am »
Cheers wp,
I will give it a good try as well. Many thanks

HeavyUser

  • Sr. Member
  • ****
  • Posts: 310
Re: PDF viewer
« Reply #5 on: December 30, 2019, 09:01:25 pm »
Cheers wp,
I will give it a good try as well. Many thanks

have you seen this one?
https://forum.lazarus.freepascal.org/index.php/topic,40938.msg283271.html#msg283271
last time I checked it worked for the minimal tests I cared to run but I haven't used lazarus after 1.6 something so I do not know how it fares.

lazdeveloper

  • Jr. Member
  • **
  • Posts: 61
Re: PDF viewer
« Reply #6 on: January 14, 2020, 07:29:08 pm »
Thank you very much HeavyUser
I tried it and it works.
Many thanks.. I was late being implementing a database project and now
Got back to pdf expiremnts!
I can say it is some how the topic is solved.
Thanks for wp as well. His additions are so useful.

 

TinyPortal © 2005-2018