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

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

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.
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;
}

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

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.
When you need to share or present your PowerPoint presentations on different computers/devices, you may occasionally find that some content cannot be displayed properly. To avoid such incompatibility issues, a common method is to convert your PowerPoint document to PDF to ensure document integrity. In this article, you will learn how to convert a PowerPoint Presentation to PDF in C++ using Spire.Presentation for C++.
- Convert an Entire PowerPoint Presentation to PDF in C++
- Convert a Specific PowerPoint Slide to PDF in C++
- Convert a PowerPoint to PDF with Specific Page Size in C++
Install Spire.Presentation for C++
There are two ways to integrate Spire.Presentation 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.Presentation for C++ in a C++ Application
Convert an Entire PowerPoint Presentation to PDF in C++
The Presentation->SaveToFile(LPCWSTR_S fileName, FileFormat::PDF) method allows you to convert each slide in PowerPoint to a PDF page. The following are the steps to convert a whole PowerPoint presentation to PDF.
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Save it to PDF using Presentation->SaveToFile(LPCWSTR_S fileName, FileFormat::PDF) method.
- C++
#include "Spire.Presentation.o.h"
using namespace std;
using namespace Spire::Presentation;
int main()
{
//Specify the input and output file paths
std::wstring inputFile = L"Data\\sample.pptx";
std::wstring outputFile = L"Output\\PowerPointToPDF.pdf";
//Create a Presentation object
Presentation* ppt = new Presentation();
//Load a PowerPoint document from disk
ppt->LoadFromFile(inputFile.c_str());
//Save the document to PDF
ppt->SaveToFile(outputFile.c_str(), FileFormat::PDF);
delete ppt;
}

Convert a Specific PowerPoint Slide to PDF in C++
If you only want to convert a particular slide to PDF, you can use the ISlide->SaveToFile(LPCWSTR_S fileName, FileFormat::PDF) method provided by Spire.Presentation for C++. The following are the detailed steps.
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Get a specified slide by index using Presentation->GetSlides()->GetItem(slideIndex) method.
- Save the slide to PDF using ISlide->SaveToFile(LPCWSTR_S fileName, FileFormat::PDF) method.
- C++
#include "Spire.Presentation.o.h"
using namespace std;
using namespace Spire::Presentation;
int main()
{
//Specify the input and output file paths
std::wstring inputFile = L"Data\\sample.pptx";
std::wstring outputFile = L"Output\\SlideToPDF.pdf";
//Create a Presentation object
Presentation* ppt = new Presentation();
//Load a PowerPoint document from disk
ppt->LoadFromFile(inputFile.c_str());
//Get the second slide
ISlide* slide = ppt->GetSlides()->GetItem(1);
//Save the second slide to PDF
slide->SaveToFile(outputFile.c_str(), FileFormat::PDF);
delete ppt;
}

Convert a PowerPoint to PDF with Specific Page Size in C++
Spire.Presentation for C++ also allows you to set a desired slide size and orientation for a PowerPoint document before converting it to PDF. The following are the steps to convert a PowerPoint to PDF with Specific Page Size (A4 slide size = 10.83x7.05 inch).
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Set the slide size of the PowerPoint document using Presentation->GetSlideSize()->SetType() method.
- Set the slide orientation of the PowerPoint document using Presentation->GetSlideSize()->SetOrientation() method.
- Save the document to PDF using Presentation->SaveToFile(LPCWSTR_S fileName, FileFormat::PDF) method.
- C++
#include "Spire.Presentation.o.h"
using namespace std;
using namespace Spire::Presentation;
int main()
{
//Specify the input and output file paths
std::wstring inputFile = L"Data\\sample.pptx";
std::wstring outputFile = L"Output\\ToPdfWithSpecificPageSize.pdf";
//Create a Presentation object
Presentation* ppt = new Presentation();
//Load a PowerPoint document from disk
ppt->LoadFromFile(inputFile.c_str());
//Set the slide size to A4
ppt->GetSlideSize()->SetType(SlideSizeType::A4);
//Set the slide orientation to Landscape
ppt->GetSlideSize()->SetOrientation(SlideOrienation::Landscape);
//Save the document to PDF
ppt->SaveToFile(outputFile.c_str(), FileFormat::PDF);
delete ppt;
}

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.