Recent

Author Topic: how to convert pdf to png file  (Read 694 times)

Packs

  • Sr. Member
  • ****
  • Posts: 290
how to convert pdf to png file
« on: September 17, 2024, 09:39:20 am »
how to convert pdf to png file .

Thaddy

  • Hero Member
  • *****
  • Posts: 15747
  • Censorship about opinions does not belong here.
Re: how to convert pdf to png file
« Reply #1 on: September 17, 2024, 09:46:35 am »
Why would you want to do that?
If the display fits in a screen, simply save the screen (with the handle of the window that displays it) as a screenshot as png.
Otherwise it would be a png with a silly format in length. Which might not be accepted by all png capable applications.

So what are you trying to achieve?
« Last Edit: September 17, 2024, 09:50:58 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Packs

  • Sr. Member
  • ****
  • Posts: 290
Re: how to convert pdf to png file
« Reply #2 on: September 17, 2024, 02:21:55 pm »
I have pdf file which is having 28 mb file.

I want first page of the pdf and want to store inside database.

loaded

  • Hero Member
  • *****
  • Posts: 853
Re: how to convert pdf to png file
« Reply #3 on: September 17, 2024, 02:44:47 pm »
I use Ghostscript library for this kind of work. You can try it too.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Packs

  • Sr. Member
  • ****
  • Posts: 290
Re: how to convert pdf to png file
« Reply #4 on: September 17, 2024, 03:14:58 pm »
You mean python libraries

loaded

  • Hero Member
  • *****
  • Posts: 853
Re: how to convert pdf to png file
« Reply #5 on: September 17, 2024, 03:24:28 pm »
You mean python libraries

No, ;D

https://www.ghostscript.com/
You install this library on your computer, then you can split, merge, rotate, convert to text (limited) and convert images from lazarus via the command line.
If anyone knows another simpler and easier method, I would be happy if they shared it.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Thaddy

  • Hero Member
  • *****
  • Posts: 15747
  • Censorship about opinions does not belong here.
Re: how to convert pdf to png file
« Reply #6 on: September 17, 2024, 03:58:28 pm »
Correct. Good advice. But a first page would probably fit in a screenshot.
If I smell bad code it usually is bad code and that includes my own code.

Zvoni

  • Hero Member
  • *****
  • Posts: 2693
Re: how to convert pdf to png file
« Reply #7 on: September 17, 2024, 04:06:53 pm »
Correct. Good advice. But a first page would probably fit in a screenshot.
Not necessarily.
Take A4 for example: 29,7 cm high
For a 100% screenshot (no scaling involved) you'd need a Screen that high.

Scaling to fit a Screen not withstanding, but then there is "loss" involved
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

rvk

  • Hero Member
  • *****
  • Posts: 6408
Re: how to convert pdf to png file
« Reply #8 on: September 17, 2024, 04:10:01 pm »
Correct. Good advice. But a first page would probably fit in a screenshot.
Can you enlighten us (preferable with some code) how you would make a screenshot from code without the need to open the PDF in a separate program or library?

The question is to create a thumbnail (probably much like the explorer.exe does in Windows at the right side when preview is on).

Zvoni

  • Hero Member
  • *****
  • Posts: 2693
Re: how to convert pdf to png file
« Reply #9 on: September 17, 2024, 04:13:31 pm »
Alternative: XpdfReader's "pdftopng" commandline-tool
Fire it off via TProcess, passing the necessary options/arguments to it, and be done with it.

pdftopng -f 1 -l 1 mypdf.pdf mypng.png

Other options (dpi, color/gray/mono etc.) available
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

rvk

  • Hero Member
  • *****
  • Posts: 6408
Re: how to convert pdf to png file
« Reply #10 on: September 17, 2024, 04:45:34 pm »
If it's for Windows, the optimal method would be to check if there is a preview handler for pdf (if Adobe reader is installed this could be PDFPrevHndlr.dll for example) and get a preview via that handler. Not sure if that's possible and how you could get it but that would be a neat way.

Of course there can also be other programs installed for viewing PDF. Getting the thumbnail from explorer.exe would also be an option (which in turn gets it from the default installed handler). But how to trigger the generation and retrieval of that thumbnail?

(And all this is assuming Windows  ;) )

Something like this with IExtractImage.
https://stackoverflow.com/a/2916610/1037511


« Last Edit: September 17, 2024, 04:52:11 pm by rvk »

Packs

  • Sr. Member
  • ****
  • Posts: 290
Re: how to convert pdf to png file
« Reply #11 on: September 17, 2024, 05:45:41 pm »
From free pascal by using code.

I have almost 40000 pdf

MarkMLl

  • Hero Member
  • *****
  • Posts: 7725
Re: how to convert pdf to png file
« Reply #12 on: September 17, 2024, 05:52:41 pm »
Your OP ("how to convert pdf to png file .") was unclear: it could be read either that you were asking for help or that you were volunteering an example.

From free pascal by using code.

I have almost 40000 pdf

Are you sure that writing it from scratch is the best way to go? My experience (on Linux) is that pdftk (which pulls in stuff from Ghostscript etc.) is very much worth investigating: I did a fairly big document preparation job a few months ago and apart from a bit of semi-manual stuff to get a pagination overlay right it did everything I needed.

https://github.com/MarkMLl/paginate_pdfs

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Packs

  • Sr. Member
  • ****
  • Posts: 290
Re: how to convert pdf to png file
« Reply #13 on: September 17, 2024, 08:23:34 pm »
Can anyone guide me how pdf file internally store objects.

I would like to understand internal architecture of pdf

zeljko

  • Hero Member
  • *****
  • Posts: 1648
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: how to convert pdf to png file
« Reply #14 on: September 17, 2024, 08:35:54 pm »
You can install PowerPDF from OPM and study code.

 

TinyPortal © 2005-2018