Free Support Forum - aspose.com

How to position the image

I would like the export set of images to pdf, and each of my images are having its own x and y postions, how to do that in the aspost.pdf.generator, Is there any sample for this ?

Hi Arun,


Thanks for your inquiry. You can add image to PDF page on your specified location using Aspsoe.Pdf for .NET. Please check following documentation link for the details and sample code.

However, please note it is recommended to use Aspose.Pdf (new generator) instead Aspose.Pdf.Generator(old generator), as new generator is more improved and efficient. Moreover, new generator can not only be used for creating a new PDF document from scratch but also to manipulate existing PDF documents.

If you want to create a new PDF document with image on specified location then you should use Document() ctor without a parameter and create a new page as following.

// Open document<o:p></o:p>

//Document pdfDocument = new Document("input.pdf");

Document pdfDocument = new Document();

// Set coordinates

int lowerLeftX = 100;

int lowerLeftY = 100;

int upperRightX = 200;

int upperRightY = 200;

// Get the page where image needs to be added

//Page page = pdfDocument.Pages[1];

Aspose.Pdf.Page page = pdfDocument.Pages.Add();

....

....


Please feel free to contact us for any further assistance.

Best Regards,

I want to get the image position, exactly where it will added in the page, when I write page.Paragraphs.Add(img)

I want to calculate if the image fits in the available page empty area or I need to create a new page and add it.
The image type is SVG so it overflows it the image does not fit in the page.

Please reply at your earliest

@PriyankaShelke

We would like to share with you that Paragraph class does not expose any property that can be used to determine location of any paragraph. Paragraphs are added in Flow layout (Top to Bottom). In case you want to add an image on a PDF page at specific position, you may add it as an ImageStamp while setting XIndent and YIndent properties as per your requirements. For further information on this, you may visit Adding Image Stamp in PDF File for your kind reference.