Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

226 changes: 226 additions & 0 deletions DocumentConversion/CreateDocFromWebPage/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.datalogics.pdfl.samples</groupId>
<artifactId>CreateDocFromWebPage</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<profiles>
<profile>
<id>Windows64</id>
<activation>
<os>
<family>windows</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<jni.classifier>win-x86-64-jni</jni.classifier>
</properties>
</profile>
<profile>
<id>MacArm</id>
<activation>
<os>
<family>mac</family>
<arch>aarch64</arch>
</os>
</activation>
<properties>
<jni.classifier>mac-arm-64-jni</jni.classifier>
</properties>
</profile>
<profile>
<id>Linux64</id>
<activation>
<os>
<!-- Use OS <name> instead of <family> because the "unix" <family> also includes Mac -->
<name>Linux</name>
<arch>amd64</arch>
</os>
</activation>
<properties>
<jni.classifier>linux-x86-64-jni</jni.classifier>
</properties>
</profile>
<profile>
<id>WindowsArm64</id>
<activation>
<os>
<family>windows</family>
<arch>aarch64</arch>
</os>
</activation>
<properties>
<jni.classifier>win-arm-64-jni</jni.classifier>
</properties>
</profile>
<profile>
<id>LinuxArm64</id>
<activation>
<os>
<!-- Use OS <name> instead of <family> because the "unix" <family> also includes Mac -->
<name>Linux</name>
<arch>aarch64</arch>
</os>
</activation>
<properties>
<jni.classifier>linux-arm-64-jni</jni.classifier>
</properties>
</profile>
<!--
The web-conversion plugin zip (DL210WebToPDF.ppi plus its helper and server
executables) is published for Windows and Linux only. On macOS the plugin
is part of the signed .ppi framework bundle that ships inside
web-conversion-cef-runtime.
-->
<profile>
<id>WebConversionPlugin</id>
<activation>
<os>
<family>!mac</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>web-conversion</artifactId>
<version>[21.0,22.0)</version>
<type>zip</type>
<classifier>${jni.classifier}</classifier>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>pdfl</artifactId>
<version>[21.0,22.0)</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>pdfl</artifactId>
<version>[21.0,22.0)</version>
</dependency>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>pdfl</artifactId>
<version>[21.0,22.0)</version>
<type>zip</type>
<classifier>${jni.classifier}</classifier>
</dependency>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>pdfl</artifactId>
<version>[21.0,22.0)</version>
<type>zip</type>
<classifier>resources</classifier>
</dependency>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>pdfl</artifactId>
<version>[21.0,22.0)</version>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>com.datalogics.pdfl</groupId>
<artifactId>web-conversion-cef-runtime</artifactId>
<version>[21.0,22.0)</version>
<type>zip</type>
<classifier>${jni.classifier}</classifier>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.datalogics.pdfl</includeGroupIds>
<includeArtifactIds>pdfl</includeArtifactIds>
<includeClassifiers>resources</includeClassifiers>
<includeTypes>zip</includeTypes>
<outputDirectory>${project.build.directory}/lib/Resources</outputDirectory>
</configuration>
</execution>
<execution>
<id>unpack-jni</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.datalogics.pdfl</includeGroupIds>
<includeArtifactIds>pdfl</includeArtifactIds>
<includeClassifiers>${jni.classifier}</includeClassifiers>
<includeTypes>zip</includeTypes>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
<!--
Unpack both halves of the web conversion add-on into the same
directory as the JNI libraries, which is what java.library.path points
at when the sample runs.
-->
<execution>
<id>unpack-web-conversion</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.datalogics.pdfl</includeGroupIds>
<includeArtifactIds>web-conversion,web-conversion-cef-runtime</includeArtifactIds>
<includeClassifiers>${jni.classifier}</includeClassifiers>
<includeTypes>zip</includeTypes>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.datalogics.pdfl.samples.CreateDocFromWebPage</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.datalogics.pdfl.samples;

