I’m trying to get image size and dimension of the attached pdfs. When an image is 150% or higher form the original size I would like to reject the file.
I found an example in your docs “Getting Image Information without Extracting the Images”:
But unfortunately I never reach the part where ScaledWidth and OriginalWidth is calculated.
I’ve adjusted the example so it will iterate through all pages and all contents:
Code snippet:
//Iterate through all the pages
foreach (Page page in doc.Pages)
{
...
// Get all the operators on first page of document
foreach (Operator op in page.Contents)
{
Thanks for using our products and sorry for the delayed response.
I have tested the scenario using Aspose.Pdf for .NET 8.1.0 using the following code snippet, and as per my observations, the image dimensions and related information is properly being retrieved. Can you please share which version of the product you are using. We are sorry for this inconvenience.
[C#]
// Load the source PDF document
Aspose.Pdf. **Document** doc = **new** Aspose.Pdf. **Document**("c:\\pdftest\\Hybride2.pdf");
**ImagePlacementAbsorber** abs = **new** **ImagePlacementAbsorber**();
// Load the contents of the first page
doc.Pages[1].Accept(abs);
**foreach** (**ImagePlacement** imagePlacement **in** abs.ImagePlacements)
{
// Get image properties
**Console**.Out.WriteLine("image width:" + imagePlacement.Rectangle.Width);
**Console**.Out.WriteLine("image height:" + imagePlacement.Rectangle.Height);
**Console**.Out.WriteLine("image LLX:" + imagePlacement.Rectangle.LLX);
**Console**.Out.WriteLine("image LLY:" + imagePlacement.Rectangle.LLY);
**Console**.Out.WriteLine("image horizontal resolution:" + imagePlacement.Resolution.X);
**Console**.Out.WriteLine("image vertical resolution:" + imagePlacement.Resolution.Y);
**Console**.Out.WriteLine("\n----- ");
// Retrieve image with visible dimensions
**Bitmap** scaledImage;
**using** (**MemoryStream** imageStream = **new** **MemoryStream**())
{
// Retrieve image from resources
imagePlacement.Image.Save(imageStream, System.Drawing.Imaging.**ImageFormat**.Png);
**Bitmap** resourceImage = (**Bitmap**)Bitmap.FromStream(imageStream);
// Create bitmap with actual dimensions
scaledImage = **new** **Bitmap**(resourceImage, (**int**)imagePlacement.Rectangle.Width,
(**int**)imagePlacement.Rectangle.Height);
}
}
Thank you for your reply. I've used Aspose Pdf for .NET 8.0.0 and retested with 8.1.0 but the results were the same. However after applying a (30day demo) license file I could use the ImagePlacementAbsorber which returned an ImagePlacementCollection with all the properties.
Thank you for your example, now I could easily use image resolution and scaling to decide if image has a minimum quality. Problem solved!
I am glad to hear that your problem is resolved while using the license file. Furthermore I would like to share that recently we have published a new version of Aspose.Pdf for .NET 8.2.0. You may consider upgrading to the latest release.
In the event of any further query, please feel free to contact.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.