Get Started — Office & PDF File API for Java
- 4 minutes to read
This getting-started help topic explains how to prepare your development environment, add DevExpress Office & PDF File API for Java libraries, and create your first document-processing application.
Prerequisites
- JDK 21 or later
- Maven 3.9+, or Gradle 8.14+
- IntelliJ IDEA, Eclipse, or VS Code with the Extension Pack for Java
Set Up Your Development Environment
Download and install a supported Java Development Kit (JDK 21 or later).
Verify that Java is installed before you create a project.
java -version
The command should display the installed Java version.
Add DevExpress API Libraries to a Project
DevExpress Office & PDF File API for Java libraries are available as Maven packages:
| Maven Package Name | DevExpress API Library |
|---|---|
devexpress-docs-pdf |
PDF Document API |
devexpress-docs-presentation |
PowerPoint Presentation API |
devexpress-docs-barcode |
Barcode Generation API |
Create a Maven or Gradle project and add the required DevExpress dependencies.
dependencies {
implementation("com.devexpress:devexpress-docs-pdf:26.2.1")
implementation("com.devexpress:devexpress-docs-presentation:26.2.1")
implementation("com.devexpress:devexpress-docs-barcode:26.2.1")
}
Add Platform-Specific Runtime Dependencies
DevExpress Office & PDF File API libraries use third-party libraries at runtime. Maven and Gradle install most managed dependencies automatically, but do not resolve platform-specific native libraries transitively.
Add the following native dependencies for your target platform to the project:
- Skija
- LWJGL
- LWJGL HarfBuzz
Use the following artifacts for each target platform:
| Platform | Skija | LWJGL | LWJGL HarfBuzz |
|---|---|---|---|
| Windows x64 | io.github.humbleui:skija-windows-x64:0.119.6 |
org.lwjgl:lwjgl:3.4.2:natives-windows |
org.lwjgl:lwjgl-harfbuzz:3.4.2:natives-windows |
| Linux x64 | io.github.humbleui:skija-linux-x64:0.119.6 |
org.lwjgl:lwjgl:3.4.2:natives-linux |
org.lwjgl:lwjgl-harfbuzz:3.4.2:natives-linux |
| macOS ARM64 | io.github.humbleui:skija-macos-arm64:0.119.6 |
org.lwjgl:lwjgl:3.4.2:natives-macos-arm64 |
org.lwjgl:lwjgl-harfbuzz:3.4.2:natives-macos-arm64 |
Use the following configuration in a PDF Document API application for Linux x64:
dependencies {
implementation 'com.devexpress:devexpress-docs-pdf:26.2.1'
runtimeOnly 'io.github.humbleui:skija-linux-x64:0.119.6'
runtimeOnly 'org.lwjgl:lwjgl:3.4.2:natives-linux'
runtimeOnly 'org.lwjgl:lwjgl-harfbuzz:3.4.2:natives-linux'
}
Warning
The required native libraries should be available at runtime. Otherwise, the application throws an UnsatisfiedLinkError.
Create Your First Application
Generate a PDF Document
Create a PDF document with an A4 page, add a formatted title and paragraph, and save the document as a PDF file.
import com.devexpress.docs.pdf.*;
import com.devexpress.drawing.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.*;
import java.io.*;
import java.nio.file.*;
import java.nio.channels.*;
public class CreatePdfDocument {
public static void main(String[] args) throws Exception {
try (PdfDocument pdfDocument = new PdfDocument()) {
// Add an A4 page to the document.
Page page = pdfDocument.getPages().add(DXPaperKind.A4);
// Add a title to the document.
TextFragment textFragment = new TextFragment();
textFragment.setText("Quarterly Sales Report");
textFragment.setLocation(new PointF(50, 770));
textFragment.setFont(new TextFont("Arial", TextFontStyle.BOLD));
textFragment.setFontSize(24);
page.addFragment(textFragment);
// Add a paragraph to the document.
ParagraphFragment paragraphFragment = new ParagraphFragment();
paragraphFragment.setText("This report summarizes sales data for Q1 2026.");
paragraphFragment.setLocation(new PointF(50, 730));
paragraphFragment.setWidth(200);
paragraphFragment.setFont(new TextFont("Arial"));
paragraphFragment.setFontSize(12);
page.addFragment(paragraphFragment);
// Save the document to a PDF file.
try (WritableByteChannel writableByteChannel =
FileChannel.open(Path.of("Result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(writableByteChannel);
}
}
}
}
Update a PowerPoint Presentation
Load an existing PowerPoint presentation, add a title slide, update its placeholder text, and save the presentation.
import com.devexpress.docs.presentation.*;
import java.nio.channels.*;
import java.nio.file.*;
public class UpdatePresentation {
public static void main(String[] args) throws Exception {
// Load an existing presentation.
Path path = Path.of("presentation.pptx");
try (Presentation presentation = new Presentation(
Files.readAllBytes(path))) {
// Create a slide and customize its title.
Slide slide = new Slide(SlideLayoutType.TITLE);
for(ShapeBase shapeBase : slide.getShapes()) {
if(shapeBase instanceof Shape shape &&
shape.getPlaceholderSettings()
.getType() == PlaceholderType.CENTERED_TITLE) {
shape.getTextArea().setText("DevExpress Presentation API for Java");
}
}
// Add the slide to the presentation.
presentation.getSlides().add(slide);
// Save the presentation while preserving PowerPoint compatibility.
try (WritableByteChannel writableByteChannel =
FileChannel.open(path,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
presentation.saveDocument(writableByteChannel);
}
}
}
}
Generate a Barcode
Generate a QR code with a logo and export it as a PNG image.
import com.devexpress.drawing.*;
import com.devexpress.docs.barcode.*;
import java.io.*;
import java.nio.file.*;
public class GenerateBarcode {
public static void main(String[] args) throws Exception {
byte[] logoBytes = Files.readAllBytes(Path.of("images/devexpress-logo.png"));
try (DXImage logo = DXImage.fromStream(new ByteArrayInputStream(logoBytes))) {
QRCodeOptions options = new QRCodeOptionsBuilder()
.withCompactionMode(QRCodeCompactionMode.BYTE)
.withVersion(QRCodeVersion.VERSION_10)
.withErrorCorrectionLevel(QRCodeErrorCorrectionLevel.H)
.withModuleSize(10)
.withShowText(false)
.withIncludeQuietZone(true)
.withLogo(logo)
.build();
try (FileOutputStream pngStream = new FileOutputStream(
Path.of("qr-code.png").toFile());
BarcodeGenerator generator = new BarcodeGenerator(options)) {
// Export the QR Code to a PNG image.
generator.export("https://www.devexpress.com", pngStream, DXImageFormat.getPng());
}
}
}
}