Hi Team,
I am working on converting HEIC to PDF using Aspose.Imaging and I need to preserve dimensions when converted. For that I need dpi data for the image, but I am unable to fetch it. It uses the default dpi (96) instead of the actual dpi. Kindly look into this ASAP.
To fetch the DPI (dots per inch) from HEIC images when converting them to PDF using Aspose.Imaging, follow these steps:
-
Cause: You need to convert HEIC images to PDF while maintaining the correct DPI settings for quality output.
-
Solution: Use the
HEICImage
class to load your HEIC file, retrieve its dimensions, and set the desired DPI for the PDF document.
Here’s a sample code snippet to help you get started:
using System.IO;
using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Heic;
private static void ConvertHEICtoPDF()
{
// The path to the HEIC file
string heicFilePath = "path/to/your/image.heic";
// Load the HEIC image
using (var fs = new FileStream(heicFilePath, FileMode.Open))
{
var heicImage = HEICImage.Load(fs);
// Get image dimensions
int width = heicImage.Width;
int height = heicImage.Height;
// Set your desired DPI
float dpiX = 300;
float dpiY = 300;
// Create a PDF document
using (var document = new Aspose.Pdf.Document())
{
var page = document.Pages.Add();
var asposeImage = new Aspose.Pdf.Image();
// Set the image properties
asposeImage.ImageStream = new MemoryStream(heicImage.GetByteArray(PixelFormat.Rgb24));
asposeImage.BitmapInfo = new Aspose.Pdf.BitmapInfo(asposeImage.ImageStream, width, height, Aspose.Pdf.BitmapInfo.PixelFormat.Rgb24);
page.PageInfo.Height = height * 72 / dpiY; // Convert to points
page.PageInfo.Width = width * 72 / dpiX; // Convert to points
page.Paragraphs.Add(asposeImage);
// Save the PDF document
document.Save("output.pdf");
}
}
}
In this example, you load the HEIC image, retrieve its dimensions, and set the PDF page size based on the desired DPI. Adjust the dpiX
and dpiY
values as needed for your specific requirements.
- Next Steps: Implement the provided code in your project, ensuring you have the necessary Aspose libraries referenced. Test the conversion with different HEIC files to verify the output quality.
If you have any further questions or need additional assistance, feel free to ask!
What code you have provided above only hard codes the dpi. But I don’t want to hard code it, I want to fetch the actual dpi from the image. Kindly help me on that.
@Krishalini_H Hello!
At the moment Openize.HEIC doesn’t return resolution data.
As a result the default resolution is set when creating RasterImage. And that is 96.
We have planned it for the future update (not 25.8).
@Krishalini_H
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): IMAGINGNET-7788
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Hi, @Krishalini_H !
Let me inform you that we have released Aspose.Imaging.HEIC.Adapter 25.10 for .NET that fixes the issue discussed in this topic (filed as IMAGINGNET-7788).