Solved

Powershell to convert image files to .pdf

Posted on 2016-08-20
6
886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 54

Accepted Solution

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

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 54

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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 54

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

622 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