'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCDRAW = GrapeCity.Documents.Drawing PublicClassInterpolationModesPublicFunctionCreatePDF(ByVal stream AsStream) AsInteger' Small image of a QRCode that will be enlarged in PDFs that are then saved as JPEGs:Using image = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "QRCode-57x57.png"))' Create 4 PDFs, each is one page on which the small image is enlarged,' save each PDF as JPEG with different interpolation modes specified in SaveAsImageOptions:Dim tmpNearestNeighbor = Path.GetTempFileName()MakePDF(image, InterpolationMode.NearestNeighbor).SaveAsJpeg(tmpNearestNeighbor, Nothing,NewSaveAsImageOptions() With {.InterpolationMode = InterpolationMode.NearestNeighbor})Dim tmpLinear = Path.GetTempFileName()MakePDF(image, InterpolationMode.Linear).SaveAsJpeg(tmpLinear, Nothing,NewSaveAsImageOptions() With {.InterpolationMode = InterpolationMode.Linear})Dim tmpCubic = Path.GetTempFileName()MakePDF(image, InterpolationMode.Cubic).SaveAsJpeg(tmpCubic, Nothing,NewSaveAsImageOptions() With {.InterpolationMode = InterpolationMode.Cubic})Dim tmpDownscale = Path.GetTempFileName()MakePDF(image, InterpolationMode.Downscale).SaveAsJpeg(tmpDownscale, Nothing,NewSaveAsImageOptions() With {.InterpolationMode = InterpolationMode.Downscale}) ' Draw each JPEG at its natural size onto a page of the resulting PDF:Dim pageCount AsInteger = 0Using imgNearestNeighbor = GCDRAW.Image.FromFile(tmpNearestNeighbor), imgLinear = GCDRAW.Image.FromFile(tmpLinear), imgCubic = GCDRAW.Image.FromFile(tmpCubic), imgDownscale = GCDRAW.Image.FromFile(tmpDownscale)Dim doc = NewGcPdfDocument()Dim page = doc.NewPage() page.Graphics.DrawImage(imgNearestNeighbor, page.Bounds, Nothing, ImageAlign.Default) page = doc.NewPage() page.Graphics.DrawImage(imgLinear, page.Bounds, Nothing, ImageAlign.Default) page = doc.NewPage() page.Graphics.DrawImage(imgCubic, page.Bounds, Nothing, ImageAlign.Default) page = doc.NewPage() page.Graphics.DrawImage(imgDownscale, page.Bounds, Nothing, ImageAlign.Default)' Save the resulting PDF: doc.Save(stream) pageCount = doc.Pages.CountEndUsing' Cleanup:File.Delete(tmpNearestNeighbor)File.Delete(tmpLinear)File.Delete(tmpCubic)File.Delete(tmpDownscale) '' Done:Return pageCountEndUsingEndFunction ' InterpolationMode parameter here is only to show in the resulting PDF,' GcPdfGraphics only supports InterpolationMode.NearestNeighbor:PublicFunctionMakePDF(ByVal image AsGCDRAW.Image, ByVal imode AsInterpolationMode) AsGcPdfDocumentDim tfCaption = NewTextFormat() With { .Font = StandardFonts.Times, .FontSize = 20 }Dim tf = NewTextFormat() With { .Font = StandardFonts.Times, .FontSize = 18 } Dim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.Graphics Dim xpad = 36Dim ypad = 36Dim ip = NewPointF(xpad, ypad) g.DrawString($"SaveAsImageOptions.InterpolationMode is {imode}", tfCaption, ip) ip.Y *= 2.5F ' Draw the original with the original size: g.DrawImage(image, NewRectangleF(ip.X, ip.Y, image.Width, image.Height), Nothing, ImageAlign.Default) g.DrawString($"⟵ Original image ({image.Width} by {image.Height} pixels)", tf, NewPointF(ip.X * 2 + image.Width, ip.Y)) ip.Y += image.Height + ypad ' Enlarge the original small image by a factor of 8:Dim f = 8Dim twidth AsInteger = image.Width * fDim theight AsInteger = image.Height * f ' Draw the enlarged image: g.DrawImage(image, NewRectangleF(ip.X, ip.Y, twidth, theight), Nothing, ImageAlign.StretchImage) g.DrawString($"Image enlarged to {twidth} by {theight} pixels:", tf, NewPointF(ip.X, ip.Y - ypad)) Return docEndFunctionEndClass