aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2011-08-10 22:34:29 +0200
committerJay Berkenbilt <ejb@ql.org>2011-08-10 22:34:29 +0200
commit759c56e1fed2849b77bff18f2a50639876395e5e (patch)
treef8c899bf5fdfd4ef4f546addf16180d6c6694152 /libqpdf
parent655c55f84830190f9fa4777c615b8a622254648a (diff)
downloadqpdf-759c56e1fed2849b77bff18f2a50639876395e5e.tar.zst
implement ability to save PDF to memory, also update ChangeLog
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFWriter.cc121
1 files changed, 87 insertions, 34 deletions
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 40368f69..7217ded7 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -4,7 +4,6 @@
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/Pl_Count.hh>
#include <qpdf/Pl_Discard.hh>
-#include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_RC4.hh>
#include <qpdf/Pl_AES_PDF.hh>
#include <qpdf/Pl_Flate.hh>
@@ -21,32 +20,65 @@
#include <stdlib.h>
+QPDFWriter::QPDFWriter(QPDF& pdf) :
+ pdf(pdf)
+{
+ init();
+}
+
QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
- pdf(pdf),
- filename(filename),
- file(0),
- close_file(false),
- normalize_content_set(false),
- normalize_content(false),
- stream_data_mode_set(false),
- stream_data_mode(qpdf_s_compress),
- qdf_mode(false),
- static_id(false),
- suppress_original_object_ids(false),
- direct_stream_lengths(true),
- encrypted(false),
- preserve_encryption(true),
- linearized(false),
- object_stream_mode(qpdf_o_preserve),
- encrypt_metadata(true),
- encrypt_use_aes(false),
- encryption_dict_objid(0),
- next_objid(1),
- cur_stream_length_id(0),
- cur_stream_length(0),
- added_newline(false),
- max_ostream_index(0)
+ pdf(pdf)
+{
+ init();
+ setOutputFilename(filename);
+}
+
+void
+QPDFWriter::init()
+{
+ filename = 0;
+ file = 0;
+ close_file = false;
+ buffer_pipeline = 0;
+ output_buffer = 0;
+ normalize_content_set = false;
+ normalize_content = false;
+ stream_data_mode_set = false;
+ stream_data_mode = qpdf_s_compress;
+ qdf_mode = false;
+ static_id = false;
+ suppress_original_object_ids = false;
+ direct_stream_lengths = true;
+ encrypted = false;
+ preserve_encryption = true;
+ linearized = false;
+ object_stream_mode = qpdf_o_preserve;
+ encrypt_metadata = true;
+ encrypt_use_aes = false;
+ encryption_dict_objid = 0;
+ next_objid = 1;
+ cur_stream_length_id = 0;
+ cur_stream_length = 0;
+ added_newline = false;
+ max_ostream_index = 0;
+}
+
+QPDFWriter::~QPDFWriter()
+{
+ if (file && close_file)
+ {
+ fclose(file);
+ }
+ if (output_buffer)
+ {
+ delete output_buffer;
+ }
+}
+
+void
+QPDFWriter::setOutputFilename(char const* filename)
{
+ this->filename = filename;
if (filename == 0)
{
this->filename = "standard output";
@@ -61,19 +93,25 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
fopen(filename, "wb+"));
close_file = true;
}
- Pipeline* p = new Pl_StdioFile("qdf output", file);
+ Pipeline* p = new Pl_StdioFile("qpdf output", file);
to_delete.push_back(p);
- pipeline = new Pl_Count("qdf count", p);
- to_delete.push_back(pipeline);
- pipeline_stack.push_back(pipeline);
+ initializePipelineStack(p);
}
-QPDFWriter::~QPDFWriter()
+void
+QPDFWriter::setOutputMemory()
{
- if (file && close_file)
- {
- fclose(file);
- }
+ this->buffer_pipeline = new Pl_Buffer("qpdf output");
+ to_delete.push_back(this->buffer_pipeline);
+ initializePipelineStack(this->buffer_pipeline);
+}
+
+Buffer*
+QPDFWriter::getBuffer()
+{
+ Buffer* result = this->output_buffer;
+ this->output_buffer = 0;
+ return result;
}
void
@@ -566,6 +604,14 @@ QPDFWriter::pushPipeline(Pipeline* p)
}
void
+QPDFWriter::initializePipelineStack(Pipeline *p)
+{
+ this->pipeline = new Pl_Count("qpdf count", p);
+ to_delete.push_back(this->pipeline);
+ this->pipeline_stack.push_back(this->pipeline);
+}
+
+void
QPDFWriter::activatePipelineStack()
{
Pl_Count* c = new Pl_Count("count", this->pipeline_stack.back());
@@ -1503,6 +1549,8 @@ QPDFWriter::generateObjectStreams()
void
QPDFWriter::write()
{
+ // XXX Check output
+
// Do preliminary setup
if (this->linearized)
@@ -1656,6 +1704,11 @@ QPDFWriter::write()
fclose(this->file);
}
this->file = 0;
+ if (this->buffer_pipeline)
+ {
+ this->output_buffer = this->buffer_pipeline->getBuffer();
+ this->buffer_pipeline = 0;
+ }
}
void