'''' 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 GCTEXT = GrapeCity.Documents.Text '' Creates pages of 'slides' from all images found in a directory.'''' IMPORTANT NOTE: When you render an image in DsPdf multiple times (e.g. rendering'' the same image as part of a page header on all pages), it will automatically be'' added to a dictionary and reused throughout the document, provided you use'' the same image object on all pages. So rather than loading the same image from'' file (or stream) each time it is needed, it is always preferable to load the image'' once and cache it in an image object. This applies to all image types used in DsPdf.PublicClassSlidePagesFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()'' Get a font for captions:Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf"))'' GcPdfDocument.ImageOptions controls various image-related settings.'' In particular, we can lower the JPEG quality from the default 75% to reduce the file size: doc.ImageOptions.JpegQuality = 50 '' Load all images from the Resources/Images folder:Dim images = New List(Of Tuple(OfString, IImage))ForEach fname InDirectory.GetFiles(Path.Combine("Resources", "Images"), "*", SearchOption.AllDirectories) images.Add(Tuple.Create(Path.GetFileName(fname), Util.ImageFromFile(fname)))Next images.Shuffle()'' Print all images as slide sheets in a 3x4 grid with 1/2" margins all around:Constmargin = 36.0FConstrows = 4Constcols = 3Dim gapx = 72.0F / 4, gapy = gapxDim sWidth = (doc.PageSize.Width - margin * 2 + gapx) / colsDim sHeight = (doc.PageSize.Height - margin * 2 + gapy) / rowsIf sWidth > sHeight Then gapx += sWidth - sHeight sWidth = sHeightElse gapy += sHeight - sWidth sHeight = sWidthEndIf ConstsMargin = 72.0F / 6'' Set up image alignment that would center images within the specified area:Dim ia = NewImageAlign(ImageAlignHorz.Center, ImageAlignVert.Center, True, True, True, False, False)'' Text format for image captions:Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = sMargin * 0.65F}'' Insertion point:Dim ip = NewPointF(margin, margin)Dim g = doc.NewPage().GraphicsFor i = 0To images.Count() - 1Dim rect = NewRectangleF(ip, NewSizeF(sWidth - gapx, sHeight - gapy)) g.FillRectangle(rect, Color.LightGray) g.DrawRectangle(rect, Color.Black, 0.5F) rect.Inflate(-sMargin, -sMargin)'' We get the actual rectangle where the image was drawn from the DrawImage method'' (via an output parameter) so that we can draw a thin border exactly around the image'' (an array is required as the image can be tiled, in which case multiple rectangles'' will be returned):Dim imageRect AsRectangleF() = Nothing g.DrawImage(images(i).Item2, rect, Nothing, ia, imageRect) g.DrawRectangle(imageRect(0), Color.DarkGray, 1)'' Print image file name as caption in the bottom slide margin: g.DrawString(Path.GetFileName(images(i).Item1), tf,NewRectangleF(rect.X, rect.Bottom, rect.Width, sMargin),TextAlignment.Center, ParagraphAlignment.Near, False) ip.X += sWidthIf ip.X + sWidth > doc.PageSize.WidthAndAlso i < images.Count() - 1Then ip.X = margin ip.Y += sHeightIf ip.Y + sHeight > doc.PageSize.HeightThen g = doc.NewPage().Graphics ip.Y = marginEndIfEndIfNext'''' Done: doc.Save(stream)'' Dispose images (can be done only after saving the document): images.ForEach(Sub(t_) t_.Item2.Dispose())Return doc.Pages.CountEndFunctionEndClass