Solved

Powershell to convert image files to .pdf

Posted on 2016-08-20
6
327 Views
Last Modified: 2016-08-21
Hello,  
Thanks for reading my post.  
Does anyone have example powershell script to convert image files to .pdf; example image format files are JPG, PNG, BMP, GIF, TIFF?  An example of the use case is employee expense reimbursement.  An employee digitizes their cash receipts; scenario A - captures an image of a cab ride receipt with his/her cell phone and scenario B - scans a hotel invoice with a mobile personal scanner.  The employee attaches two image format files to an e-mail requesting reimbursement.  The corporate accounts payable associate uses a workstation desktop image to pdf conversion utility to compile both images into a single .PDF file.   The single .PDF file is later uploaded into a Document Imaging Software.   A Business Process Management (BPM) product like BizTalk would call the powershell command as part of the business process automation routine.
0
Comment
Question by:jrbledsoe001
  • 3
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Joe Winograd, EE MVE earned 250 total points
ID: 41763844
Both GraphicsMagick and ImageMagick can do it. They are command line executables that can convert any image file type to PDF. Simply include a command line call to them in your PowerShell script or batch file or any scripting/programming language that can call a command line executable. For example, this EE article shows how to call GraphicsMagick from a batch file:
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method

That article also explains how to download/install it and discusses issues surrounding the various editions. Regards, Joe
0
 
LVL 79

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 250 total points
ID: 41763890
powershell has no native commands to do this, you would have to call the program

GM ftp location for win32/win64 http://78.108.103.11/MIRROR/ftp/GraphicsMagick/windows/
code below doesn't work it call's gm but there is no output
$source_dir = read-host 'Source Location no backslash'
$destination_dir = read-host 'destination directory without backslash'
$files = Get-ChildItem -Path $source_dir -filter '*.jpg'
foreach($file in $files){
$destination_file = $destination_dir + '\' + $file.Name -replace '.jpg','.pdf'
#write-host ('{0}  {1}' -f $file.FullName,$destination_file) 
start-process -filepath 'C:\Program Files\GraphicsMagick-1.3.21-Q16\gm.exe' -ArgumentList "convert $file.FullName  $destination_file" -WindowStyle Hidden 
}

Open in new window

0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 41763969
Here's an EE article I wrote that shows how to create a single PDF file from multiple image files using GraphicsMagick:

Create a PDF file with Contact Sheets (montage of thumbnails) for all JPG files in a folder and each of its subfolders using an automated, batch method

The core of the solution is one line of code:
gm.exe montage -compress JPEG -font Arial -pointsize %FilenameFontSize% -tile %ColumnsByRows% -frame 6 -shadow -label %%t -geometry %ThumbnailPixelSize% *.jpg %OutputFile%

Open in new window

The article talks about JPG input files, but they can be other image file types. It uses some options that you may or may not care about, such as -frame, -shadow, -label, etc. And there are a ton of other options besides the ones in the article. Here's a link to its command line syntax where you may read about the multitude of options:
http://www.graphicsmagick.org/GraphicsMagick.html

Regards, Joe
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:jrbledsoe001
ID: 41764479
Thank you for your comments - they are insightful and thought provoking.  The GraphicsMagick solution sounds like a great option when you have access to the server to install code or an executable.  In the day and age of Software as a Service (SaaS) and applications running on public cloud there are often limitations to calling external programs.  I do appreciate that you took the time to respond to my inquiry and provide code samples!
0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 41764487
Are you saying that you want a public cloud-based solution?
0
 

Author Comment

by:jrbledsoe001
ID: 41764494
Joe and David,  You both provided enough insight for me to move forward.  Thank you!!
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
The goal of this is to tech the user how to export photos out of Lightroom and the different options they have. Select which photos you want to export : Select where you want to export and with which options : Export :
The goal of the tutorial is to teach the user how to import photos into Adobe Lightroom efficiently and to keep everything organized.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now