Imports System
Imports System.IO
Imports System.Text
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.Formats.PDF
Public Function SaveCompressedPDFtoStream(inputFileName As String) As Stream
' Load PDF document.
Dim pdfDocument As ImGearPDFDocument
Using fileStream As New FileStream(inputFileName, FileMode.Open, FileAccess.Read,
FileShare.Read)
pdfDocument = DirectCast(ImGearFileFormats.LoadDocument(fileStream),
ImGearPDFDocument)
End Using
' Save compressed PDF document to stream.
Dim stream As Stream = New MemoryStream()
pdfDocument.SaveCompressed(stream)
Return stream
End Function