How to HTML to PDF in Java - ByteScout

How to HTML to PDF in Java

Use the sample source code below to convert HTML to PDF in Java using ByteScout Cloud API (low level).

You can also check how to convert PDF to HTML.

POST endpoint:

https://api.pdf.co/v1/pdf/convert/from/html

Code Sample:

import Bytescout\Client\API.*;
import Bytescout\Client\API.auth.*;
import Bytescout\Client\API.model.*;
import Bytescout\Client\API.api.DefaultApi;

import java.io.File;
import java.util.*;

public class DefaultApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        
        // Configure API key authorization: api_key
        ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key");
        api_key.setApiKey("YOUR API KEY");
        // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
        //api_key.setApiKeyPrefix("Token");

        DefaultApi apiInstance = new DefaultApi();
        Text text = ; // Text | HTML data to convert to PDF.
        String name = name_example; // String | File name for the generated result.
        try {
            SingleResponseModel result = apiInstance.pdfConvertFromHtmlPost(text, name);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#pdfConvertFromHtmlPost");
            e.printStackTrace();
        }
    }
}

Tutorials:

prev
next