Set Image Size

[ ]

It is possible to set the size of an image that’s being added to a PDF file. In order to set size, you can use setFixWidth and setFixHeight methods of com.aspose.pdf.Image Class.

The following code snippet demonstrates how to set the size of an image:

package com.aspose.pdf.examples;

import com.aspose.pdf.*;

public class ExampleSetImageSize {
    private static String _dataDir = "/home/admin1/pdf-examples/Samples/";

    public static void Replace() {
        // Instantiate Document object
        Document doc = new Document();
        // add page to pages collection of PDF file
        Page page = doc.getPages().add();
        // Create an image instance
        Image img = new Image();
        // Set Image Width and Height in Points
        img.setFixWidth (100);
        img.setFixHeight (100);
        // Set image type as SVG
        img.setFileType (ImageFileType.Svg);
        // Path for source file
        img.setFile (_dataDir + "aspose-logo.jpg");
        // Set page properties
        // save resultant PDF file + "SetImageSize_out.pdf");