Recent

Author Topic: Embedded pdf viewer / converter  (Read 27799 times)

timmermanj

  • New Member
  • *
  • Posts: 39
Embedded pdf viewer / converter
« on: October 21, 2009, 12:26:49 am »
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

  • Full Member
  • ***
  • Posts: 196
Re: Embedded pdf viewer / converter
« Reply #1 on: October 21, 2009, 12:38:38 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

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #2 on: October 21, 2009, 10:07:55 am »
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

  • Full Member
  • ***
  • Posts: 196
Re: Embedded pdf viewer / converter
« Reply #3 on: October 21, 2009, 06:01:20 pm »
point with Compiler Options- other Units to the Directory of the pascalmagick files
There is also a demo.

timmermanj

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #4 on: October 21, 2009, 06:46:45 pm »
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

  • Full Member
  • ***
  • Posts: 196
Re: Embedded pdf viewer / converter
« Reply #5 on: October 21, 2009, 07:12:14 pm »
What error do you get?
Maybe try to skip the thumbnail part of the code.

timmermanj

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #6 on: October 21, 2009, 07:20:18 pm »
I've got error:

Project wanddemo.exe raised exception class 'unknown'.

I've skipped also the thumbnail part & i got the same error.


timmermanj

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #7 on: October 21, 2009, 07:26:31 pm »
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

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #8 on: October 21, 2009, 07:53:29 pm »
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.  :D

http://sourceforge.net/projects/ghostscript/

Now I can start with my actual application! 

Thanks for all your help!

Jeffrey

timmermanj

  • New Member
  • *
  • Posts: 39
Re: Embedded pdf viewer / converter
« Reply #9 on: October 23, 2009, 12:12:09 am »
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

  • Sr. Member
  • ****
  • Posts: 461
Re: Embedded pdf viewer / converter
« Reply #10 on: August 05, 2013, 08:30:52 am »
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
Speak postscript or die!
Translate to pdf and live!

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Embedded pdf viewer / converter
« Reply #11 on: August 07, 2013, 05:14:58 pm »
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
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018