Re: [Podofo-users] Few improvements for podofoimpose

2021-01-24 Thread podofo

Hi Dominik,

Very good. Thank you very much for committing the code.

I'll be testing podofoimpose a bit more on a large set of different 
PDFs. Maybe I'll find some other things :)


Best regards,
Chris

On 1/24/21 12:35 PM, Dominik Seichter wrote:

Hi Chris,

Thank you very much for your valuable contribution. I committed all 
four patches to SVN.


Kindest regards,
Dominik


On Fri, Jan 22, 2021 at 5:56 PM > wrote:


Hi,

Thanks for such a great tool (PoDoFo in general).

I made a few improvements to the podofoimpose tool. Hope they are
useful
to others as well. Here a short explanation for each patch.

- 1_Allow_to_set_the_bounding_box_with_the_legacy_plan_reader.patch
Also allow to set the bounding box with the legacy plan reader.

- 2_Return_none_zero_return_code.patch
If an exception happens, return none zero return code.

- 3_Allow_scaling_of_inserted_pages.patch
This is the biggest change. With this change it is possible to
scale an
inserted page (one by one with different scaling). I tried to make
sure,
that all additional parameters are optional and the previous
behavior is
retained if no scaling factors are given.

- 4_Handle_Name_datatype_correctly.patch
Handle the Name datatype correctly. Without this fix the Name
datatype
got converted to a dictionary after imposing the PDF. This
resulted in
having an invalid /ColorSpace for images and thus images that did not
show up in the resulting PDF.

I tested and applied all patches against the trunk.

Best regards,
Chris
___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/podofo-users



___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users


Re: [Podofo-users] Few improvements for podofoimpose

2021-01-24 Thread Dominik Seichter via Podofo-users
Hi Chris,

Thank you very much for your valuable contribution. I committed all four
patches to SVN.

Kindest regards,
Dominik


On Fri, Jan 22, 2021 at 5:56 PM  wrote:

> Hi,
>
> Thanks for such a great tool (PoDoFo in general).
>
> I made a few improvements to the podofoimpose tool. Hope they are useful
> to others as well. Here a short explanation for each patch.
>
> - 1_Allow_to_set_the_bounding_box_with_the_legacy_plan_reader.patch
> Also allow to set the bounding box with the legacy plan reader.
>
> - 2_Return_none_zero_return_code.patch
> If an exception happens, return none zero return code.
>
> - 3_Allow_scaling_of_inserted_pages.patch
> This is the biggest change. With this change it is possible to scale an
> inserted page (one by one with different scaling). I tried to make sure,
> that all additional parameters are optional and the previous behavior is
> retained if no scaling factors are given.
>
> - 4_Handle_Name_datatype_correctly.patch
> Handle the Name datatype correctly. Without this fix the Name datatype
> got converted to a dictionary after imposing the PDF. This resulted in
> having an invalid /ColorSpace for images and thus images that did not
> show up in the resulting PDF.
>
> I tested and applied all patches against the trunk.
>
> Best regards,
> Chris
> ___
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
___
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users


[Podofo-users] Few improvements for podofoimpose

2021-01-22 Thread podofo

Hi,

Thanks for such a great tool (PoDoFo in general).

I made a few improvements to the podofoimpose tool. Hope they are useful 
to others as well. Here a short explanation for each patch.


- 1_Allow_to_set_the_bounding_box_with_the_legacy_plan_reader.patch
Also allow to set the bounding box with the legacy plan reader.

- 2_Return_none_zero_return_code.patch
If an exception happens, return none zero return code.

- 3_Allow_scaling_of_inserted_pages.patch
This is the biggest change. With this change it is possible to scale an 
inserted page (one by one with different scaling). I tried to make sure, 
that all additional parameters are optional and the previous behavior is 
retained if no scaling factors are given.


- 4_Handle_Name_datatype_correctly.patch
Handle the Name datatype correctly. Without this fix the Name datatype 
got converted to a dictionary after imposing the PDF. This resulted in 
having an invalid /ColorSpace for images and thus images that did not 
show up in the resulting PDF.


I tested and applied all patches against the trunk.

