What's the simplest way to migrate from DocPub to PDFNet?

Q:

I’ve been developing a proof-of-concept project using DocPub. But after going to through the licensing process, it seems that PDFNet would be a better fit for us. But now I need to go back and change all of my code to use PDFNet instead of DocPub. What’s the easiest/quickest way to get that done?

A:

The easiest way to rewrite your code using DocPub is to create a simple command-line program that only performs your specific conversions.

If you download PDFNet SDK, then on every platform you can compile the Samples/WebViewerConvertTest project out of the box. On OS X and Linux, you simply need to go into Samples/WebViewerConvertTest/CPP and run “make” at the command line. Then WebViewerConvertTest will be runnable at the command line just like DocPub.

So that you can pass file paths into this command-line, please replace the content of WebViewerConvertTest.cpp with the following (then run make again):

`
#include
#include
#include <PDF/PDFNet.h>
#include <PDF/Convert.h>

using namespace pdftron;
using namespace PDF;
using namespace std;

int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cout << “Syntax: WebViewerConvertTest input.pdf output.xod” << std::endl;
return 2;
}

int err = 0;
try
{
const char* szInput = argv[1];
const char* szOutput = argv[2];

PDFNet::Initialize();
// https://www.pdftron.com/pdfnet/docs/PDFNetC/d0/d30/classpdftron_1_1_p_d_f_1_1_convert_1_1_x_o_d_output_options.html
// https://www.pdftron.com/pdfnet/docs/PDFNetC/d3/d99/classpdftron_1_1_p_d_f_1_1_convert_1_1_x_p_s_output_common_options.html
Convert::XODOutputOptions xod_options;
//xod_options.SetPreferJPG(true);
//xod_options.SetDPI(200);
Convert::ToXod(szInput, szOutput, xod_options);
}
catch(Common::Exception& e)
{
std::cout << e << std::endl;
err = 1;
}
catch(std::exception& e)
{
std::cout << e.what() << std::endl;
err = 1;
}
catch(…)
{
std::cout << “Unknown Exception” << std::endl;
err = 1;
}

std::cout << “Done.\n”;
return err;
}

`

Once you have a PDFNet license, you can pass it in as a string into PDFNet::Initialize().

Note that you can change this code sample, perhaps taking code from the samples at https://www.pdftron.com/pdfnet/samplecode.html. For example, you can use a few lines from the sample at https://www.pdftron.com/pdfnet/samplecode.html#Word2PDF to change the code sample to convert DOC/DOCX/PPTX documents to PDF:

`
#include
#include
#include <PDF/PDFNet.h>
#include <PDF/Convert.h>

using namespace pdftron;
using namespace PDF;
using namespace std;

int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cout << “Syntax: WebViewerConvertTest input.pdf output.xod” << std::endl;
return 2;
}

int err = 0;
try
{
const char* szInput = argv[1];
const char* szOutput = argv[2];

PDFNet::Initialize();
PDFDoc pdfdoc;
Convert::WordToPDF(pdfdoc, szInput, NULL);
pdfdoc.Save(szOutput, SDF::SDFDoc::e_linearized, NULL);
}
catch (Common::Exception& e)
{
std::cout << e << std::endl;
err = 1;
}
catch (std::exception& e)
{
std::cout << e << std::endl;
err = 1;
}
catch (…)
{
std::cout << “Unknown Exception” << std::endl;
err = 1;
}

std::cout << “Done.\n”;
return err;
}

`