Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell to convert image files to .pdf

Posted on 2016-08-20
6
Medium Priority
?
1,341 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 56

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 earned 1000 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 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 1000 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 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 

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 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Microsoft Office Picture Manager is not included in Office 2013. This comes as quite a surprise to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This video expla…
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…

916 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