LibreOffice Module sdext (master) 1
pdf2xml.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "outputwrap.hxx"
22#include <contentsink.hxx>
23#include <pdfihelper.hxx>
24#include <wrapper.hxx>
25#include <pdfparse.hxx>
26#include "../pdfiadaptor.hxx"
27
28#include <sal/main.h>
29#include <osl/process.h>
30#include <rtl/ref.hxx>
31#include <sal/log.hxx>
36
37using namespace ::pdfi;
38using namespace ::com::sun::star;
39
41{
42 if( argc < 4 )
43 return 1;
44
45 int nRet = 0;
46
47 try
48 {
49 OUString aBaseURL, aTmpURL, aSrcURL, aDstURL;
50
51 TreeVisitorFactorySharedPtr pTreeFactory;
52 if( rtl_str_compare(argv[1], "-writer") == 0 )
53 pTreeFactory = createWriterTreeVisitorFactory();
54 else if( rtl_str_compare(argv[1], "-draw") == 0 )
55 pTreeFactory = createDrawTreeVisitorFactory();
56 else if( rtl_str_compare(argv[1], "-impress") == 0 )
57 pTreeFactory = createImpressTreeVisitorFactory();
58 else
59 return 1;
60
61 osl_getProcessWorkingDir(&aBaseURL.pData);
62 osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[2]).pData,
63 &aTmpURL.pData );
64 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
65
66 osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[3]).pData,
67 &aTmpURL.pData );
68 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
69
70 // bootstrap UNO
71 uno::Reference< uno::XComponentContext > xContext(
73 uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager());
74 uno::Reference<lang::XMultiServiceFactory> xSM(xFactory, uno::UNO_QUERY_THROW);
76
78 aEnv.setUp();
79
81 xAdaptor->setTreeVisitorFactory(pTreeFactory);
82 nRet = xAdaptor->odfConvert(aSrcURL, new OutputWrap(aDstURL), nullptr) ? 0 : 1;
83 }
84 catch (const uno::Exception&)
85 {
86 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
87 return 1;
88 }
89 catch (const std::exception& e)
90 {
91 SAL_WARN("vcl.app", "Fatal: " << e.what());
92 return 1;
93 }
94
95 return nRet;
96}
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Adapts raw pdf import to XImportFilter interface.
Definition: pdfiadaptor.hxx:81
virtual void setUp() override
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
std::shared_ptr< TreeVisitorFactory > TreeVisitorFactorySharedPtr
TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory()
TreeVisitorFactorySharedPtr createDrawTreeVisitorFactory()
TreeVisitorFactorySharedPtr createImpressTreeVisitorFactory()
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
Definition: pdf2xml.cxx:40