Best regards,
Chris
diff --git a/podofo/trunk/tools/podofoimpose/planreader_legacy.cpp b/podofo/trunk/tools/podofoimpose/planreader_legacy.cpp
index 2aa1b91fa..23d0f052c 100644
--- a/podofo/trunk/tools/podofoimpose/planreader_legacy.cpp
+++ b/podofo/trunk/tools/podofoimpose/planreader_legacy.cpp
@@ -268,6 +268,8 @@ PlanReader_Legacy::PlanReader_Legacy(const std::string & plan, PoDoFo::Impose::I
 	/// SUPPORTED
 	if ( I->vars.find("$ScaleFactor") != I->vars.end() )
 		I->setScale( PoDoFo::Impose::PageRecord::calc( I->vars["$ScaleFactor"] , I->vars));
+	if ( I->vars.find("$BoundingBox") != I->vars.end() )
+		I->setBoundingBox(I->vars["$BoundingBox"]);
 	/// END OF SUPPORTED
 	
 	
diff --git a/podofo/trunk/tools/podofoimpose/podofoimpose.cpp b/podofo/trunk/tools/podofoimpose/podofoimpose.cpp
index 6053f1c96..1d41b5a12 100644
--- a/podofo/trunk/tools/podofoimpose/podofoimpose.cpp
+++ b/podofo/trunk/tools/podofoimpose/podofoimpose.cpp
@@ -119,6 +119,7 @@ int main ( int argc, char *argv[] )
 	catch ( std::exception & e )
 	{
 		cerr << e.what() << endl;
+		return 4;
 	}
 
 	return 0;
diff --git a/podofo/trunk/tools/podofoimpose/impositionplan.cpp b/podofo/trunk/tools/podofoimpose/impositionplan.cpp
index 4d07970b9..71253455f 100644
--- a/podofo/trunk/tools/podofoimpose/impositionplan.cpp
+++ b/podofo/trunk/tools/podofoimpose/impositionplan.cpp
@@ -42,12 +42,14 @@ using std::runtime_error;
 
 #include  //XXX
 namespace PoDoFo { namespace Impose {
-PageRecord::PageRecord ( int s,int d,double r, double tx, double ty, int du )
+PageRecord::PageRecord ( int s,int d,double r, double tx, double ty, int du, double sx, double sy )
 		: sourcePage ( s ),
 		destPage ( d ),
 		rotate ( r ),
 		transX ( tx ),
 		transY ( ty ),
+		scaleX ( sx ),
+		scaleY ( sy ),
 		duplicateOf( du )
 {
 };
@@ -58,6 +60,8 @@ PageRecord::PageRecord ( )
 		rotate ( 0 ),
 		transX ( 0 ),
 		transY ( 0 ),
+		scaleX ( 1 ),
+		scaleY ( 1 ),
 		duplicateOf( 0 )
 {};
 
@@ -80,7 +84,7 @@ void PageRecord::load ( const std::string& buffer, const std::map m0 = transformMatrix;
+std::vector m;
+
+m.push_back(m0.at(0)*a + m0.at(1)*c);
+m.push_back(m0.at(0)*b + m0.at(1)*d);
+m.push_back(m0.at(2)*a + m0.at(3)*c);
+m.push_back(m0.at(2)*b + m0.at(3)*d);
+
+m.push_back(m0.at(4)*a + m0.at(5)*c + e);
+m.push_back(m0.at(4)*b + m0.at(5)*d + f);
+
+transformMatrix = m;
+			}
+		}
+
+		void PdfTranslator::rotate_and_translate(double theta, double dx, double dy)
+		{
+			double cosR = cos ( theta * 3.14159 / 180.0 );
+			double sinR = sin ( theta * 3.14159 / 180.0 );
+			transform(cosR, sinR, -sinR, cosR, dx, dy);
+		}
+
+		void PdfTranslator::translate(double dx, double dy)
+		{
+			transform(1, 0, 0, 1, dx, dy);
+		}
+
+		void PdfTranslator::scale(double sx, double sy)
+		{
+			transform(sx, 0, 0, sy, 0, 0);
+		}
+
+		void PdfTranslator::rotate(double theta)
+		{
+			double cosR = cos ( theta  *  3.14159 / 180.0 );
+			double sinR = sin ( theta  *  3.14159 / 180.0 );
+			// Counter-clockwise rotation (default):
+			transform(cosR, sinR, -sinR, cosR, 0, 0);
+			// Clockwise rotation:
+			// transform(cosR, -sinR, sinR, cosR, 0, 0);
+		}
+
 		void PdfTranslator::loadPlan ( const std::string & planFile , PoDoFo::Impose::PlanReader loader )
 		{
 // 			std::cerr<< "loadPlan" << planFile< 0) ? curRecord.duplicateOf : */curRecord.sourcePage );
 		PdfXObject *xo = xobjects[resourceIndex];
@@ -563,9 +617,18 @@ namespace PoDoFo
 std::cerr<<"ERROR Unknown type resource "