RemoveSquareImages.cs
// 完毕:
using System;
using System.IO;
using System.Drawing;
using System.Text;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Drawing;
using System.Linq;

namespace DsPdfWeb.Demos
{
    // This demo shows how to remove images that have a certain aspect ratio
    // (square, width same as height) from a PDF using the GcPdfDocument.RemoveImages() method.
    public class RemoveSquareImages
    {
        public int CreatePDF(Stream stream)
        {
            using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "SlidePages.pdf"));
            var doc= new GcPdfDocument();
            doc.Load(fs);
            // Get the list of images in the document:            
            var imageInfos = doc.GetImages();
            // Remove non-square images from the list:
            for (int i = imageInfos.Count - 1; i >= 0; i--)
            {
                if (imageInfos[i].Image.Width != imageInfos[i].Image.Height)
                    imageInfos.RemoveAt(i);
            }
            // Remove images left in the list from the PDF:
            doc.RemoveImages(imageInfos);
            // 完毕:
            doc.Save(stream);
            return doc.Pages.Count;
        }
    }
}