@@ -49,32 +49,48 @@ public function convertFile($source, $destination) {
49
49
$ this ->cmd ,
50
50
$ source ,
51
51
'dump_data ' ,
52
- Shell::arg ('| ' , Shell::SHELL_SAFE ),
52
+ Shell::arg ('2>&1 | ' , Shell::SHELL_SAFE ),
53
53
Shell::arg ("sed 's/Value: .*/Value:/' > " , Shell::SHELL_SAFE ),
54
54
$ empty ,
55
55
));
56
56
57
- // pdftk source.pdf update_info empty.txt output destination.pdf flatten compress
58
- $ cmd = array (
59
- $ this ->cmd ,
60
- $ source ,
61
- 'update_info ' ,
62
- $ empty ,
63
- 'output ' ,
64
- '- ' ,
65
- 'flatten ' ,
66
- ($ remove_meta ? 'uncompress ' : 'compress ' ),
67
- );
68
- if (isset ($ this ->configuration ['remove-id ' ])
69
- && $ this ->configuration ['remove-id ' ]) {
70
- // /ID [<e8c87bb7a19df73c042da3b2a01dc7ff> <e8c87bb7a19df73c042da3b2a01dc7ff>]
71
- $ cmd [] = Shell::arg (" | grep -va '^ \\/ID \\[' " , Shell::SHELL_SAFE );
57
+ // Determine whether InfoKey exists.
58
+ $ infoKey = preg_match ("@(?:^| \n)InfoKey:@s " , file_get_contents ($ empty ));
59
+ if ($ infoKey || $ remove_meta ) {
60
+ // pdftk source.pdf update_info empty.txt output destination.pdf flatten compress
61
+ $ cmd = array (
62
+ $ this ->cmd ,
63
+ $ source ,
64
+ 'update_info ' ,
65
+ $ empty ,
66
+ 'output ' ,
67
+ '- ' ,
68
+ 'flatten ' ,
69
+ ($ remove_meta ? 'uncompress ' : 'compress ' ),
70
+ );
71
+ if (isset ($ this ->configuration ['remove-id ' ])
72
+ && $ this ->configuration ['remove-id ' ]) {
73
+ // /ID [<e8c87bb7a19df73c042da3b2a01dc7ff> <e8c87bb7a19df73c042da3b2a01dc7ff>]
74
+ $ cmd [] = Shell::arg (" | grep -va '^ \\/ID \\[' " , Shell::SHELL_SAFE );
75
+ }
76
+ $ cmd [] = Shell::arg ('> ' , Shell::SHELL_SAFE );
77
+ $ cmd [] = $ cleaned ;
78
+ $ this ->shell ($ cmd );
79
+ }
80
+ else {
81
+ $ cleaned = $ source ;
72
82
}
73
- $ cmd [] = Shell::arg ('> ' , Shell::SHELL_SAFE );
74
- $ cmd [] = $ cleaned ;
75
- $ this ->shell ($ cmd );
76
83
77
84
// Clean up and finalize files.
85
+ if (function_exists ('drush_get_context ' )
86
+ && drush_get_context ('DRUSH_VERBOSE ' )) {
87
+ drush_print (dt ('PDFTK InfoKey: !bool ' , array (
88
+ '!bool ' => var_export ($ infoKey , 1 ),
89
+ )));
90
+ drush_print (dt ('PDFTK remove_meta: !bool ' , array (
91
+ '!bool ' => var_export ($ remove_meta , 1 ),
92
+ )));
93
+ }
78
94
if ($ remove_meta ) {
79
95
$ temp = $ this ->getTempFile ('pdf ' );
80
96
$ fp = fopen ($ cleaned , 'r ' );
0 commit comments