It works fine when using a single page PDF, but when trying to convert multi-page PDFs only the first page gets converted.
My C++ Code:
Code: Select all
#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "boost/program_options.hpp"
#include "Magick++.h"
#include <boost/filesystem/convenience.hpp>
#include <boost/format.hpp>
using namespace Magick;
int main(int argc, char* argv[])
{
namespace po = boost::program_options;
po::options_description desc("Optionen");
desc.add_options()
("help,h", "Help")
("inf", po::value<std::string>(), "Eingabedatei")
("outf", po::value<std::string>(), "Ausgabedatei")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << "\n";
return 1;
}
if (!vm.count("inf") && !vm.count("outf")) {
std::cout << "Ein- und Ausgabedatei müssen gesetzt sein.";
}
//Parameter passen, kann verarbeitet werden
std::string infilePath = vm["inf"].as<std::string>();
std::string outfilePath = vm["outf"].as<std::string>();
//Datei existiert nicht
if (!std::ifstream(infilePath))
{
std::cout << "ERROR: Infile existiert nicht.";
return 1;
}
Image infile;
std::string outfileBasename = outfilePath;
try {
outfileBasename = boost::filesystem::change_extension(outfilePath, "").string();
}
catch (Exception &e) {
std::cout << "keine Extension angegeben\n";
}
try {
infile.density(200);
infile.read(infilePath);
char* extPath = new char[128];
sprintf_s(extPath, 128, "%s_0%%04d.tif", outfileBasename.c_str());
infile.write(extPath);
delete[] extPath;
}
catch (Exception &e) {
std::cout << "Exception: \n";
std::cout << e.what();
return 1;
}
return 0;
}
Example single-page PDF: https://www.dropbox.com/s/3sowi7698koek ... e.pdf?dl=1
I'm running W8.1 Enterprise x64, VS2013, Ghostscript 9.20 x32 and IM 7.0.4-0, both compiled from source.