Hey everyone,

I was updating my PoDoFo library and ran into some issues with the changes involving immutable dictionaries. When doing PdfDocument::Append, AssertMutable fails in PdfDictionary::AddKey. I'm attaching example code which fails for me (it merges multiple PDFs into a single PDF; if you run it without arguments it will describe the arguments it expects). Hopefully someone will have some insight on how and why this dictionary was set immutable; I think the code which sets it immutable is invoked in PdfImmediateWriter::WriteObject, but I'm not totally certain.

Thanks,
Mike Slegeir
//============================================================================
// Name        : PoDoFo-merge.cpp
// Author      : Mike Slegeir
// Version     :
// Copyright   : LLM Inc
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <podofo/podofo.h>

#include <pthread.h>

#include <iostream>
#include <vector>

struct merge_args {
	const char*  out;
	int          inc;
	const char** inv;
};

void* merge(void* _args) {
	merge_args* args = static_cast<merge_args*>(_args);
	if(args->inc <= 0) {
		std::cerr << "No files to merge." << std::endl;
		return 0;
	}
	std::cout << "Merging into " << args->out << std::endl;

	PoDoFo::PdfStreamedDocument doc(args->out);

	for(int i=0; i<args->inc; ++i) {
		doc.Append( PoDoFo::PdfMemDocument(args->inv[i]) );
	}

	doc.Close();

	return 0;
}

int main(int argc, const char* argv[]) {
	//PoDoFo::PdfError::EnableDebug( false );	// turn it off to better view the output from this app!
	PoDoFo::PdfError::EnableLogging( false );

	if(argc < 2) {
		std::cout << "Usage: merge num_docs [out1.pdf ...] [num_input1 [in1_1.pdf ...]]" << std::endl;
		return 1;
	}

	int num;
	{
		std::stringstream snum(argv[1]);
		snum >> num;
	}

	const char** outv = argv + 2, ** inp = outv + num;
	std::vector<merge_args> thread_args(num);
	std::vector<pthread_t> threads(num);
	for(int i=0; i<num; ++i){
		int num_in;
		{
			std::stringstream snum(*(inp++));
			snum >> num_in;
		}
		thread_args[i].out = *(outv++);
		thread_args[i].inc = num_in;
		thread_args[i].inv = inp;
		inp += num_in;

		pthread_create(&threads[i], 0, merge, &thread_args[i]);
	}

	for(int i=0; i<num; ++i){
		pthread_join(threads[i], 0);
	}

	return 0;
}
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to