From 8705e2e8fc1a9721b2438c09ba7e92ec673af19d Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 5 Jul 2012 21:22:27 -0400 Subject: Add QPDFWriter method to output to FILE* --- libqpdf/QPDFWriter.cc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 564133e3..a7c78b19 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -34,6 +34,14 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) : setOutputFilename(filename); } +QPDFWriter::QPDFWriter(QPDF& pdf, char const* description, + FILE *file, bool close_file) : + pdf(pdf) +{ + init(); + setOutputFile(description, file, close_file); +} + void QPDFWriter::init() { @@ -79,21 +87,31 @@ QPDFWriter::~QPDFWriter() void QPDFWriter::setOutputFilename(char const* filename) { - this->filename = filename; + char const* description = filename; + FILE* f = 0; if (filename == 0) { - this->filename = "standard output"; + description = "standard output"; QTC::TC("qpdf", "QPDFWriter write to stdout"); - file = stdout; + f = stdout; QUtil::binary_stdout(); } else { QTC::TC("qpdf", "QPDFWriter write to file"); - file = QUtil::fopen_wrapper(std::string("open ") + filename, - fopen(filename, "wb+")); + f = QUtil::fopen_wrapper(std::string("open ") + filename, + fopen(filename, "wb+")); close_file = true; } + setOutputFile(description, f, close_file); +} + +void +QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file) +{ + this->filename = description; + this->file = file; + this->close_file = close_file; Pipeline* p = new Pl_StdioFile("qpdf output", file); to_delete.push_back(p); initializePipelineStack(p); -- cgit v1.2.3-70-g09d2