1

I have a JPEG image inside a PDF file, i know that it is a JPEG, because when i open the file with a hex editor i can see JFIF string present in it. How do i extract it into a separate file.

The particular file that i have only has a single image and it is on the first page.

I know that it is possible to use convert from the Image Magic package to convert the image, but this will mean that a double conversion will take place possibly making an image either worse quality or unnecesserily larger size.

v010dya
  • 1,472

1 Answers1

3

In order to extract an image one needs an automatically installed pdfimages.

The command line will look as follows:

pdfimages -j file.pdf ./

Please note that the slash is needed, if it is omitted then the extraction process will not happen and no error message will be generated. It is also possible to give the files a starting prefix as ./prefix then all of them will be placed in the current directory and will start with the provided prefix.

It is not possible to limit pdfimages to only extract a single file, but it is possible to provide the page that it will process by using -f (first page) and -l (last page) options. All options must be provided before the input file.

v010dya
  • 1,472
  • What is the point of asking a question if you already know the answer? This is not a wiki page. – Russo Sep 26 '17 at 10:27
  • @Russo hmm it is allowed (it is mentioned in the help tour) though it is expected for a user to wait and give others the possibility to come with an answer first – Rinzwind Sep 26 '17 at 10:30
  • @Rinzwind, I know that. But he posted the question and the answer at the same time. – Russo Sep 26 '17 at 10:31
  • 1
    @Russo actually, it is. The Stack Exchange sites have always aimed to be a cross between a forum, a blog and a wiki. Asking and answering your own question is actively encouraged. – terdon Sep 26 '17 at 10:43
  • @terdon, I apologize for my comment then. I thought even if you know the answer, you have to give others a chance to answer the question first. Sorry. – Russo Sep 26 '17 at 10:44
  • 1
    @Russo sure, but nobody is stopping others from answering! It's just that one person has already taken the time and put in the effort to post their own answer. Great! But anyone else can also add their answer, just like with any other post. – terdon Sep 26 '17 at 10:49