'''' 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.DrawingImportsGrapeCity.Documents.Pdf.AnnotationsImports GCTEXT = GrapeCity.Documents.Text '' This sample loads all images found in a directory, then renders each image'' in the largest possible size on a separate page of the PDF.'' Finally it inserts a TOC of image thumbnails linked to the large images'' into the document.'' See also SlidePages.PublicClassImageLinksPrivateClassImageInfoPublicPropertyNameAsStringPublicPropertyImageAsIImagePublicPropertyPageIdxAsIntegerEndClass FunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Bold.ttf"))'' 1/4" page margins all around:Constmargin = 36.0F '' Load all images from the Resources/Images folder:Dim imageInfos AsNew List(OfImageInfo)ForEach fname InDirectory.GetFiles(Path.Combine("Resources", "Images"), "*", SearchOption.AllDirectories) imageInfos.Add(NewImageInfo() With {.Name = Path.GetFileName(fname), .Image = Util.ImageFromFile(fname)})Next imageInfos.Shuffle()'' Set up image alignment that would center images horizontally and align to top vertically:Dim ia = NewImageAlign(ImageAlignHorz.Center, ImageAlignVert.Top, True, True, True, False, False)'' Image rectangle for full-sized images - whole page:Dim rBig = NewRectangleF(margin, margin, doc.PageSize.Width - margin * 2, doc.PageSize.Height - margin * 2)'' Render all images full-size, one image per page:For i = 0To imageInfos.Count - 1Dim g = doc.NewPage().GraphicsDim ii = imageInfos(i) g.DrawImage(ii.Image, rBig, Nothing, ia) ii.PageIdx = iNext '' Insert page(s) with thumbnails into the beginning of the document as a 4x5 grid (see SlidePages):Constrows = 5Constcols = 4Dim 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 = sWidthEndIfConstsMargin = 72.0F / 6'' Center thumbnails vertically too: ia.AlignVert = ImageAlignVert.Center'' Text format for image captions:Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = sMargin * 0.65F}'' Insertion point:Dim ip = NewPointF(margin, margin)Dim page = doc.Pages.Insert(0)For i = 0To imageInfos.Count() - 1Dim ii = imageInfos(i)Dim rect = NewRectangleF(ip, NewSizeF(sWidth - gapx, sHeight - gapy))'' Add a link to the page where the full-sized image is (the page index'' will be updated when we know how many pages are in TOC, see below): page.Annotations.Add(NewLinkAnnotation(rect, NewDestinationFit(ii.PageIdx)))'' Draw thumbnail:Dim g = page.Graphics g.FillRectangle(rect, Color.LightGray) g.DrawRectangle(rect, Color.Black, 0.5F) rect.Inflate(-sMargin, -sMargin)Dim imageRect AsRectangleF() = Nothing g.DrawImage(ii.Image, rect, Nothing, ia, imageRect) g.DrawRectangle(imageRect(0), Color.DarkGray, 1)'' Print image file name as caption in the bottom slide margin: g.DrawString(ii.Name, tf,NewRectangleF(rect.X, rect.Bottom, rect.Width, sMargin),TextAlignment.Center, ParagraphAlignment.Near, False) ip.X += sWidthIf (ip.X + sWidth > doc.PageSize.Width) Then ip.X = margin ip.Y += sHeightIf (ip.Y + sHeight > doc.PageSize.Height) Then page = doc.Pages.Insert(doc.Pages.IndexOf(page) + 1) ip.Y = marginEndIfEndIfNext'' We now go through all TOC pages, updating page indices in links' destinations'' to account for the TOC pages inserted in the beginning of the document:Dim tocPages = doc.Pages.IndexOf(page) + 1For i = 0To tocPages - 1ForEach ann In doc.Pages(i).AnnotationsIfTypeOf ann IsLinkAnnotationAndAlsoTypeOfCType(ann, LinkAnnotation).DestIsDestinationFitThenDim link = DirectCast(ann, LinkAnnotation)Dim dest = DirectCast(CType(ann, LinkAnnotation).Dest, DestinationFit) link.Dest = NewDestinationFit(dest.PageIndex.Value + tocPages)EndIfNextNext'''' Done: doc.Save(stream) imageInfos.ForEach(Sub(ii_) ii_.Image.Dispose())Return doc.Pages.CountEndFunctionEndClass