'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.NumericsImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.Graphics '' This sample shows how to create FormXObject representing a page'' from a PDF loaded into a temporary GcPdfDocument, and render that'' object into the current document.PublicClassPageFormXObjectFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.Graphics Dim rc = Util.AddNote("The thumbnails below are pages from an existing document. " +"We load an arbitrary PDF into a temporary GcPdfDocument, " +"then create a FormXObject representing each of its pages, " +"and render those objects as thumbnails into the current document. " +"To show that the same FormXObject can be used more than once, " +"we also render each thumbnail a second time applying a mirror transform.", page) '' Layout params:Dim margin = rc.LeftDim pad = 36Dim side = (page.Size.Width - margin * 2 - pad) / 2Dim ip = NewPointF(margin, rc.Bottom + pad)'' Mirror transform:Dim tr = Matrix3x2.CreateScale(-1, 1) * Matrix3x2.CreateTranslation(page.Size.Width, 0)'' Text format for the overlaid page captions:Dim clr = Color.DarkRedDim tf = NewTextFormat() With { .Font = StandardFonts.HelveticaBold, .FontSize = 16, .ForeColor = Color.FromArgb(128, clr) }'' Open an arbitrary PDF, load it into a temp document and loop over its pages,'' drawing each into the current document:Using fs = NewFileStream(Path.Combine("Resources", "PDFs", "Wetlands.pdf"), FileMode.Open, FileAccess.Read)Dim doc1 = NewGcPdfDocument() doc1.Load(fs)'' Create a list of FormXObject for the pages of the loaded PDF:Dim fxos = NewList(OfFormXObject)() doc1.Pages.ToList().ForEach(Sub(p_) fxos.Add(NewFormXObject(doc, p_)))'' Render the thumbnails into the current document:For i = 0To fxos.Count - 1If (ip.Y + side > page.Size.Height - margin) Then page = doc.NewPage() g = page.Graphics ip = NewPointF(margin, margin)EndIfDim rcfx = NewRectangleF(ip.X, ip.Y, side, side)'' Draw direct: g.DrawForm(fxos(i), rcfx, Nothing, ImageAlign.ScaleImage) g.DrawRectangle(rcfx, clr) g.DrawString($"Page {i + 1}", tf, rcfx, TextAlignment.Center, ParagraphAlignment.Center, False)'' Draw reversed: g.Transform = tr g.DrawForm(fxos(i), rcfx, Nothing, ImageAlign.ScaleImage) g.DrawRectangle(rcfx, clr) g.Transform = Matrix3x2.Identity rcfx.Offset(side + pad, 0) g.DrawString($"Reversed page {i + 1}", tf, rcfx, TextAlignment.Center, ParagraphAlignment.Center, False)'' ip.Y += side + padNextEndUsing'' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass