Tuesday, 20 June 2023 01:05

C++: Convert PDF to SVG

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();
}

C++: Convert PDF to SVG

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();
}

C++: Convert PDF to SVG

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.

Published in Conversion
Monday, 24 April 2023 01:11

C++: Convert PDF to Excel

PDF files are great for delivering documents in a standard format that looks exactly the same no matter what device or software you use to view them, but they are difficult to edit. If you have a spreadsheet in PDF format, usually the easiest way to work with the data is to convert the PDF to Excel and edit it there. In this article, you will learn how to convert PDF to Excel 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 PDF to Excel in C++

Spire.PDF for C++ offers the PdfDocument->SaveToFile() method to convert PDF documents to other file formats including XLSX. Before converting, you can set the conversion options by using PdfDocument->GetConvertOptions->SetPdfToXlsxOptions() method. This method takes the XlsxLineLayoutOptions object as a parameter, and the constructor of the XlsxLineLayoutOptions class has the following five parameters, enabling you to control how PDF will be converted to Excel.

  • bool convertToMultipleSheet: Indicates whether each page of the PDF will be converted to a worksheet in Excel.
  • bool rotatedText: Indicates whether to show rotated text.
  • bool splitCell: Indicates whether a PDF table cell containing text spanning several lines will be split into multiple rows in Excel.
  • bool wrapText: Indicates whether to wrap text in an Excel cell.
  • bool overlapText: Indicates whether to display overlapping text.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;

int main() {

    //Create a PdfDcoument object
    PdfDocument* doc = new PdfDocument();

    //Load a PDF document
    doc->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\Business sales invoice.pdf");

    //Create a XlsxLineLayoutOptions object
    XlsxLineLayoutOptions* options = new XlsxLineLayoutOptions(true, true, false, true, false);

    //Set PDF to XLSX convert options
    doc->GetConvertOptions()->SetPdfToXlsxOptions(options);

    //Save the PDF document to Excel
    doc->SaveToFile(L"output/PdfToExcel.xlsx", FileFormat::XLSX);
	doc->Close();
	delete doc;
}

C++: Convert PDF to Excel

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.

Published in Conversion
Wednesday, 19 April 2023 00:45

C++: Convert PDF to PDF/A or PDF/X

PDF/A and PDF/X are two subsets of PDF file formats that were created to standardize the use of PDF in different areas. The former, PDF/A format, is primarily used for the long-term preservation or archiving of electronic documents, while the latter, PDF/X format, is specifically designed for the reliable and accurate pre-print exchange of graphic data. This article will demonstrate how to programmatically convert PDF to PDF/A or PDF/X format 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 PDF to PDF/A-1A, 2A, 3A, 1B, 2B and 3B in C++

With the passage of time, PDF/A has been continuously enhanced and further standards such as PDF/A-1, PDF/A-2 and PDF/A-3 have been developed. In addition, each standard defines several different levels of conformance. The following are the steps to convert PDF to PDF/A-1A, 2A, 3A, 1B, 2B and 3B compliant files.

  • Create a PdfStandardsConverter instance, and pass in a sample PDF file as a parameter.
  • Convert the sample file to PdfA1A conformance level using PdfStandardsConverter->ToPdfA1A() method.
  • Convert the sample file to PdfA1B conformance level using PdfStandardsConverter->ToPdfA1B() method.
  • Convert the sample file to PdfA2A conformance level using PdfStandardsConverter->ToPdfA2A() method.
  • Convert the sample file to PdfA2B conformance level using PdfStandardsConverter->ToPdfA2B() method.
  • Convert the sample file to PdfA3A conformance level using PdfStandardsConverter->ToPdfA3A() method.
  • Convert the sample file to PdfA3B conformance level using PdfStandardsConverter->ToPdfA3B() method.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;
using namespace std;
int main() {

	//Specify the input file
	wstring inputFile = L"Data\\Test.pdf";

	//Create a PdfStandardsConverter instance
	PdfStandardsConverter* converter = new PdfStandardsConverter(inputFile.c_str());

	//Convert to PdfA1A
	converter->ToPdfA1A(L"Output/ToPdfA1A.pdf");

	//Convert to PdfA1B
	converter->ToPdfA1B(L"Output/ToPdfA1B.pdf");

	//Convert to PdfA2A
	converter->ToPdfA2A(L"Output/ToPdfA2A.pdf");

	//Convert to PdfA2B
	converter->ToPdfA2B(L"Output/ToPdfA2B.pdf");

	//Convert to PdfA3A
	converter->ToPdfA3A(L"Output/ToPdfA3A.pdf");

	//Convert to PdfA3B
	converter->ToPdfA3B(L"Output/ToPdfA3B.pdf");

	delete converter;
}

C++: Convert PDF to PDF/A or PDF/X

Convert PDF to PDF/X-1a:2001 Standard in C++

PDF/X-1a:2001 is a standard published in 2001 and has been widely adopted by the printing and publishing industries. It restricts certain features of the PDF format to ensure that the file is suitable for high quality printing. The following are the steps to convert PDF to a PDF/X-1a:2001 standard-compliant file.

  • Create a PdfStandardsConverter instance, and pass in a sample PDF file as a parameter.
  • Convert the sample file to PDF/X-1a:2001 standards compliant file using PdfStandardsConverter->ToPdfX1A2001() method.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;
using namespace std;
int main() {

	//Specify the input file
	wstring inputFile = L"Data\\Test.pdf";

	//Create a PdfStandardsConverter instance
	PdfStandardsConverter* converter = new PdfStandardsConverter(inputFile.c_str());

	//Convert to PDF/X-1a:2001
	converter->ToPdfX1A2001(L"Output/ToPdfX1A2001.pdf");
	converter->Dispose();
	delete converter;
}

C++: Convert PDF to PDF/A or PDF/X

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.

Published in Conversion
Wednesday, 15 March 2023 01:07

C++: Convert PDF to Word

PDF documents are great for presenting documents on different devices while keeping documents' appearance unchanged. It can also facilitate the sharing and transmission of documents. But editing PDF documents is usually quite troublesome. Therefore, many users will choose to convert PDF documents into easy-to-edit Word documents to facilitate the modification of document content.

  • The fixed layout conversion mode has a faster conversion speed and is conducive to the maximum preservation of the original appearance of PDF files. However, since each line of PDF text will be presented in a separate frame in the generated Word documents, the editability of the generated documents will be limited.
  • The flowable structure conversion mode is a full recognition mode. The converted content is not rendered in frames and the resulting document structure is flowable, meaning that the resulting Word document is easy to re-edit but may look different from the original PDF file.

This article is going to demonstrate how to use Spire.PDF for C++ to convert PDFs to Word documents in fixed layout mode or flowable structure mode.

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 PDFs to Doc/Docx Files in Fixed Layout

By default, when PdfDocument->SaveToFile() method is used to convert a PDF file to a Word document without setting the conversion options, the content arrangement of the output Word document will be in fixed layout. The detailed steps for converting a PDF file to a Word document in fixed layout mode are as follows.

  • Create an object of PdfDocument.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Save the PDF file as a Doc and a Docx file using PdfDocument->SaveToFile() method.
  • C++
#include "Spire.Pdf.o.h"

using namespace Spire::Pdf;

int main()
{
    //Create an Object of PdfDocument
    PdfDocument* pdf = new PdfDocument();

    //Load a PDF file
    pdf->LoadFromFile(L"C:/The Space Between Us.pdf");

    //Save the document as a Doc file
    pdf->SaveToFile(L"Output/PDFToWord.doc", FileFormat::DOC);

    //Save the document as a Docx file
    pdf->SaveToFile(L"Output/PDFToWord.docx", FileFormat::DOCX);
    pdf->Close();
    delete pdf;
}

C++: Convert PDF to Word

Convert PDFs to Doc/Docx Files in Flowable Structure

