Set Image Size
Contents
[
Hide
]
The following code snippet also work with Aspose.PDF.Drawing library.
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 FixWidth and FixHeight properties of Aspose.Pdf.Image Class. The following code snippet demonstrates how to set the size of an image:
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetImageSizeInPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Instantiate Document object
using (var document = new Aspose.Pdf.Document())
{
// Add page to pages collection of PDF file
var page = document.Pages.Add();
// Create an image instance
var img = new Aspose.Pdf.Image();
// Set Image Width and Height in Points
img.FixWidth = 100;
img.FixHeight = 100;
// Set image type as SVG
img.FileType = Aspose.Pdf.ImageFileType.Unknown;
// Path for source file
img.File = dataDir + "InputImage.jpg";
// Add image to the page
page.Paragraphs.Add(img);
// Set page properties
page.PageInfo.Width = 800;
page.PageInfo.Height = 800;
// Save resultant PDF file
document.Save(dataDir + "SetImageSize_out.pdf");
}
}