The following example demonstrates how to modify the paths contained in a PDF document. It covers how to get the path & then modify its brush's characteristics.
| Modify the paths found in a PDF document (C#) |
Copy Code |
|---|---|
public static void ModifyPaths() { Console.WriteLine( "=== MODIFY PATHS ===" ); var filename = "DocumentWithPaths.pdf"; var outputFileName = "ModifyPaths.pdf"; var outputPath = PathsSample.PathsSampleOutputDirectory + outputFileName; // Load a PdfDocument. using( var pdfDoc = PdfDocument.Load( PathsSample.PathsSampleResourcesDirectory + filename ) ) { // Gets the first Page. var page1 = pdfDoc.Pages.First(); // Gets the first path from the first page. var blueRect = page1.Paths[ 0 ]; // Modify the blueRect Pen Paint(to red), position(to 360,360) and size(to 100x100). blueRect.Pen = blueRect.Pen.SetPaint( new RGBPaint( Color.Red ) ); blueRect.Bounds = new Rectangle( 360, 360, 100, 100 ); var pinkRect = page1.Paths[ 1 ]; // Modify the pinkRect Fill Brush(to Orange) and position(to 72,360). pinkRect.Brush = Brushes.Orange; pinkRect.Bounds = new Rectangle( 72, 360, pinkRect.Bounds.Width, pinkRect.Bounds.Height ); // Saves the output document. pdfDoc.SaveAs( outputPath ); Console.WriteLine( $"Info exported to path: {outputFileName}" ); } } | |