Convert multi-page PDF to multi-page TIFF
Posted: 2016-12-21T08:45:37-07:00
Hello, I'm trying to convert a multi-page PDF to a multi-page TIFF.
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:
Example multi-page PDF: https://www.dropbox.com/s/l6jzdqre9cjxe ... e.pdf?dl=1
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.
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.