1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: wrapper_gpl.cxx,v $
9 * last change: $Author: cmc $ $Date: 2008/08/25 16:17:55 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU General Public License Version 2.
15 * GNU General Public License, version 2
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public
31 * License along with this program; if not, write to the Free
32 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 * Boston, MA 02110-1301, USA.
35 ************************************************************************/
37 #include "pdfioutdev_gpl.hxx"
38 //#include "SecurityHandler.h"
41 # include <fcntl.h> /*_O_BINARY*/
44 FILE* g_binary_out
=stderr
;
46 #ifndef SYSTEM_POPPLER
47 static char ownerPassword
[33] = "\001";
48 static char userPassword
[33] = "\001";
49 static char outputFile
[256] = "\001";
51 static ArgDesc argDesc
[] = {
52 {(char*)"-f", argString
, outputFile
, sizeof(outputFile
),
53 (char*)"output file for binary streams"},
54 {(char*)"-opw", argString
, ownerPassword
, sizeof(ownerPassword
),
55 (char*)"owner password (for encrypted files)"},
56 {(char*)"-upw", argString
, userPassword
, sizeof(userPassword
),
57 (char*)"user password (for encrypted files)"},
58 {NULL
, argString
, NULL
, 0, NULL
}
61 static const char *ownerPassword
= "\001";
62 static const char *userPassword
= "\001";
63 static const char *outputFile
= "\001";
66 int main(int argc
, char **argv
)
68 #ifndef SYSTEM_POPPLER
69 // parse args; initialize to defaults
70 if( !parseArgs(argDesc
, &argc
, argv
) )
76 if (!strcmp(argv
[k
], "-f"))
78 outputFile
= argv
[k
+1];
80 for (int j
= k
; j
< argc
; ++j
)
83 else if (!strcmp(argv
[k
], "-opw"))
85 ownerPassword
= argv
[k
+1];
87 for (int j
= k
; j
< argc
; ++j
)
90 else if (!strcmp(argv
[k
], "-upw"))
92 userPassword
= argv
[k
+1];
94 for (int j
= k
; j
< argc
; ++j
)
105 globalParams
= new GlobalParams(
106 #ifndef SYSTEM_POPPLER
110 globalParams
->setErrQuiet(gTrue
);
111 #if !defined(SYSTEM_POPPLER) || defined(_MSC_VER)
112 globalParams
->setupBaseFonts(NULL
);
115 // try to read a possible open password form stdin
118 if( ! fgets( aPwBuf
, sizeof(aPwBuf
)-1, stdin
) )
119 aPwBuf
[0] = 0; // mark as empty
122 for( unsigned int i
= 0; i
< sizeof(aPwBuf
); i
++ )
124 if( aPwBuf
[i
] == '\n' )
132 // PDFDoc takes over ownership for all strings below
133 GooString
* pFileName
= new GooString(argv
[1]);
134 GooString
* pTempErrFileName
= new GooString("_err.pdf");
135 GooString
* pTempErrFileNamePath
= new GooString(argv
[0]);
137 GooString
* pErrFileName
= new GooString(pTempErrFileNamePath
,pTempErrFileName
);
140 // check for password string(s)
141 GooString
* pOwnerPasswordStr( ownerPassword
[0] != '\001'
142 ? new GooString(ownerPassword
)
143 : (GooString
*)NULL
);
144 GooString
* pUserPasswordStr( aPwBuf
[0] != 0
145 ? new GooString( aPwBuf
)
146 : ( userPassword
[0] != '\001'
147 ? new GooString(userPassword
)
148 : (GooString
*)NULL
) );
149 if( outputFile
[0] != '\001' )
150 g_binary_out
= fopen(outputFile
,"wb");
153 // Win actually modifies output for O_TEXT file mode, so need to
154 // revert to binary here
155 _setmode( _fileno( g_binary_out
), _O_BINARY
);
158 PDFDoc
aDoc( pFileName
,
162 PDFDoc
aErrDoc( pErrFileName
,
167 // Check various permissions.
170 pdfi::PDFOutDev
* pOutDev( new pdfi::PDFOutDev(&aErrDoc
) );
172 const int nPages
= aErrDoc
.isOk() ? aErrDoc
.getNumPages() : 0;
174 // tell receiver early - needed for proper progress calculation
175 pOutDev
->setPageNum( nPages
);
177 // virtual resolution of the PDF OutputDev in dpi
178 static const int PDFI_OUTDEV_RESOLUTION
=7200;
181 for( int i
=1; i
<=nPages
; ++i
)
183 aErrDoc
.displayPage( pOutDev
,
185 PDFI_OUTDEV_RESOLUTION
,
186 PDFI_OUTDEV_RESOLUTION
,
187 0, gTrue
, gTrue
, gTrue
);
188 aErrDoc
.processLinks( pOutDev
, i
);
194 pdfi::PDFOutDev
* pOutDev( new pdfi::PDFOutDev(&aDoc
) );
196 // tell receiver early - needed for proper progress calculation
197 pOutDev
->setPageNum( aDoc
.getNumPages() );
199 // virtual resolution of the PDF OutputDev in dpi
200 static const int PDFI_OUTDEV_RESOLUTION
=7200;
203 const int nPages
= aDoc
.getNumPages();
204 for( int i
=1; i
<=nPages
; ++i
)
206 aDoc
.displayPage( pOutDev
,
208 PDFI_OUTDEV_RESOLUTION
,
209 PDFI_OUTDEV_RESOLUTION
,
210 0, gTrue
, gTrue
, gTrue
);
211 aDoc
.processLinks( pOutDev
, i
);