Macros/General/006

    From The Document Foundation Wiki


    Description

    A hybrid PDF is a file which can be read like any other PDF, but which contains a source document in PDF format, allowing you to modify it using LibreOffice. It can be created with the menu command File ▸ Export as ▸ Export as PDF.

    The following macro shows how to do this in LibreOffice Basic. The array propFich in this example specifies the filter to use (calc_pdf_Export) and the selected options. The filterProps array specifies the text to be exported and contains a switch IsAddStream to determine whether the export is to take place.

    Code

    In LibreOffice Basic:

    Option Explicit
    
    Sub ExportPDFinHybridFormat
        '''Export current active Calc sheet to a hybrid PDF'''
    
        Dim filterData(1) As New com.sun.star.beans.PropertyValue
        Dim filterProps(1) As New com.sun.star.beans.PropertyValue
        Dim fileAddress As String
    
        'create prop-vals in filterData, which will be fed into filterProps
        filterData(0).Name = "Selection"
        filterData(0).Value = ThisComponent.CurrentController.ActiveSheet
        filterData(1).Name = "IsAddStream"
        filterData(1).Value = True
    
        'create prop-vals in filterProps, which will be fed in the export function storeToURL
        filterProps(0).Name = "FilterName"
        filterProps(0).Value = "calc_pdf_Export"
        filterProps(1).Name = "FilterData"
        filterProps(1).Value = filterData()
    
        fileAddress = convertToURL("/home/<user>/Documents/test.pdf")
        ThisComponent.storeToURL(fileAddress, filterProps())
    
    End Sub ' ExportPDFinHybridFormat

    ODS file to test macro

    Notes