Convert Multi page tiff to pdf using Powershell

Hello -


I am trying to convert a multi page tiff to PDF using Powershell. Can anyone provide a code snippet?

Thanks in advance.

Hi There,


Thanks for contacting support.

I am preparing the code snippet for PowerShell to convert a multi page TIFF to PDF. Please be patient. I will get back to you shortly.

Best Regards,

Hi,

Thanks for your patience.

I tried converting multi page TIFF into PDF in PowerShell using following code snippet and was unable to convert. I am afraid that API is having some issue when converting images (i.e TIFF, PNG, etc) into PDF.

# Load the Assemblies

Add-Type -literalpath ($PSScriptRoot + "\Aspose.Pdf.dll")

Add-Type -AssemblyName System.IO

Add-Type -AssemblyName System.Drawing


$license = new-object Aspose.Pdf.License

$license.SetLicense($PSScriptRoot + "\Aspose.Total.lic")

# Instantiate Document Object

$doc = new-object Aspose.Pdf.Document

# Add a page to pages collection of document

$page = $doc.Pages.Add()

# Load the source image file to Stream object

$file = $PSScriptRoot + "\input.tif"

$tmpBytes = Get-Content $file -Encoding byte


$mystream = new-object System.IO.MemoryStream

$mystream.Read($tmpBytes, 0, $tmpBytes.Length)

# Instantiate BitMap object with image

$b = new-object System.Drawing.Bitmap($file)

$error[0]|format-list -force

# Set margins so image will fit, etc.

$page.PageInfo.Margin.Bottom = 0

$page.PageInfo.Margin.Top = 0

$page.PageInfo.Margin.Left = 0

$page.PageInfo.Margin.Right = 0


$page.CropBox = New-Object Aspose.Pdf.Rectangle(0, 0, $b.Width, $b.Height)

# Create an image object

$image1 = new-object Aspose.Pdf.Image

# Add the image into paragraphs collection of the section

$page.Paragraphs.Add($image1)

# Set the image file stream

$image1.ImageStream = $mystream

# Save resultant PDF file

$doc.Save($PSScriptRoot + "\output.pdf")

$error[0]|format-list -force

$mystream.Close()

However for further investigation I have logged this issue as PDFNET-42253 in our issue tracking system. We will further look into the details which are causing the issue and keep you updated on the status of resolution within this thread. Please be patient and spare us a little time. We are sorry for the inconvenience.

Best Regards,