Knowledgebase (2345)
Children categories
SVG (Scalable Vector Graphics) is a vector graphics format that can be scaled up or down without losing quality, which is especially useful when images need to be placed on large billboards/stadium screens, or when small logos and icons need to be saved. By the same token, if you want to make PDF pages infinitely scalable, you can convert them to SVG format. This article will demonstrate how to convert PDF to SVG in C++ using Spire.PDF for C++.
Install Spire.PDF for C++
There are two ways to integrate Spire.PDF for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.PDF for C++ in a C++ Application
Convert a PDF File to SVG in C++
Spire.PDF for C++ offers the PdfDocument->SaveToFile() method to convert each page in a PDF file to a single SVG file. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a sample PDF file using PdfDocument->LoadFromFile() method.
- Convert the PDF file to SVG using PdfDocument->SaveToFile(LPCWSTR_S filename, FileFormat::SVG) method.
- C++
#include "Spire.Pdf.o.h";
using namespace Spire::Pdf;
using namespace std;
int main()
{
//Specify the input and output files
wstring inputFile = L"Data\\sample1.pdf";
wstring outputFile = L"ToSVG\\ToSVG.svg";
//Create a PdfDcoument instance
intrusive_ptr<PdfDocument> pdf = new PdfDocument();
//Load a sample PDF document
pdf->LoadFromFile(inputFile.c_str());
//Convert the PDF document to SVG
pdf->SaveToFile(outputFile.c_str(),FileFormat::SVG);
pdf->Close();
}

Convert Specified PDF Pages to SVG in C++
Spire.PDF for C++ also allows you to convert specified pages in a PDF file to SVG files. During conversion, if you want to specify the width and height of the output SVG file, you can use the PdfDocument->GetConvertOptions()->SetPdfToSvgOptions() method. The following are the detailed steps to convert a selected PDF page to SVG with custom width and height.
- Create a PdfDocument instance.
- Load a sample PDF file using PdfDocument->LoadFromFile() method.
- Specify the width and height of the output SVG file using PdfDocument->GetConvertOptions()->SetPdfToSvgOptions(float wPixel, float hPixel) method.
- Convert selected PDF pages to SVG using PdfDocument->SaveToFile(LPCWSTR_S filename, int startIndex, int endIndex, FileFormat::SVG) method.
- C++
#include "Spire.Pdf.o.h";
using namespace Spire::Pdf;
using namespace std;
int main()
{
//Specify the input and output files
wstring inputFile = L"Data\\sample1.pdf";
wstring outputFile = L"PDFPagetoSVG.svg";
//Create a PdfDcoument instance
intrusive_ptr<PdfDocument> pdf = new PdfDocument();
//Load a sample PDF document
pdf->LoadFromFile(inputFile.c_str());
//Specify the width and height of the output SVG file
pdf->GetConvertOptions()->SetPdfToSvgOptions(900, 1200);
//Convert the specified PDF page to SVG
pdf->SaveToFile(outputFile.c_str(), 2, 2, FileFormat::SVG);
pdf->Close();
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
HTML is a markup language for creating websites or other web applications. In daily work, you might need to convert HTML to images for various reasons, such as creating thumbnails of web pages to use in search engine results pages or social media posts, generating snapshots of your html files for archiving or other purposes, and so on. In this article, you will learn how to convert Html to JPG, PNG, or BMP images in C++ using Spire.Doc for C++.
Install Spire.Doc for C++
There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.Doc for C++ in a C++ Application
Convert HTML to JPG, PNG and BMP Images in C++
To complete the task, you’ll need to load an HTML file first and then convert it to images using Document->SaveImageToStreams() method. These images can also be further saved as JPEG, PNG, BMP, EMF, GIF or WMF image formats. The following are the detailed steps.
- Create a Document instance.
- Load a sample html file using Document->LoadFromFile(LPCWSTR_S filename, FileFormat::Html, XHTMLValidationType::None) method.
- Convert the html file to an image stream using Document->SaveImageToStreams() method.
- Convert the image stream to an Image object using Image::FromStream(intrusive_ptr<Stream> stream) method.
- Save the Image object as a JPEG, PNG, BMP, or other image formats using Image->Save(LPCWSTR_S filename, ImageFormat format) method.
- C++
#include "Spire.Doc.o.h"
using namespace std;
using namespace Spire::Doc;
int main() {
//Specify the input file path
wstring inputFile = L"Data\\sample.html";
//Create a Document instance
intrusive_ptr<Document> document = new Document();
//Load a sample html file from disk
document->LoadFromFile(inputFile.c_str(), FileFormat::Html, XHTMLValidationType::None);
//Convert the html to image streams
intrusive_ptr<Stream> imageStream = document->SaveImageToStreams(0,ImageType::Bitmap);
//Save the image stream as a PNG, JPG or BMP image
intrusive_ptr<Image> image = Image::FromStream(imageStream);
image->Save(L"HtmlToPNG.png", ImageFormat::GetPng());
image->Save(L"HtmlToJPG.jpg", ImageFormat::GetJpeg());
image->Save(L"HtmlToImage.bmp", ImageFormat::GetBmp());
document->Close();
imageStream->Dispose();
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
If you have multiple images that you want to combine into one file for easier distribution or storage, converting them into a single PDF document is a great solution. This process not only saves space but also ensures that all your images are kept together in one file, making it convenient to share or transfer. In this article, you will learn how to combine several images into a single PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Combine Multiple Images into a Single PDF in C# and VB.NET
In order to convert all the images in a folder to a PDF, we iterate through each image, add a new page to the PDF with the same size as the image, and then draw the image onto the new page. The following are the detailed steps.
- Create a PdfDocument object.
- Set the page margins to zero using PdfDocument.PageSettings.SetMargins() method.
- Get the folder where the images are stored.
- Iterate through each image file in the folder, and get the width and height of a specific image.
- Add a new page that has the same width and height as the image to the PDF document using PdfDocument.Pages.Add() method.
- Draw the image on the page using PdfPageBase.Canvas.DrawImage() method.
- Save the document using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace ConvertMultipleImagesIntoPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Set the page margins to 0
doc.PageSettings.SetMargins(0);
//Get the folder where the images are stored
DirectoryInfo folder = new DirectoryInfo(@"C:\Users\Administrator\Desktop\Images");
//Iterate through the files in the folder
foreach (FileInfo file in folder.GetFiles())
{
//Load a particular image
Image image = Image.FromFile(file.FullName);
//Get the image width and height
float width = image.PhysicalDimension.Width;
float height = image.PhysicalDimension.Height;
//Add a page that has the same size as the image
PdfPageBase page = doc.Pages.Add(new SizeF(width, height));
//Create a PdfImage object based on the image
PdfImage pdfImage = PdfImage.FromImage(image);
//Draw image at (0, 0) of the page
page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height);
}
//Save to file
doc.SaveToFile("CombinaImagesToPdf.pdf");
doc.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.