Embedded pdf viewer / converter lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- timmermanj · 2009-10-20 22:26 Hi, Maybe I'm not the first one who is asking this but I'm searching a while on the internet and cannot find a proper solution. I'm searching any kind of pdfviewer (component) which i can embed in a Lazarus application? My goal is to load a pdf in a application, view it, add some layers text & save it back as a pdf with powerpdf. Another solution would be: A component to convert a pdf to jpg, png or ... so i can view it this way in my application, add the layers text & create a new pdf with powerpdf. Anybody any idea where i can find these components? Or maybe a better solution? Thanks a lot! ---------------------------------------------------------------------- mica · 2009-10-20 22:38 Quote from: timmermanj on October 21, 2009, 12:26:49 am Another solution would be: A component to convert a pdf to jpg, png or ... so i can view it this way in my application, add the layers text & create a new pdf with powerpdf. Thanks a lot! ImageMagick? http://wiki.lazarus.freepascal.org/PascalMagick http://www.imagemagick.org/script/index.php ---------------------------------------------------------------------- timmermanj · 2009-10-21 08:07 How can i install this component on my componentpalet? I cannot find any lpk - file like with the powerpdf component. Do i have to use / install these files another way? Thanks for the help! ---------------------------------------------------------------------- mica · 2009-10-21 16:01 point with Compiler Options- other Units to the Directory of the pascalmagick files There is also a demo. ---------------------------------------------------------------------- timmermanj · 2009-10-21 16:46 Yes thanks! The demo works fine. I've also tried to change the code. It now converts size & extensions of other files. But when i try to convert a pdf-file into jpg i got a error. Do i have to install something extra to do this? Or do i have to write other code? program wanddemo; {$mode objfpc}{$H+} uses SysUtils, magick_wand, ImageMagick; procedure ThrowWandException(wand: PMagickWand); var   description: PChar;   severity: ExceptionType; begin   description := MagickGetException(wand, @severity);   WriteLn(Format('An error ocurred. Description: %s', [description]));   description := MagickRelinquishMemory(description);   Abort; end; var   status: MagickBooleanType;   wand: PMagickWand; begin   { Read an image. }   MagickWandGenesis;   wand := NewMagickWand;   try     status := MagickReadImage(wand, 'Picture 0026.pdf');     if (status = MagickFalse) then ThrowWandException(wand);     { Turn the images into a thumbnail sequence. }     MagickResetIterator(wand);     while (MagickNextImage(wand) <> MagickFalse) do      MagickResizeImage(wand, 270, 270, LanczosFilter, 1.0);     { Write the image as MIFF and destroy it. }     status := MagickWriteImages(wand, 'Picture 0026.jpg', MagickTrue);     if (status = MagickFalse) then ThrowWandException(wand);   finally     wand := DestroyMagickWand(wand);     MagickWandTerminus;   end; end. The red text is the only thing that I've changed in the demo code. You can see, not that much...  The picture0026.pdf file is in the same folder as the demo image. I've tested this with images with other extensions & it works perfect. I hope you can help me succeed in this! Thanks for all the help so far! Jeffrey ---------------------------------------------------------------------- mica · 2009-10-21 17:12 What error do you get? Maybe try to skip the thumbnail part of the code. ---------------------------------------------------------------------- timmermanj · 2009-10-21 17:20 I've got error: Project wanddemo.exe raised exception class 'unknown'. I've skipped also the thumbnail part & i got the same error. ---------------------------------------------------------------------- timmermanj · 2009-10-21 17:26 There is another error i first did not saw. It says: An error occurred. Description: unable to open image 'Picture 0026.pdf': No such file or directory @ blob.c/openblob/2480 I hope this is more helpful. ---------------------------------------------------------------------- timmermanj · 2009-10-21 17:53 I've found the solution to my last problem. After I installed ghostscript, converting pdf's into jpg's with the code above is no problem anymore.  http://sourceforge.net/projects/ghostscript/ Now I can start with my actual application!  Thanks for all your help! Jeffrey ---------------------------------------------------------------------- timmermanj · 2009-10-22 22:12 Does anybody know how to convert only the first page of a pdf with multiple pages into a jpg with PascalMagick? I cannot find any code of this on the Internet. Do I have to add a extra parameter in this line of code or does it go much further? status := MagickReadImage(wand, 'example.pdf'); ... status := MagickWriteImages(wand, 'example.jpg', MagickTrue); Thanks! ---------------------------------------------------------------------- Blestan · 2013-08-05 06:30 Hi ia have started a port of mupdf lib to lazar... the included demeo is an very basic pdf viewer ... you can use it and inprove it ... https://github.com/blestan/lazmupdf regards, blestan ---------------------------------------------------------------------- Mike.Cornflake · 2013-08-07 15:14 G'day, When I needed to do this I used the XPDF command line tool pdftoppm.exe.  This produces a ppm file (Portable Bitmap) for each page that TImage unfortunately cannot load, so the next step is to use ImageMagick to convert the ppm to a png or jpg.  Meant I had to acknowledge XPDF in my about as I was distributing their commandline tool, no issue with that, it's a good tool. Cheers Mike