Can anyone provide a sample of the easiest way to convert a JPEG to PDF?
-
Do you have the Microsoft Office suite available for use on this system? If so, then yes - there's a way, but it involves COM objects, and no third-party applications as the answers below insist are necessary. – gravity Dec 09 '16 at 14:49
3 Answers
All you have to do is print to a PDF virtual printer. There are many such printers available.

- 20,574
- 3
- 26
- 62
You can do this on Windows without the need for any third-party executables or libraries.
function ConvertToPdf($files, $outFile) {
Add-Type -AssemblyName System.Drawing
$files = @($files)
if (!$outFile) {
$firstFile = $files[0]
if ($firstFile.FullName) { $firstFile = $firstFile.FullName }
$outFile = $firstFile.Substring(0, $firstFile.LastIndexOf(".")) + ".pdf"
} else {
if (![System.IO.Path]::IsPathRooted($outFile)) {
$outFile = [System.IO.Path]::Combine((Get-Location).Path, $outFile)
}
}
try {
$doc = [System.Drawing.Printing.PrintDocument]::new()
$opt = $doc.PrinterSettings = [System.Drawing.Printing.PrinterSettings]::new()
$opt.PrinterName = "Microsoft Print to PDF"
$opt.PrintToFile = $true
$opt.PrintFileName = $outFile
$script:_pageIndex = 0
$doc.add_PrintPage({
param($sender, [System.Drawing.Printing.PrintPageEventArgs] $a)
$file = $files[$script:_pageIndex]
if ($file.FullName) {
$file = $file.FullName
}
$script:_pageIndex = $script:_pageIndex + 1
try {
$image = [System.Drawing.Image]::FromFile($file)
$a.Graphics.DrawImage($image, $a.PageBounds)
$a.HasMorePages = $script:_pageIndex -lt $files.Count
}
finally {
$image.Dispose()
}
})
$doc.PrintController = [System.Drawing.Printing.StandardPrintController]::new()
$doc.Print()
return $outFile
}
finally {
if ($doc) { $doc.Dispose() }
}
}
Example usage:
ConvertToPdf (gi *.jpeg| sort Name) out.pdf

- 1,308
- 11
- 35
Q
Can anyone provide a sample of the easiest way to convert a JPEG to PDF?
A
the first correct answer was just as brief from user3344003 above https://stackoverflow.com/a/41068017/10802527 however did not explain that Windows has the inbuilt ability via "Microsoft Print to PDF".
This can be used without powershell from the command line with good results but complicated by the fact that by default requires a manual response to specify filename. There are many ways round that such that printing file.txt to file.pdf can be easily configured in print ui. (However in some cases, the destination file may not already exist.)
Image to pdf is not as simple so without powershell we can print via
mspaint /pt image.jpg "Microsoft Print to PDF"
but again needs a workaround to the PortPrompt: issue see https://stackoverflow.com/a/71225924/10802527
so with or without powershell we simply need to run to a given port name with a default forms size, and here I have set one as A4Landscape for my Landscape inputs
mspaint /pt Landscape.jpg A4LPdf
File: C:\Users\Me\Documents\printout.pdf
Title: Untitled.jpg
Author: Me
Created: 2022-06-26 02:52:33
Modified: 2022-06-26 02:52:33
PDF Producer: Microsoft: Print To PDF
PDF Version: 1.7
File Size: 7.45 KB (7,632 Bytes)
Number of Pages: 1
Page Size: 21.0 x 29.7 cm (A4)
The eagle eyed will have spotted that although I specified Landscape the output is Portrait, and that is the core problem with blind print to PDF, there is no fine scale or orientation control without the user selections.
Each task should be considered as to end game. So if wanting a good PDF it is best to import image into a PDF app to do the conversion by numbers.
Hence I suggest the question and thus answer should be along the lines of
Q Can I save in a controlled fashion an image using MuTool.exe convert to PDF?
A Yes.

- 8,045
- 3
- 14
- 36