//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingSystem.Numerics;usingSystem.Collections.Generic;usingSystem.Linq;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Graphics; namespaceDsPdfWeb.Demos{// 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.publicclassPageFormXObject {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage();var g = page.Graphics; var rc = Common.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:var margin = rc.Left;var pad = 36;var side = (page.Size.Width - margin * 2 - pad) / 2;var ip = newPointF(margin, rc.Bottom + pad);// Mirror transform:var tr = Matrix3x2.CreateScale(-1, 1) * Matrix3x2.CreateTranslation(page.Size.Width, 0);// Text format for the overlaid page captions:var color = Color.DarkRed;var tf = newTextFormat() {Font = StandardFonts.HelveticaBold,FontSize = 16,ForeColor = Color.FromArgb(128, color), };// Open an arbitrary PDF, load it into a temp document and loop over its pages,// drawing each into the current document:usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf"));var doc1 = newGcPdfDocument(); doc1.Load(fs);// Create a list of FormXObject for the pages of the loaded PDF:var fxos = newList<FormXObject>(); doc1.Pages.ToList().ForEach(p_ => fxos.Add(newFormXObject(doc, p_)));// Render the thumbnails into the current document:for (int i = 0; i < fxos.Count; ++i) {if (ip.Y + side > page.Size.Height - margin) { page = doc.NewPage(); g = page.Graphics; ip = newPointF(margin, margin); }var rcfx = newRectangleF(ip.X, ip.Y, side, side);// Draw direct: g.DrawForm(fxos[i], rcfx, null, ImageAlign.ScaleImage); g.DrawRectangle(rcfx, color); g.DrawString($"Page {i + 1}", tf, rcfx, TextAlignment.Center, ParagraphAlignment.Center, false);// Draw reversed: g.Transform = tr; g.DrawForm(fxos[i], rcfx, null, ImageAlign.ScaleImage); g.DrawRectangle(rcfx, color); 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 + pad; }// Done: doc.Save(stream);return doc.Pages.Count; } }}