All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.pdfservices.operation.pdfjobs.params.htmltopdf.HTMLToPDFParams Maven / Gradle / Ivy

Go to download

Adobe PDF Services SDK allows you to access RESTful APIs to create, convert, and manipulate PDFs within your applications. Older versions can be found under groupId: com.adobe.documentservices, artifactId: pdftools-sdk

There is a newer version: 4.2.0
Show newest version
/*
 * Copyright 2024 Adobe
 * All Rights Reserved.
 *
 * NOTICE: Adobe permits you to use, modify, and distribute this file in
 * accordance with the terms of the Adobe license agreement accompanying
 * it. If you have received this file from a source other than Adobe,
 * then your use, modification, or distribution of it requires the prior
 * written permission of Adobe.
 */

package com.adobe.pdfservices.operation.pdfjobs.params.htmltopdf;

import com.adobe.pdfservices.operation.pdfjobs.jobs.HTMLToPDFJob;
import com.adobe.pdfservices.operation.pdfjobs.params.PDFServicesJobParams;
import org.json.JSONObject;

/**
 * Parameters for converting HTML to PDF using {@link HTMLToPDFJob}.
 */
public class HTMLToPDFParams implements PDFServicesJobParams {
    /**
     * Default values for params.
     */
    private static final boolean PRINT_HEADER_FOOTER_BY_DEFAULT = true;

    private boolean includeHeaderFooter;

    private PageLayout pageLayout;

    private JSONObject dataToMerge;

    private HTMLToPDFParams(boolean includeHeaderFooter, PageLayout pageLayout, JSONObject dataToMerge) {
        this.includeHeaderFooter = includeHeaderFooter;
        this.pageLayout = pageLayout;
        this.dataToMerge = dataToMerge;
    }

    /**
     * Returns {@code true} if default header and footer will be included in the resulting PDF file.
     * The default header consists of the date and the document title.
     * The default footer consists of the file name and page number.
     *
     * @return {@code true} if default header and footer will be included in the resulting PDF file
     */
    public boolean includesHeaderFooter() {
        return includeHeaderFooter;
    }

    /**
     * Returns the intended page layout of the resulting PDF file.
     *
     * @return intended page layout.
     */
    public PageLayout getPageLayout() {
        return pageLayout;

    }

    /**
     * Returns JSON data that will be used to manipulate HTML DOM before it is converted into PDF file.
     * This mechanism is intended to be used to supply data that might otherwise be retrieved using ajax requests.
     * 

* To make use of this mechanism, the source html file must include a script element such as: *

{@code }
     *      where json.js refers to the JSON data,
* And also Requires javascript in the source html file to make use of this JSON data to manipulate the HTML DOM. * * @return data inputs for manipulating HTML DOM before converting it into a PDF file. */ public JSONObject getDataToMerge() { return dataToMerge; } /** * Creates a new {@link Builder}. * * @return a {@link Builder} instance. */ public static Builder htmltoPDFParamsBuilder() { return new Builder(); } /** * Builds a {@link HTMLToPDFParams} instance. */ public static class Builder { private boolean includeHeaderFooter; private PageLayout pageLayout; private JSONObject dataToMerge; /** * Constructs a {@code Builder} instance. */ public Builder() { this.includeHeaderFooter = PRINT_HEADER_FOOTER_BY_DEFAULT; this.pageLayout = new PageLayout(); this.dataToMerge = new JSONObject(); } /** * Sets the includeHeaderFooter parameter. If true, default header and footer will be included in resulting PDF. * The default header consists of the date and the document title. * The default footer consists of the file name and page number. * * @param includeHeaderFooter true if default header and footer should be included in the resulting PDF. * Default value is {@code true}. * @return this Builder instance to add any additional parameters */ public Builder includeHeaderFooter(boolean includeHeaderFooter) { this.includeHeaderFooter = includeHeaderFooter; return this; } /** * Sets the pageLayout parameter. * * @param pageLayout intended page layout of the resulting PDF file. * @return this Builder instance to add any additional parameters */ public Builder withPageLayout(PageLayout pageLayout) { this.pageLayout = pageLayout; return this; } /** * Sets the data to be used by the javascript in the source html file to manipulate the HTML DOM before it * gets converted to PDF. * This mechanism is intended to be used to supply data that might otherwise be retrieved using ajax requests. *

* To make use of this mechanism, the source html file must include a script element such as: *

{@code }
         *      where json.js refers to the JSON data,
* And also Requires javascript in the source html file to make use of this JSON data to manipulate the HTML * DOM. * * @param dataToMerge JSON object * @return this Builder instance to add any additional parameters */ public Builder withDataToMerge(JSONObject dataToMerge) { this.dataToMerge = dataToMerge; return this; } /** * Returns a new {@link HTMLToPDFParams} instance built from the current state of this builder. * * @return a new {@code HTMLtoPDFParams} instance. */ public HTMLToPDFParams build() { return new HTMLToPDFParams(includeHeaderFooter, pageLayout, dataToMerge); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy