Solved

Powershell to convert image files to .pdf

Posted on 2016-08-20
6
207 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 51

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 78

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 51

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 51

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

13 Experts available now in Live!

Get 1:1 Help Now