In This Topic
    Modify images
    In This Topic

    Introduction

    The following example demonstrates how to modify the images contained in a PDF document. It covers how to get an image & then modify its size, position & rotation angle.

    Modify images found in a PDF document (C#)
    Copy Code
    public static void ModifyImageSizeAndPosition()
    {
      Console.WriteLine( "=== MODIFY IMAGE SIZE AND POSITION ===" );
      var filename = "documentWithImage.pdf";
      var outputFileName = "ModifyImageSizeAndPosition.pdf";
      var outputPath = ImagesSample.ImagesSampleOutputDirectory + outputFileName;
    
      // Load a PdfDocument.
      using( var pdfDoc = PdfDocument.Load( ImagesSample.ImagesSampleResourcesDirectory + filename ) )
      {
        // Gets the first Page.
        var page1 = pdfDoc.Pages.First();
    
        // Gets the first image from the first page.
        var image = page1.Images[ 0 ];
    
        // Modify position, size and rotation of that image.
        image.Bounds = new Rectangle( 100, 150, 400, 400 );
        image.RotationAngle = 45d;
    
        // Saves the output document.
        pdfDoc.SaveAs( outputPath );
        Console.WriteLine( $"Info exported to path: {outputFileName}" );
      }
    }


    See Also

    Add elements to a PDF document

    Get elements from a PDF