Hi, We were trying your example code Add Image to PDF using C++|Aspose.PDF for C++ for adding single image on multiple pages but we encountered the issue for Annotation and Page “Pointer to incomplete class type is not allowed” We have also tried including Annotation.h but that doesn’t solve the issue. could you help?
@ashvek You should add the following statements to the example to avoid the “Pointer to incomplete class type is not allowed” error:
#include <system/io/file.h>
#include "Aspose.PDF.Cpp/Document.h"
#include "Aspose.PDF.Cpp/PageCollection.h"
#include "Aspose.PDF.Cpp/Page.h"
#include "Aspose.PDF.Cpp/Resources.h"
#include "Aspose.PDF.Cpp/XImage.h"
#include "Aspose.PDF.Cpp/XImageCollection.h"
#include "Aspose.PDF.Cpp/OperatorCollection.h"
#include "Aspose.PDF.Cpp/Operator.h"
#include "Aspose.PDF.Cpp/Rectangle.h"
#include "Aspose.PDF.Cpp/DOM/Matrix.h"
Also, you can use Aspose::Pdf::Page::AddImage function.
#include <system/io/file.h>
#include "Aspose.PDF.Cpp/Document.h"
#include "Aspose.PDF.Cpp/PageCollection.h"
#include "Aspose.PDF.Cpp/Page.h"
#include "Aspose.PDF.Cpp/Rectangle.h"
using namespace System;
using namespace System::IO;
using namespace Aspose::Pdf;
int main()
{
auto doc = MakeObject<Document>();
auto page = doc->get_Pages()->Add();
double x = 100.0, y = 600.0, width = 200.0, height = 200.0;
auto rect = MakeObject<Aspose::Pdf::Rectangle>(x, y, x + width, y + height);
page->AddImage(File::OpenRead(u"logo.png"), rect);
doc->Save(u"logo.pdf");
}
Thank you, This works well with PNG images can we add SVG images in PDF page? I tried the above code for svg but it give me error:
System::ArgumentException: __cdecl System::Drawing::Bitmap::Bitmap(const class System::SmartPtr &,bool)
Does Aspose.PDF 24.6 supports adding vector images(SVG) format?
@ashvek Using the 24.6 version you can convert the SVG image to PDF, like:
#include "Aspose.PDF.Cpp/Document.h"
#include "Aspose.PDF.Cpp/SvgLoadOptions.h"
using namespace System;
using namespace Aspose::Pdf;
int main()
{
auto doc = MakeObject<Document>(u"image.svg", MakeObject<SvgLoadOptions>());
doc->Save(u"svg.pdf");
}
Adding SVG images to existing PDF documents will be implemented in the 24.8 version (approx release date 23 Aug 2024)
Hi Alexander,
Existing code take one SVG image on one page. Our use case is to arrange multiple SVG Images(10-30) into one single PDF page. Please verify if this will be supported in 24.8 version.
@ashvek Adding multiple SVG images into one PDF document page will be available in the 24.8 version.