'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.LinqImportsSystem.Collections.GenericImportsGrapeCity.Documents.Pdf '' This sample shows how to save pages of an existing PDF as images.'' It loads a PDF generated by the SlidePages sample, then saves'' the whole PDF as a multi-page TIFF. It also saves each of the pages'' as a separate JPEG image.'' All generated images are attached to the resulting PDF.'' '' Other image formats that are also supported: PNG, BMP, GIF.PublicClassSaveAsImagePublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage() Util.AddNote("We load the PDF generated by the 'Slide Pages' sample, " +"and save the whole PDF as a multi-page TIFF. " +"We also save each of the pages as a separate JPEG image. " +"Finally, the last page is saved as SVGZ (compressed SVG). " +"All created images are then attached to this document.", page) '' Keep track of temp files, delete them on exit:Dim tfiles = NewList(OfString) Using fs = NewFileStream(Path.Combine("Resources", "PDFs", "SlidePages.pdf"), FileMode.Open, FileAccess.Read)Dim origDoc = NewGcPdfDocument() origDoc.Load(fs)'' Save all pages of the loaded PDF as a multi-page TIFF:Dim tf = Path.GetTempFileName() origDoc.SaveAsTiff(tf)Dim fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, tf)) fspec.File.FileName = "SlidePages.tiff" doc.EmbeddedFiles.Add(tf, fspec) tfiles.Add(tf) '' Save each page of the loaded PDF as a JPEG:ForEach p In origDoc.Pages tf = Path.GetTempFileName() p.SaveAsJpeg(tf) fspec = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, tf)) fspec.File.FileName = $"Page_{p.Index}.jpeg" doc.EmbeddedFiles.Add(tf, fspec) tfiles.Add(tf)Next EndUsing'' Done: doc.Save(stream)'' Clean up: tfiles.ForEach(Sub(tf_) File.Delete(tf_))Return doc.Pages.CountEndFunctionEndClass