Add EMF Image to PDF Document in C++

We are trying to create pdf and add some emf files into it but seems emf are not supported so we tried to convert them to SVG and then add . Convert EMF to SVG using C++ application | products.aspose.com but we are not finding namespaces “Aspose::Slides::Export::SaveFormat::Svg” could you help?

@ashvek,
Thank you for contacting support.

If I understand you correctly, you have a PowerPoint presentation, you want to add EMF images to the presentation and then convert it to a PDF document using Aspose.Slides for C++. Could you please confirm?

Thank you for responding. We have few EMF files to be placed on PDF. Do any of Aspose library directly support this?
After searching we came across the link where SVG can be placed in pdf using Aspose so we thought of converting our emf to SVG and place them. But the code sample above doesn’t have require namespaces which will help.

@ashvek,
Thank you for the clarification. I think you need the Aspose.PDF library to do this. I’ve moved this thread to the Aspose.PDF forum. My colleagues from the Aspose.PDF team will assist you shortly.

Yes, Our goal is to get our EMF images on PDF with proper alignment as we are building some pdf reports using them.

@ashvek Currently Aspose.PDF for C++ does not support EMF/WMF images.
You may use Aspose.Slides for C++ to create a presentation, add EMF image and save the presentation in PDF format.

#include <system/io/file.h>

#include <DOM/Presentation.h>
#include <DOM/SlideCollection.h>
#include <DOM/ShapeCollection.h>
#include <DOM/ImageCollection.h>
#include <DOM/Slide.h>
#include <DOM/Shape.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>

using namespace System;
using namespace System::IO;
using namespace Aspose::Slides;

int main()
{
    try
    {
        auto pres = MakeObject<Presentation>();
        auto slide = pres->get_Slides()->idx_get(0);
        auto image = pres->get_Images()->AddImage(File::ReadAllBytes(u"image.emf"));
        slide->get_Shapes()->AddPictureFrame(ShapeType::Rectangle, 10.0f, 10.0f, 500.0f, 500.0f, image);
        pres->Save(u"result.pdf", Export::SaveFormat::Pdf);
    }
    catch (const std::exception& e)
    {
        std::cout << e.what();
    }
}

ConsoleApplication1.7z (2.7 KB)

Thanks for the reply, This works great. Just wanted to ask if you support server side application of slides and if there is performance implication of using slides. If native pdf is better than conversion through slides?. I mean It took some few seconds of time for generating PDF using above code for single EMF image. We have like more then 100 images

@ashvek Most possibly you run the app in debug mode. Please try to run it in release mode. It will be much faster. Furthermore, it takes some time to initialize the library at the start of the app, subsequent file processing will not have this kind of delay.
Also, you can try this Online EMF to PDF converter.

Hi,

I been testing your solution for performance and quality and found out the emf vector image was added as raster image when i export the PDF. I have used following code:

emfFilePath1 = _filePath + u"DPV3070.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, x, y, imgW, imgH, image1);
pres->Save(u"result.pdf", Export::SaveFormat::Pdf);

attached result.pdf and original emf file for reference. Could you help ?
result.pdf (60.1 KB)

DPV3070.zip (5.0 KB)

@ashvek As I mentioned before (see message from Jul 2) Aspose.PDF for C++ does not support EMF/WMF images. Therefore you are using Aspose.Slides for C++.

Would you like me to connect you with Aspose.Slides team?