DEIVEEGARAJA has asked for the wisdom of the Perl Monks concerning the following question:

Need a help for converting PDF to Image. Kindly give me any idea to do it. I have studied some docs but still I got stuck on this.
  • Comment on Conver PDF to Image( JPG , JPEG , etc. )

Replies are listed 'Best First'.
Re: Conver PDF to Image( JPG , JPEG , etc. )
by Corion (Patriarch) on Jun 01, 2012 at 08:33 UTC

    What documentation did you study? What code did you write? Where do you have problems exactly?

    This is not a code writing service. If you want our help, you will need to show us where exactly we can help.

    I recommend looking at Ghostview, which can likely convert PDF to JPG. ImageMagic likely can utilize Ghostview to do that conversion.

      Yup, I've used ImageMagick's convert to explode pdfs into images

      convert foo.pdf pages-%03d.bmp

      But it can be tricky (memory hungry)

        There's nothing wrong with using Perl as a glue language:

        #!/usr/bin/perl print `convert foo.pdf pages-%03d.bmp 2>&1`;

        Aaron B.
        Available for small or large Perl jobs; see my home node.

Re: Conver PDF to Image( JPG , JPEG , etc. )
by zentara (Cardinal) on Jun 01, 2012 at 09:22 UTC
Re: Conver PDF to Image( JPG , JPEG , etc. )
by jmlynesjr (Deacon) on Feb 03, 2015 at 17:27 UTC

    Using Fritzing for some simple PCB layout. Fritzing only prints in pdf format. I needed a png format for posting to the chipKIT forum(single page PCB images). Thanks for the OP, responses above, and Steve from wxperl-users for the hints. For those that follow, my code is attached(Ubuntu 14.04LTS).

    Update: Modified to use the safer list version of the "system" call as suggested by Johan.

    #! /usr/bin/perl # Name: pdf_to_png.pl # Authors: Steve Cookson & James M. Lynes, Jr. # Created: January 30, 2015 # Modified By: James M. Lynes, Jr. # Last Modified: February 11, 2015 # Change Log: 1/30/2015 - Program Created # 1/30/2015 - added events for filepicker change +d & textctrl changed # - added default filename and crop pa +rameters # - added spacers to sizers # - Modified some captions # - Modified default path # - Changed Cancel button to Exit(Quit +) button # 1/31/2015 - Added "system" function call to ex +ecute convert CLI program # - Changed exit(0) to $self->Close to + terminate script # 2/11/2015 - Changed to safer/list version of t +he "system" function # - as recommended by Johan # Description: Script to convert a pdf file to a png file + # package main; use strict; use warnings; my $app = App->new(); $app->MainLoop; package App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Frame->new(); $frame->Show(1); } package Frame; use strict; use warnings; use Wx qw(:everything); use base qw(Wx::Frame); use Data::Dumper; sub new { my ($class, $parent) = @_; my $frame = $class->SUPER::new($parent, -1, "PDF to PNG File Conve +rter", wxDefaultPosition, wxDefaultSize); #Create controls # Fields my $pdfLabel=Wx::StaticText->new($frame, wxID_ANY,"Select a PDF fi +le to Convert", wxDefaultPosition, wxDefaultSize); my $pdfFilePicker=Wx::FilePickerCtrl->new($frame, wxID_ANY, "", "S +elect the PDF File","*.pdf", wxDefaultPosition, [400,-1], wxDIRP_DIR_MUST +_EXIST| wxDIRP_CHANGE_DIR|wxDIRP_USE_TEXTCTRL); $pdfFilePicker->SetPath("~/"); $frame->{inpath} = "default.pdf"; my $cropLabel=Wx::StaticText->new($frame, wxID_ANY,"Enter Image cr +opping Parameters", wxDefaultPosition, wxDefaultSize); my $cropStringText=Wx::TextCtrl->new($frame, wxID_ANY,"250x175+10+ +10", wxDefaultPosition, [200,-1]); $frame->{cropstring} = $cropStringText->GetValue; # Buttons my $okButton = Wx::Button->new($frame, wxID_OK, "", wxDefaultPosit +ion, wxDefaultSize); my $exitButton = Wx::Button->new($frame, wxID_EXIT, "", wxDefaultP +osition, wxDefaultSize); # Create sizers. my $verticalSizerFrame = Wx::BoxSizer->new(wxVERTICAL); $frame->SetSizer($verticalSizerFrame); my $verticalSizerControls = Wx::BoxSizer->new(wxVERTICAL); my $horizontalSizerButtons = Wx::BoxSizer->new(wxHORIZONTAL); # Lay 'em out. $verticalSizerFrame->Add($verticalSizerControls,0,0,0); $verticalSizerFrame->Add($horizontalSizerButtons,0,0,0); $verticalSizerControls->AddSpacer(15); # Spacer $verticalSizerControls->Add($pdfLabel,0,0,0); $verticalSizerControls->Add($pdfFilePicker,0,0,0); $verticalSizerControls->AddSpacer(15); # Spacer $verticalSizerControls->Add($cropLabel,0,0,0); $verticalSizerControls->Add($cropStringText,0,0,0); $verticalSizerControls->AddSpacer(15); # Spacer $horizontalSizerButtons->Add($okButton,0,0,0); $horizontalSizerButtons->Add($exitButton,0,0,0); # Event handlers Wx::Event::EVT_BUTTON($frame, $okButton, sub { my ($self, $event) = @_; #print "\nOK Button\n"; #Convert the pdf file to png using # "convert" command line command via "system +" function call my @convertcommand = ( "convert", $self->{inpath}, "-crop", $self->{cropstring}, $self->{inpath} . ".p +ng" ); #print "\n\n@convertcommand\n\n"; system @convertcommand; # Execute conv +ert command }); Wx::Event::EVT_BUTTON($frame, $exitButton, sub { my ($self, $event) = @_; #print "\nEXIT Button\n"; #exit (0); # Causing Sgem +entation Fault(core dumped) $self->Close; # This seems t +o work ok }); Wx::Event::EVT_FILEPICKER_CHANGED($frame, $pdfFilePicker, sub { my ($self, $event) = @_; $self->{inpath} = $pdfFilePicker->GetPath; }); Wx::Event::EVT_TEXT($frame, $cropStringText, sub { my ($self, $event) = @_; $self->{cropstring} = $cropStringText->GetVa +lue; }); $verticalSizerFrame->Layout(); return $frame; } 1;

    James

    There's never enough time to do it right, but always enough time to do it over...

A reply falls below the community's threshold of quality. You may see it by logging in.