Hi Team, Please find the details below.
Requirement : We want to convert HEIC image to PDF along with Same Dimensions and Resolutions.
Please find the sample code and HEIC image metadata.
private static void ConvertHeicToPdfUsingAspose_Raster(string heicPath, string outputPdfPath)
{
try
{
HEICImage.Register(); // Register HEIC support
using (var image = Aspose.Imaging.Image.Load(heicPath))
{
if (!(image is Aspose.Imaging.RasterImage rasterImage))
{
Console.WriteLine("Unsupported image format.");
return;
}
// Get DPI and dimensions
float dpiX = (float)(rasterImage.HorizontalResolution > 0 ? rasterImage.HorizontalResolution : 96f);
float dpiY = (float)(rasterImage.VerticalResolution > 0 ? rasterImage.VerticalResolution : 96f);
float widthPoints = image.Width * 72f / dpiX;
float heightPoints = image.Height * 72f / dpiY;
// Save image to stream in a supported format (e.g., PNG)
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, new PngOptions());
ms.Position = 0;
// Create PDF and set page size to match image resolution
var pdfDocument = new Aspose.Pdf.Document();
var page = pdfDocument.Pages.Add();
page.SetPageSize(widthPoints, heightPoints);
var pdfImage = new Aspose.Pdf.Image
{
ImageStream = ms,
FixWidth = widthPoints,
FixHeight = heightPoints,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center
};
page.Paragraphs.Add(pdfImage);
pdfDocument.Save(outputPdfPath);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
HEIC File Meta data :
ExifTool Version Number : 13.32
File Name : sample-heic.heic
File Size : 539 kB
Zone Identifier : Exists
File Modification Date/Time : 2025:08:18 03:33:16-04:00
File Access Date/Time : 2025:08:20 04:46:48-04:00
File Creation Date/Time : 2025:08:18 03:37:18-04:00
File Permissions : -rw-rw-rw-
File Type : HEIC
File Type Extension : heic
MIME Type : image/heic
Major Brand : High Efficiency Image Format HEVC still image (.HEIC)
Minor Version : 0.0.0
Compatible Brands : mif1, heic
Handler Type : Picture
Primary Item Reference : 1
Exif Byte Order : Big-endian (Motorola, MM)
Orientation : Horizontal (normal)
X Resolution : 72
Y Resolution : 72
Resolution Unit : inches
Y Cb Cr Positioning : Centered
XMP Toolkit : Image::ExifTool 12.40
HEVC Configuration Version : 1
General Profile Space : Conforming
General Tier Flag : Main Tier
General Profile IDC : Format Range Extensions
Gen Profile Compatibility Flags : Format Range Extensions
Constraint Indicator Flags : 0 0 0 0 0 0
General Level IDC : 150 (level 5.0)
Min Spatial Segmentation IDC : 0
Parallelism Type : 0
Chroma Format : 4:2:0
Bit Depth Luma : 8
Bit Depth Chroma : 8
Average Frame Rate : 0
Constant Frame Rate : Unknown
Num Temporal Layers : 1
Temporal ID Nested : Yes
Image Width : 2400
Image Height : 1600
Image Spatial Extent : 2400x1600
Media Data Size : 538619
Media Data Offset : 471
Image Size : 2400x1600
Megapixels : 3.8
Sample File :
sample-heic.7z (524.6 KB)
Question :
As per meta data X & Y Resolution is “72” using code we are unable to get this value. When open image and verify the file information / properties we can able to see the “72 dpi”.
rasterImage.HorizontalResolution
rasterImage.VerticalResolution
In these lines of code I am getting 96 instead of 72.
Could you please help me here. Thank you.
Please find the Environment details:
- .Net framework 4.8
- Aspose.Imaging (Version : 25.8.0.0)
- Aspose.Imaging.HEIC.Adapter (Version : 25.6.0.0)