Package: pdftk
Version: 1.41-3
Severity: wishlist

It would be nice if pdftk would allow to overlay different pages at the
same time, like a stamp but not limited to only one page.

Attached patch for example adds an multistamp command, so that different
pages are stamped with different pages. This is for example very nice
to add page numbers or other "corrections" on top of an existing
document. (getting the different pages out and stamping those and
concatenating everything back is both more complex and generates much
bigger files).

Hochachtungsvoll,
        Bernhard R. Link
diff -r -u pdftk-1.41.old/pdftk/pdftk.cc pdftk-1.41/pdftk/pdftk.cc
--- pdftk-1.41.old/pdftk/pdftk.cc	2006-11-28 23:51:36.000000000 +0100
+++ pdftk-1.41/pdftk/pdftk.cc	2009-01-10 16:46:50.000000000 +0100
@@ -392,6 +392,12 @@
 		// (and preserving old behavior for backwards compatibility)
 		return background_k;
 	}
+	else if( strcmp( ss_copy, "multibackground" )== 0 ) {
+		return multibackground_k;
+	}
+	else if( strcmp( ss_copy, "multistamp" )== 0 ) {
+		return multistamp_k;
+	}
 	else if( strcmp( ss_copy, "stamp" )== 0 ) {
 		return stamp_k;
 	}
@@ -945,10 +951,20 @@
 				m_operation= filter_k;
 				arg_state= background_filename_e;
 			}
+			else if( arg_keyword== multibackground_k ) {
+				m_operation= filter_k;
+				m_multibackground_b = true;
+				arg_state= background_filename_e;
+			}
 			else if( arg_keyword== stamp_k ) {
 				m_operation= filter_k;
 				arg_state= stamp_filename_e;
 			}
+			else if( arg_keyword== multistamp_k ) {
+				m_operation= filter_k;
+				m_multistamp_b = true;
+				arg_state= stamp_filename_e;
+			}
 			else if( arg_keyword== output_k ) { // we reached the output section
 				arg_state= output_filename_e;
 			}
@@ -2285,10 +2301,12 @@
 
 				// try opening the PDF background or stamp before we get too involved
 				itext::PdfReader* mark_p= 0;
+				bool mark_per_page_b = false;
 				bool background_b= true; // set false for stamp
 				com::lowagie::text::pdf::PdfImportedPage* mark_page_p= 0;
 				//
 				if( !m_background_filename.empty() ) {
+					mark_per_page_b = m_multibackground_b;
 					if( m_background_filename== "PROMPT" ) {
 						prompt_for_filename( "Please enter a filename for the background PDF:", 
 																 m_background_filename );
@@ -2306,6 +2324,7 @@
 					}
 				}
 				else if( !m_stamp_filename.empty() ) { // stamp
+					mark_per_page_b = m_multistamp_b;
 					background_b= false;
 					if( m_stamp_filename== "PROMPT" ) {
 						prompt_for_filename( "Please enter a filename for the stamp PDF:", 
@@ -2470,15 +2489,19 @@
 
 					// create a PdfTemplate from the first page of mark
 					// (PdfImportedPage is derived from PdfTemplate)
-					com::lowagie::text::pdf::PdfImportedPage* mark_page_p=
-						writer_p->getImportedPage( mark_p, 1 );
+					com::lowagie::text::pdf::PdfImportedPage* mark_page_p;
+					if( !mark_per_page_b )
+						mark_page_p = writer_p->getImportedPage( mark_p, 1 );
 
           // iterate over document's pages, adding mark_page as
           // a layer 'underneath' the page content; scale mark_page
           // and move it so it fits within the document's page;
 					jint num_pages= input_reader_p->getNumberOfPages();
+					jint mark_num_pages= mark_p->getNumberOfPages();
 					for( jint ii= 0; ii< num_pages; ) {
 						++ii;
+						if( mark_per_page_b && ( ii == 1 || ii <= mark_num_pages ) )
+							mark_page_p = writer_p->getImportedPage( mark_p, ii );
 						com::lowagie::text::Rectangle* doc_page_size_p= 
 							input_reader_p->getCropBox( ii );
 						jint doc_page_rotation= input_reader_p->getPageRotation( ii );
diff -r -u pdftk-1.41.old/pdftk/pdftk.h pdftk-1.41/pdftk/pdftk.h
--- pdftk-1.41.old/pdftk/pdftk.h	2006-09-14 23:07:06.000000000 +0200
+++ pdftk-1.41/pdftk/pdftk.h	2009-01-10 16:39:55.000000000 +0100
@@ -83,7 +83,9 @@
 		update_info_k,
 		update_xmp_k,
 		background_k, // promoted from output option to operation in pdftk 1.10
+		multibackground_k,
 		stamp_k,
+		multistamp_k,
 
 		// optional attach_file argument
 		attach_file_to_page_k,
@@ -161,6 +163,8 @@
 	string m_output_owner_pw;
 	string m_output_user_pw;
 	jint m_output_user_perms;
+	bool m_multistamp_b;
+	bool m_multibackground_b;
 	bool m_output_uncompress_b;
 	bool m_output_compress_b;
 	bool m_output_flatten_b;

Reply via email to