/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef _WIN32 // Win actually modifies output for O_TEXT file mode, so need to // revert to binary here
_setmode( _fileno( g_binary_out ), _O_BINARY ); #endif
// We receive commands from stdin, these can include a password. bool bFinishedInput = false; char *aPwBuf = strdup("");
std::unique_ptr<PDFDoc> pDocUnique;
do
{ // try to read an input line char aInputBuf[129];
aInputBuf[128] = 0; if (!fgets(aInputBuf, sizeof(aInputBuf)-1, stdin))
{
printf("#ERROR:-1:Empty Input\n");
fflush(stdout); return EXIT_FAILURE;
} else
{ for (size_t i = 0; i < sizeof(aInputBuf); i++)
{ if (aInputBuf[i] == '\n')
{
aInputBuf[i] = 0; break;
}
}
}
switch (aInputBuf[0])
{ case'E': // Exit // We treat this as an error, we normally // expect password input and then processing
printf("#ERROR:-1:Exit on request\n");
fflush(stdout); return EXIT_FAILURE;
case'G': // Go! - actually render if (pDocUnique == nullptr || !pDocUnique->isOk())
{
printf("#ERROR:-1:PDF is not open\n");
fflush(stdout); return EXIT_FAILURE;
}
bFinishedInput = true; break;
case'O': // Open // Try opening the document with any password we have
{ // PDFDoc takes over ownership for all strings below
GooString* pFileName = new GooString(myStringToStdString(argv[1]));
if (pDocUnique->isOk())
{
printf("#OPEN\n");
} else
{ int err = pDocUnique->getErrorCode(); // e.g. #ERROR:1: (code for OpenFile) // #ERROR:2:ENCRYPTED For ones we need to detect, use text
printf("#ERROR:%d:%s\n", err, err==errEncrypted ? "ENCRYPTED" : "");
}
fflush(stdout);
} break;
// tell the receiver early - needed for proper progress calculation constint nPages = pDoc->getNumPages();
pdfi::PDFOutDev::setPageNum(nPages);
// virtual resolution of the PDF OutputDev in dpi staticconstint PDFI_OUTDEV_RESOLUTION = 7200;
// do the conversion for (int i = 1; i <= nPages; ++i)
{
pDoc->displayPage(&aOutDev,
i,
PDFI_OUTDEV_RESOLUTION,
PDFI_OUTDEV_RESOLUTION,
0, true, true, true);
pDoc->processLinks(&aOutDev, i);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.