Save from Word to Pdf images resolution

Hi,

I'm trying to save a Word document into a Pdf, by keeping the original images resolution.
In the converted Pdf file, using PdfExtractor I see that the images are always 150 dpi, even if I add 200 dpi images inside my Word document.
In the PdfSaveOptions I can use only JpegQuality property, which seems is ignored, anyway.

How can I keep the images resolution during saving from Word to Pdf?

Thank you


Hi Adrian,

Thanks for your query. It would be great, If you share your document for investigation purposes.

Hi,

I attached the documents. There is a Word which contains some images and the Pdf saved from it with the following code:

var wordDoc = new Document(wordDocument);

wordDoc.Save(@"C:\temp\docBeforePdf.docx");

byte[] pdfContent;
using (var pdfMemoryStream = new MemoryStream())
{

var pdfSaveOptions = new PdfSaveOptions
{
JpegQuality = 100,
MetafileRenderingMode = MetafileRenderingMode.Vector,
TextCompression = PdfTextCompression.None
};
wordDoc.Save(pdfMemoryStream, pdfSaveOptions);

pdfContent = pdfMemoryStream.GetContent();
}

Saving later the files with PdfExtractor i can see that all have the 150 dpi resolution and look worse than in Word document. I attached also an image obtained with PdfExtractor.

Thank you

Hi Adrian,

I have verified the images extracted from PDF file by using PdfExtractor and images looks good. Can you please explain some more detail about your issue? Are you talking about extracted images has bad quality?

Saving later the files with PdfExtractor i can see that all have the 150
dpi resolution and look worse than in Word document. I attached also an
image obtained with PdfExtractor.

Hi,

the images looks good, but no matter the settings, they always have 150 dpi. Like I mentioned previously, they have 200 dpi in the Word document. When I save it to Pdf, I expect to have images of 200 dpi, too, not scaled down to 150 dpi.

Thank you

Hi Adrian,

Please share images with 200 dpi for investigation purposes.

Hi again,

if you save non-chart images from the Word attached and look with Paint.NET (Photoshop, whatever) you 'll see it has 200 dpi.

The chart doesn't have 200 dpi because other bug in Aspose in Chart.ToImage (currently in investigation).

So, the non-chart images in Word has 200 dpi resolution. They look like text, but they are images.

Thanks

Hi Adrian,

I have tested the scenario and found that your query is more related to Aspose.PDF. I have shared my findings with Aspose.PDF team.

I am moving this thread to Aspose.PDF forum and my colleagues will reply you shortly.


Hi Adrian,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file.

We are able to reproduce your mentioned issue after an initial test regarding image resolution. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-33452. You will be notified via this forum thread regarding any update against the issue.

Sorry for the inconvenience,

Hi Adrian,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-33452 and have come to the conclusion that it is quite impossible to retrieve original resolution of an embedded image. Please note that XImage.Save methods always retrieve images with 150 dpi by default.

However you may consider using other Save method overloads that accept resolution parameter, but this is a way to manually set the resolution for the generated images. And there is a way to retrieve image resolution relative to pdf document dimensions (computed the same way like Adobe does).

The ImagePlacementAbsorber functionality must be used to do it: Please have a look over the following code snippet.

[C#]

// Open document

Document doc = new Document("d:/pdftest/savedFromWord.pdf");

// Create ImagePlacementAbsorber object to perform image placement search

ImagePlacementAbsorber abs = new ImagePlacementAbsorber();

// Accept the absorber for first page

doc.Pages.Accept(abs);

int imageIndex = 1;

// Retrieve images with visible dimensions

foreach (ImagePlacement imagePlacement in abs.ImagePlacements)

{

using (MemoryStream imageStream = new MemoryStream())

{

// Retrieve image from resources

imagePlacement.Image.Save(imageStream, ImageFormat.Jpeg);

Bitmap image = (Bitmap)Bitmap.FromStream(imageStream);

// set actial resolution for the image

image.SetResolution(imagePlacement.Resolution.X, imagePlacement.Resolution.Y);

image.Save("d:/pdftest/savedFromWord" + imageIndex.ToString() + ".jpeg", ImageFormat.Jpeg);

imageIndex++;

}

}


I have tested the scenario using current release version of Aspose.Pdf for .NET 7.0.0 and as per my observations, the resolution of extracted images is much better. Please try using it and in case you still encounter the same problem or you have any further query, please feel free to contact. We are sorry for the delay and inconvenience.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan