1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "pdfioutdev_gpl.hxx"
23 # include <fcntl.h> /*_O_BINARY*/
26 FILE* g_binary_out
=stderr
;
28 static const char *ownerPassword
= "\001";
29 static const char *userPassword
= "\001";
30 static const char *outputFile
= "\001";
31 static const char *options
= "\001";
33 int main(int argc
, char **argv
)
38 if (!strcmp(argv
[k
], "-f"))
40 outputFile
= argv
[k
+1];
42 for (int j
= k
; j
< argc
; ++j
)
45 else if (!strcmp(argv
[k
], "-o"))
49 for (int j
= k
; j
< argc
; ++j
)
53 else if (!strcmp(argv
[k
], "-opw"))
55 ownerPassword
= argv
[k
+1];
57 for (int j
= k
; j
< argc
; ++j
)
60 else if (!strcmp(argv
[k
], "-upw"))
62 userPassword
= argv
[k
+1];
64 for (int j
= k
; j
< argc
; ++j
)
71 globalParams
= new GlobalParams();
72 globalParams
->setErrQuiet(gTrue
);
74 globalParams
->setupBaseFonts(NULL
);
77 // try to read a possible open password form stdin
80 if( ! fgets( aPwBuf
, sizeof(aPwBuf
)-1, stdin
) )
81 aPwBuf
[0] = 0; // mark as empty
84 for( unsigned int i
= 0; i
< sizeof(aPwBuf
); i
++ )
86 if( aPwBuf
[i
] == '\n' )
94 // PDFDoc takes over ownership for all strings below
95 GooString
* pFileName
= new GooString(argv
[1]);
96 GooString
* pErrFileName
= new GooString(argv
[2]);
98 // check for password string(s)
99 GooString
* pOwnerPasswordStr( aPwBuf
[0] != 0
100 ? new GooString( aPwBuf
)
101 : (ownerPassword
[0] != '\001'
102 ? new GooString(ownerPassword
)
103 : (GooString
*)NULL
) );
104 GooString
* pUserPasswordStr( userPassword
[0] != '\001'
105 ? new GooString(userPassword
)
106 : (GooString
*)NULL
);
107 if( outputFile
[0] != '\001' )
108 g_binary_out
= fopen(outputFile
,"wb");
111 // Win actually modifies output for O_TEXT file mode, so need to
112 // revert to binary here
113 _setmode( _fileno( g_binary_out
), _O_BINARY
);
116 PDFDoc
aDoc( pFileName
,
120 PDFDoc
aErrDoc( pErrFileName
,
124 // Check various permissions for aDoc.
125 PDFDoc
&rDoc
= aDoc
.isOk()? aDoc
: aErrDoc
;
127 pdfi::PDFOutDev
aOutDev(&rDoc
);
128 if (!strcmp(options
, "SkipImages")) {
129 aOutDev
.setSkipImages(true);
132 // tell the receiver early - needed for proper progress calculation
133 const int nPages
= rDoc
.isOk()? rDoc
.getNumPages(): 0;
134 pdfi::PDFOutDev::setPageNum(nPages
);
136 // virtual resolution of the PDF OutputDev in dpi
137 static const int PDFI_OUTDEV_RESOLUTION
= 7200;
140 for (int i
= 1; i
<= nPages
; ++i
)
142 rDoc
.displayPage(&aOutDev
,
144 PDFI_OUTDEV_RESOLUTION
,
145 PDFI_OUTDEV_RESOLUTION
,
146 0, gTrue
, gTrue
, gTrue
);
147 rDoc
.processLinks(&aOutDev
, i
);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */