Can /cool/convert-to/pdf change the document model (page size, margins, table width, Calc scaling) before PDF export?

Hi,

We run a server-side document-to-PDF converter that drives headless LibreOffice through the UNO API (C++). We’re considering replacing it with Collabora Online’s REST conversion API (/cool/convert-to/pdf). Before deciding, we need to know whether Collabora Online can handle the customizations we apply to each document after loading and before PDF export.
What we do today with UNO

  1. Writer – custom page size and margins on every page style (values come from our configuration):
    Reference xPageStyles;

    xFamilies->getByName(“PageStyles”) >>= xPageStyles;

    for (const OUString& name : xPageStyles->getElementNames())

    {

    Reference<XPropertySet> xStyle;
    
    xPageStyles->getByName(name) >>= xStyle;
    
    xStyle->setPropertyValue("Width",        Any(sal_Int32(27940)));  // 1/100 mm
    
    xStyle->setPropertyValue("Height",       Any(sal_Int32(43180)));
    
    xStyle->setPropertyValue("IsLandscape",  Any(false));
    
    xStyle->setPropertyValue("TopMargin",    Any(sal_Int32(1270)));
    
    xStyle->setPropertyValue("LeftMargin",   Any(sal_Int32(1270)));
    
    // ... BottomMargin, RightMargin
    

    }

  2. Writer – force a relative width on every table:
    for (sal_Int32 i = 0; i < xTables->getCount(); ++i)

    {

    Reference<XPropertySet> xTable(xTables->getByIndex(i), UNO_QUERY);
    
    xTable->setPropertyValue("RelativeWidth", Any(sal_Int16(100)));
    
    xTable->setPropertyValue("LeftMargin",    Any(sal_Int32(0)));
    
    xTable->setPropertyValue("RightMargin",   Any(sal_Int32(0)));
    

    }

  3. Accessibility fixes for PDF/UA (Writer, Impress, Draw):

    • Set a fallback Description (alt text) on images and shapes that have none.
    • Set HyperLinkName to the URL on hyperlinks whose name is empty.
  4. Export with storeToURL and these FilterData entries: PDFUACompliance, UseTaggedPDF, ExportBookmarks etc.,

Our Questions:

  1. Can the FilterData options in item 4 be passed to /cool/convert-to/pdf, for example through the options form field as JSON?
  2. Is there any supported way to apply the document-model changes in items 1–3 during a convert-to request?
  3. if the answer to question 2 is no, what approach do you recommend for a conversion service that needs these changes?

Regards,

Satya

Hi Satya,

Can the FilterData options in item 4 be passed to /cool/convert-to/pdf, for example through the options form field as JSON?

Yes, the options form field takes the PDF export settings as JSON, with the same names as the FilterData you use today; the list is at https://sdk.collaboraonline.com/docs/conversion_api.html#pdf-filter-options:

curl -F data=@input.docx \
  -F 'options={"UseTaggedPDF":{"type":"boolean","value":"true"},"PDFUACompliance":{"type":"boolean","value":"true"},"ExportBookmarks":{"type":"boolean","value":"true"}}' \
  https://your-server:9980/cool/convert-to/pdf -o output.pdf

Put all export settings into that one JSON, including SelectPdfVersion if you need a specific PDF version, rather than using the older separate PDFVer and FullSheetPreview fields, which are deprecated.

Is there any supported way to apply the document-model changes in items 1–3 during a convert-to request?

Only partly, today. There is a second endpoint, /cool/transform-document-structure, which applies a JSON list of transformations to the loaded document and then saves it in the requested format, which can be pdf. It was built for filling in templates, so for Writer it covers content controls, charts, document properties and a fixed list of allowed .uno: commands. It has no operation for the page size and margins of all page styles, for the width of all tables, or for filling in empty alt text and hyperlink names, and it does not take the options field.

if the answer to question 2 is no, what approach do you recommend for a conversion service that needs these changes?

The natural way forward would be to extend that transform API with the operations you need (setting properties on all page styles, setting the width and margins of all tables, and filling in missing alt text and hyperlink names). That way, the whole conversion would happen within Collabora Online, without a separate office process driven through UNO. The existing transformations are implemented in the FN_TRANSFORM_DOCUMENT_STRUCTURE case of SwTextShell::Execute in engine/sw/source/uibase/shells/textsh1.cxx for Writer, and in DrawViewShell::FuTransformDocumentStructure in engine/sd/source/ui/view/drviews2.cxx for Impress and Draw.