in reply to Conver PDF to Image( JPG , JPEG , etc. )

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...