The code below will help you to implement an VB.NET app to convert digital photos to PDF. ByteScout PDF SDK is the SDK for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings. It can be used to convert digital photos to PDF using VB.NET.
This code snippet below for ByteScout PDF SDK works best when you need to quickly convert digital photos to PDF in your VB.NET application. In your VB.NET project or application you may simply copy & paste the code and then run your app! Use of ByteScout PDF SDK in VB.NET is also explained in the documentation included along with the product.
Free trial version of ByteScout PDF SDK is available on our website. Documentation and source code samples are included.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
Imports Bytescout.PDF
''' <summary>
''' This example demonstrates how to add images in their proper orientation and size
''' </summary>
Class Program
Shared Sub Main()
' Create new document
Dim pdfDocument As Document = New Document()
pdfDocument.RegistrationName = "demo"
pdfDocument.RegistrationKey = "demo"
' Input image array
Dim arrImages = New String() {"Image1.jpg", "Image2.jpg"}
' Process each image
For Each itmImage In arrImages
Dim sysImage = FixImageOrientation(itmImage)
Using sysImage
Dim image = New Image(sysImage, ImageCompression.DCT, 75)
Dim w As Single = sysImage.Width / sysImage.HorizontalResolution * 72.0F
Dim h As Single = sysImage.Height / sysImage.VerticalResolution * 72.0F
' Create PDF page
Dim page = New Page(w, h)
Dim canvas = page.Canvas
canvas.DrawImage(image, 0, 0, w, h)
' Add PDF document
pdfDocument.Pages.Add(page)
End Using
Next
' Save PDF document
pdfDocument.Save("result.pdf")
' Cleanup
pdfDocument.Dispose()
' Open result document in default associated application (for demo purpose)
Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("result.pdf")
processStartInfo.UseShellExecute = True
Process.Start(processStartInfo)
End Sub
''' <summary>
''' Fix image orientation
''' </summary>
Private Shared Function FixImageOrientation(ByVal fileName As String) As System.Drawing.Image
Dim sysImage As System.Drawing.Image = System.Drawing.Image.FromFile(fileName, False)
' fix orientation by EXIF rotation tag
Const exifRotationTag As Integer = &H112
Dim propertyItemIDs As Integer() = sysImage.PropertyIdList
Dim found As Integer = Array.BinarySearch(propertyItemIDs, 0, propertyItemIDs.Length, exifRotationTag)
If found > -1 Then
Dim pi As System.Drawing.Imaging.PropertyItem = sysImage.GetPropertyItem(exifRotationTag)
Dim orientation As Integer = pi.Value(0)
Select Case orientation
Case 2
sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX)
Case 3
sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone)
Case 4
sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY)
Case 5
sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX)
Case 6
sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone)
Case 7
sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipX)
Case 8
sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone)
Case Else
End Select
sysImage.RemovePropertyItem(&H112)
End If
Return sysImage
End Function
End Class
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: