//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingSystem.Text;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Drawing; namespaceDsPdfWeb.Demos{ // This sample loads a PDF (we use the document generated by the Wetlands sample)// and extracts all images from it. It then prints those images into a new PDF,// centered one per page.publicclassGetImages {publicintCreatePDF(Stream stream) {// Load an existing PDF with some images:var docSrc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf")); docSrc.Load(fs);// This call extracts information about images from the loaded PDF,// note that for large files it may take a while to complete:var imageInfos = docSrc.GetImages(); var doc = newGcPdfDocument();var textPt = newPointF(72, 72);var imageRc = newRectangleF(72, 72 * 2, doc.PageSize.Width - 72 * 2, doc.PageSize.Height - 72 * 3);var tf = newTextFormat() { Font = StandardFonts.Times, FontSize = 12 };foreach (var imageInfo in imageInfos) {// The same image may appear on multiple locations, // imageInfo includes page indices and locations on pages;// for simplicity sake we only print page numbers here:var sb = newStringBuilder(); imageInfo.Locations.ForEach(il_ => sb.Append((il_.Page.Index + 1).ToString() + ", "));var g = doc.NewPage().Graphics; g.DrawString($"This image appears on page(s) {sb.ToString().TrimEnd(' ', ',')} of the original PDF:", tf, newPointF(72, 72)); g.DrawImage(imageInfo.Image, imageRc, null, ImageAlign.ScaleImage); }// Done: doc.Save(stream);return doc.Pages.Count; } }}