Issue Generating PDF Files in C++: Vector EMF Images Are Changing to Raster

Hi, I have tried following code to add EMF image into the PDF page using Aspose.Slides but the final output pdf the image seems to be raster-based rather than the original vector based emf image.

emfFilePath1 = _filePath + u"DPV3070-New.emf";
auto sl = pres->get_LayoutSlides()->idx_get(1);
SharedPtr<ISlide> slide = pres->get_Slides()->AddEmptySlide(sl);
auto image1 = pres->get_Images()->AddImage(File::ReadAllBytes(emfFilePath1));
slide->get_Shapes()->AddPictureFrame(ShapeType::Rectangle, 0, 10.0f, 300.0f, 200.0f, image1);

pres->Save(u"result.pdf", Export::SaveFormat::Pdf);

Could you please help? What are the other ways to insert the EMF image into slide so it remains vector in the exported PDF?
DPV3070.zip (5.0 KB)

result.pdf (60.1 KB)

@ashvek,
Thank you for posting the question.

By default, Aspose.Slides converts vector images to raster images when converting PowerPoint presentations to PDF documents.You can use the PdfOptions class to specify whether vector images should be preserved in exported PDF files as is. The following code example shows you how to do this:

auto pdfOptions = MakeObject<PdfOptions>();
pdfOptions->set_SaveMetafilesAsPng(false);

pres->Save(outputFilePath, Export::SaveFormat::Pdf, pdfOptions);
pres->Dispose();

More examples: Convert PowerPoint to PDF in C++|Aspose.Slides Documentation

Thank you, could you please help with the header class to include for “Pdfoptions” in C++?
I tried to “#include <Export/IPdfOptions.h>” but its says cannot instantiate abstract class

@ashvek,
Please use the following header:

#include <Export/PdfOptions.h>

Thank you, that worked for me. Just want to clarify will there be any performance issues printing 20-30 EMF images in single page and creating 30–40-page vector-based PDF? If so than how can I optimize it?

@ashvek,
No, there shouldn’t be any performance issues when printing 20-30 EMF images on a single page and creating a 30–40-page vector-based PDF. EMF files are vector images, which typically take up less space compared to raster images, making them more suitable for multi-page PDF documents. However, it’s always a good idea to test with actual data to confirm this. Please let us know if performance does become an issue.

Thank you, sure we will get in touch if we face any issues. Just one more thing to clarify is for this test code I have used “File::ReadAllBytes(emfFilePath1)” from IImageCollection | Aspose.Slides for C++ API Reference

String emfFilePath1 = _filePath + u"DPV3070.emf";
auto image1 = pres->get_Images()->AddImage(File::ReadAllBytes(emfFilePath1));

Is this the optimized way of reading file in slides or I have to use different API among Iimagecollection?

We are about to purchase your license.

@ashvek,
This is the correct way to add the image to the presentation resources. You can also look at methods for adding images with other parameters that may be useful to you, particularly methods to which streams are passed.