Spire.PDF for C++ provides the PdfDocument->GetConvertOptions()->SetPdfToDocOptions(true, true) method to change the conversion mode to flowable structure mode. The detailed steps for converting a PDF file To a Word document in flowable structure mode are as follows.

  • Create an object of PdfDocument.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Change the conversion mode to flowable structure mode using PdfDocument->GetConvertOptions()->SetPdfToDocOptions(true, true) method.
  • Save the PDF file as a Doc and a Docx file using PdfDocument->SaveToFile() method.
  • C++
#include "Spire.Pdf.o.h"

using namespace Spire::Pdf;

int main()
{
    //Create an Object of PdfDocument
    PdfDocument* pdf = new PdfDocument();

    //Load a PDF file
    pdf->LoadFromFile(L"C:/The Space Between Us.pdf");

    //Change the conversion mode to flowable structure mode
    pdf->GetConvertOptions()->SetPdfToDocOptions(true, true);

    //Save the document as a Doc file
    pdf->SaveToFile(L"Output/PDFToWord.doc", FileFormat::DOC);

    //Save the document as a Docx file
    pdf->SaveToFile(L"Output/PDFToWord.docx", FileFormat::DOCX);
    pdf->Close();
    delete pdf;
}

C++: Convert PDF to Word

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.

Published in Conversion
Tuesday, 14 March 2023 01:00

C++: Convert PDF to Images

The PDF file format is ideal for most occasions. But still, you may encounter situations where you need to convert PDF to images. Once you convert a certain PDF page into an image, you can post it on social media, upload or transfer it in devices that can only display images, or embed it in your Word document or PowerPoint presentation. In this article, you will learn how to programmatically convert PDF to images 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 Specific Page to an Image in C++

Spire.PDF for C++ offers the PdfDocument->SaveAsImage(int pageIndex) method to convert a particular page into image stream. The stream can be then saved as an image file with the desired extension like PNG, JPG, and BMP. The following are the detailed steps.

  • Create a PdfDocument instance.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Convert a specific page into image stream using PdfDocument->SaveAsImage() method.
  • Save the image steam as a JPG file using Stream->Save() method.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;
using namespace std;

int main() {

	//Specify input and output file paths
	wstring inputFile = L"C:\\Users\\Administrator\\Desktop\\sample.pdf";
	wstring outputFile = L"C:\\Users\\Administrator\\Desktop\\Output\\ToImage";

	//Create a PdfDocument object
	PdfDocument* doc = new PdfDocument();

	//Load a PDF file
	doc->LoadFromFile(inputFile.c_str());

	//Convert a specific page as image
	Stream* image = doc->SaveAsImage(0, PdfImageType::Bitmap);

	//Write image to a .jpg file
	wstring fileName = outputFile + L".jpg";
	image->Save(fileName.c_str());

	doc->Close();
	delete doc;
}

C++: Convert PDF to Images

Convert an Entire PDF to Multiple Images in C++

In order to save the whole PDF as separate individual images, you just need to put the conversion part inside a loop statement. The follows are the detailed steps.

  • Create a PdfDocument instance.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Loop through the pages in the document and convert each of them into image stream using PdfDocument->SaveAsImage(int pageIndex) method.
  • Save the image steam as JPG files using Stream->Save() method.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;
using namespace std;

int main() {

	//Specify input and output file paths
	wstring inputFile = L"C:\\Users\\Administrator\\Desktop\\sample.pdf";
	wstring outputFile = L"C:\\Users\\Administrator\\Desktop\\Output\\ToImg-";

	//Create a PdfDocument object
	PdfDocument* doc = new PdfDocument();

	//Load a PDF file
	doc->LoadFromFile(inputFile.c_str());

	//Iterate through the pages in the document
	for (int i = 0; i < doc->GetPages()->GetCount(); i++) {

		//Save a specific page as image
		Stream* image = doc->SaveAsImage(i);

		//Write image to a .jpg file
		wstring fileName = outputFile + to_wstring(i) + L".jpg";
		image->Save(fileName.c_str());
	}
	doc->Close();
	delete doc;
}

C++: Convert PDF to Images

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.

Published in Conversion

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details