import java.util.EnumSet;

import com.datalogics.PDFL.Document;
import com.datalogics.PDFL.Library;
import com.datalogics.PDFL.SaveFlags;
import com.datalogics.PDFL.WebConvertInfo;
import com.datalogics.PDFL.WebPageOrientation;
import com.datalogics.PDFL.WebPageSize;
import com.datalogics.PDFL.WebToPDFConvertParams;
import com.datalogics.PDFL.WebViewportPreset;

/*
* This sample demonstrates converting a web page or a local HTML file into a
* PDF document.
*
* The optional first argument may be a URL (http://, https://, or file://) or a
* path to a local HTML file. The sample detects which from the scheme prefix
* and calls Document.fromWebUrl or Document.fromHtmlFile accordingly. Relative
* asset references in a local file resolve against that file's directory. The
* optional second argument names the output file.
*
* Rendering is performed by the WebToPDF plugin. The plugin runtime ships as a
* separate add-on package; see pom.xml, which declares it and unpacks it
* alongside the JNI libraries.
*
* Copyright (c) 2026, Datalogics, Inc. All rights reserved.
*
*/

public class CreateDocFromWebPage {

/**
* Returns true if the argument looks like a URL the conversion plugin
* handles natively, rather than a local filesystem path.
*/
private static boolean looksLikeUrl(String s) {
return s.startsWith("http://") || s.startsWith("https://") || s.startsWith("file://");
}

/**
* @param args optional source (URL or HTML file path) and output PDF path
*/
public static void main(String[] args) throws Throwable {
System.out.println("CreateDocFromWebPage sample:");

Library lib = new Library();

try {
String source = args.length > 0 ? args[0] : "https://www.datalogics.com";
String output = args.length > 1 ? args[1] : "CreateDocFromWebPage-out.pdf";

// Conversion parameters
WebToPDFConvertParams params = new WebToPDFConvertParams();
params.setViewportSize(WebViewportPreset.DESKTOP);
params.setPageSize(WebPageSize.LETTER);
params.setPageOrientation(WebPageOrientation.PORTRAIT);
params.setMargins(0.5, 0.5, 0.5, 0.5);
params.setPrintBackground(true);
params.setTimeoutSeconds(60); // 0 uses the 300s plugin default; -1 waits forever

WebConvertInfo info = new WebConvertInfo();

final boolean isUrl = looksLikeUrl(source);
System.out.println("Converting " + (isUrl ? "URL " : "HTML file ") + source + " ...");

Document doc = isUrl
? Document.fromWebUrl(source, params, info)
: Document.fromHtmlFile(source, params, info);

System.out.println("Wrote " + info.getPageCount() + " pages in "
+ info.getConversionTimeMs() + " ms");
if (!info.getTitle().isEmpty()) {
System.out.println("Title: " + info.getTitle());
}
// getSourceUrl reports the URL actually rendered, so it reflects any
// redirects the browser followed.
if (!info.getSourceUrl().isEmpty() && !info.getSourceUrl().equals(source)) {
System.out.println("Resolved URL: " + info.getSourceUrl());
}

System.out.println("Saving the document...");
doc.save(EnumSet.of(SaveFlags.FULL), output);
System.out.println("Saved to " + output);
}
catch (RuntimeException e) {
System.err.println("Conversion failed: " + e.getMessage());
System.err.println("If the plugin could not be loaded, confirm that the web "
+ "conversion runtime was unpacked into target/lib (see pom.xml).");
throw e;
}
finally {
lib.delete();
}
}
}
1 change: 1 addition & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'ContentModification/Watermark/',
'DocumentConversion/ColorConvertDocument/',
'DocumentConversion/ConvertToOffice/',
'DocumentConversion/CreateDocFromWebPage/',
'DocumentConversion/CreateDocFromXPS/',
'DocumentConversion/FacturXConverter/',
'DocumentConversion/PDFAConverter/',
Expand Down