打印

openoffice我只关注pdf输出

[复制链接]
1379|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
keer_zu|  楼主 | 2015-5-12 16:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
keer_zu|  楼主 | 2015-5-12 18:27 | 只看该作者
pdf.rar (47.75 KB)



使用特权

评论回复
板凳
keer_zu|  楼主 | 2015-5-12 18:28 | 只看该作者
从导出部分开始看起



class PDFExport
{
private:

        Reference< XComponent >        mxSrcDoc;
    Reference< lang::XMultiServiceFactory > mxMSF;
        Reference< task::XStatusIndicator > mxStatusIndicator;
        Reference< task::XInteractionHandler > mxIH;

        sal_Bool                                mbUseTaggedPDF;
    sal_Int32               mnPDFTypeSelection;
        sal_Bool                                mbExportNotes;
        sal_Bool                                mbExportNotesPages;
        sal_Bool                    mbEmbedStandardFonts;
        sal_Bool                                mbUseTransitionEffects;
    sal_Bool                mbExportBookmarks;
    sal_Int32               mnOpenBookmarkLevels;

        sal_Bool                                mbUseLosslessCompression;
        sal_Bool                                mbReduceImageResolution;
    sal_Bool                mbSkipEmptyPages;
    sal_Bool                mbAddStream;
        sal_Int32                                mnMaxImageResolution;
        sal_Int32                                mnQuality;
        sal_Int32                                mnFormsFormat;
    sal_Bool                mbExportFormFields;
    sal_Bool                mbAllowDuplicateFieldNames;
        sal_Int32                                mnProgressValue;
    sal_Bool                mbRemoveTransparencies;
   
    sal_Bool                mbWatermark;
    uno::Any                maWatermark;

//these variable are here only to have a location in filter/pdf to set the default
//to be used by the macro (when the FilterData are set by the macro itself)
    sal_Bool                                mbHideViewerToolbar;
    sal_Bool                                mbHideViewerMenubar;
    sal_Bool                                mbHideViewerWindowControls;
    sal_Bool                                mbFitWindow;
    sal_Bool                                mbCenterWindow;
    sal_Bool                                mbOpenInFullScreenMode;
    sal_Bool                                mbDisplayPDFDocumentTitle;
    sal_Int32                                mnPDFDocumentMode;
    sal_Int32                                mnPDFDocumentAction;
    sal_Int32               mnZoom;
    sal_Int32               mnInitialPage;
    sal_Int32                                mnPDFPageLayout;
    sal_Bool                                mbFirstPageLeft;

    sal_Bool                                mbEncrypt;
        sal_Bool                                mbRestrictPermissions;
    sal_Int32                                mnPrintAllowed;
    sal_Int32                                mnChangesAllowed;
    sal_Bool                                mbCanCopyOrExtract;
    sal_Bool                                mbCanExtractForAccessibility;
   
    SvtGraphicFill          maCacheFill;
    sal_Int32               mnCachePatternId;

//--->i56629
        sal_Bool                                mbExportRelativeFsysLinks;
    sal_Int32               mnDefaultLinkAction;
        sal_Bool                                mbConvertOOoTargetToPDFTarget;
    sal_Bool                                mbExportBmkToDest;
//<---
        sal_Bool                ImplExportPage( ::vcl::PDFWriter& rWriter, ::vcl::PDFExtOutDevData& rPDFExtOutDevData,
                                                                                                const GDIMetaFile& rMtf );
    void                    ImplWriteWatermark( ::vcl::PDFWriter& rWriter, const Size& rPageSize );
public:

                                                PDFExport( const Reference< XComponent >& rxSrcDoc,
                                                           const Reference< task::XStatusIndicator >& xStatusIndicator,
                                                          const Reference< task::XInteractionHandler >& xIH,
                                                           const Reference< lang::XMultiServiceFactory >& xFact );
                                                ~PDFExport();

        sal_Bool                ExportSelection( vcl::PDFWriter& rPDFWriter, Reference< com::sun::star::view::XRenderable >& rRenderable, Any& rSelection,
                                MultiSelection aMultiSelection, Sequence< PropertyValue >& rRenderOptions, sal_Int32 nPageCount );

        sal_Bool                Export( const OUString& rFile, const Sequence< PropertyValue >& rFilterData );
   
    void                    showErrors( const std::set<vcl::PDFWriter::ErrorCode>& );
};

使用特权

评论回复
地板
keer_zu|  楼主 | 2015-5-13 10:09 | 只看该作者
keer_zu 发表于 2015-5-12 18:28
从导出部分开始看起

从这个类开始

使用特权

评论回复
5
keer_zu|  楼主 | 2015-5-19 16:53 | 只看该作者
通过java操作openoffice写文本

1. 首先要得到远程office组件的上下文.通过:
com.sun.star.uno.XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
得到,如果OpenOffice安装路径不是在工程的路径下面(我自己猜的), 就会报:
com.sun.star.comp.helper.BootstrapException: no office executable found!
解决办法可以参考http://blog.csdn.net/xt_chaoji/article/details/6617330
2. 得到 XMultiComponentFactory (ComponentFactory 工厂)
com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
3. 得到各种组件可以通过下面代码:
// docType 是 与 soffice 同目录下面的OpenOffice的其他shell文件,swrite等等
    protected XComponent newDocComponent(String docType)
            throws java.lang.Exception {
        String loadUrl = "private:factory/" + docType;
        
        mxRemoteServiceManager = this.getRemoteServiceManager();
        Object desktop = mxRemoteServiceManager.createInstanceWithContext(
                "com.sun.star.frame.Desktop", mxRemoteContext);
        
        XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime
                .queryInterface(XComponentLoader.class, desktop);
        PropertyValue[] loadProps = new PropertyValue[0];
        
        return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0,
                loadProps);
    }

4.得到 XTextDocument
       XComponent xEmptyWriterComponent = newDocComponent("swriter");
        XTextDocument mxDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,
                xEmptyWriterComponent);
5. 得到一个文档的引用
XText mxDocText = mxDoc.getText();
6. 得到文档的属性列表
        XPropertySet mxDocProps = (XPropertySet) UnoRuntime.queryInterface(
                XPropertySet.class, mxDoc);

7. 建立光标,用来插入新的内容。
XTextCursor mxDocCursor = mxDocText.createTextCursor();
        XSentenceCursor xSentenceCursor = (XSentenceCursor) UnoRuntime
        .queryInterface(XSentenceCursor.class, mxDocCursor);
        
        XWordCursor xWordCursor = (XWordCursor) UnoRuntime.queryInterface(
                XWordCursor.class, mxDocCursor);

8.得到光标属性列表
      XPropertySet xCursorProps = (XPropertySet) UnoRuntime .queryInterface(XPropertySet.class, mxDocCursor);
9.设置插入文字格式
        xCursorProps.setPropertyValue("CharFontName", "宋体");
        xCursorProps.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));
        xCursorProps.setPropertyValue("CharHeight", new Float(10.5));
        // 居中显示
        xCursorProps.setPropertyValue("ParaAdjust", com.sun.star.style.ParagraphAdjust.CENTER);
10.在该光标处插入信息
mxDocText.insertString(xSentenceCursor, “Hello World", true);

11. 保存的关键代码
    protected void storeDocComponent(XComponent xDoc, String storeUrl)
            throws java.lang.Exception {

        XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
                XStorable.class, xDoc);
        PropertyValue[] storeProps = new PropertyValue[1];
        storeProps[0] = new PropertyValue();
        storeProps[0].Name = "FilterName";
        storeProps[0].Value = "MS Word 97";

        openOfficeJavaLogger.debug("... store \"" + xDoc.toString() + "\" to \"" + storeUrl
                + "\".");

        xStorable.storeAsURL(storeUrl, storeProps);
    }

使用特权

评论回复
6
keer_zu|  楼主 | 2015-5-19 16:54 | 只看该作者
jodconvert就是使用类似方法实现从word到pdf转换的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1333

主题

12334

帖子

53

粉丝