//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations; namespaceDsPdfWeb.Demos{// This sample shows how to use the Page.AdjustCoordinates() method// to convert visual coordinates (measured from the top left corner// of the page according to DsPdf rules) to correct coordinates in a PDF// that was loaded into GcPdfDocument and may have arbitrary unknown// transformations applied to its pages. The adjusted coordinates can be// used to position annotations (redact in this case) etc.//// The PDF used in this sample has one page containing the scan of a sample invoice// that was rotated 90 degrees clockwise. The PDF page is rotated 270 degrees to// compensate (so that visually the page has correct portrait orientation).publicclassAdjustCoords {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "invoice-scan-rot270.pdf")); doc.Load(fs); if (doc.Pages.Count != 1)thrownewException("Unexpected: sample invoice should have exactly one page."); var page = doc.Pages[0]; // The bounding rectangle of the area to redact,// measured from the top left corner of the PDF page.// If this rectangle is used as is, it will miss the target content:var rectToRedact = newRectangleF(20, 170, 200, 40); // The adjusted bounding rectangle, taking into consideration// any possible page transformations (rotation in this case):var adjusted = page.AdjustCoordinates(rectToRedact); // Note: if 'rectToRedact' is used instead of 'adjusted',// the redact will miss the target (customer name/address):var redact = newRedactAnnotation() {Page = page,Rect = adjusted,OverlayFillColor = Color.Orange,OverlayText = "Redacted", };// Apply the redact: doc.Redact(redact); // Done: doc.Save(stream);return doc.Pages.Count; } }}