Solved

Powershell to convert image files to .pdf

Posted on 2016-08-20
6
530 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 53

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 80

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 53

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 53

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Use email signature images to promote corporate certifications and industry awards.
The goal of the tutorial is to teach the user what exposure is and how to use the exposure slider. Analyze the photo that you want to edit, then adjust the exposure slider to your liking.
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

808 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