Skip to main content

Transform PDF Page Content

  • 2 minutes to read

Use page transformation methods to modify how page content is rendered without changing the page structure. You can rotate, scale, or offset page content.

Rotate Page Content

Call the Page.rotateContent() method to rotate page content around a specified point.

The following code snippet rotates page content by 270 degrees around the specified point:

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;

import java.nio.channels.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (PdfDocument pdfDocument = new PdfDocument(FileChannel.open(
                Path.of("document.pdf")))) {

            Page page = pdfDocument.getPages().getFirst();

            // Rotate page content around the specified point.
            page.rotateContent(300, 300, 270);

            try (WritableByteChannel writableByteChannel =
                 FileChannel.open(Path.of("result.pdf"),
                     StandardOpenOption.CREATE,
                     StandardOpenOption.WRITE,
                     StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(writableByteChannel);
            }
        }
    }
}

Scale Page Content

Call the Page.scaleContent() method to scale page content horizontally, vertically, or both.

The following code snippet scales page content to 50% of its original size:

Page page = pdfDocument.getPages().getFirst();

// Scale page content by 50% on both axes.
page.scaleContent(0.5, 0.5);

Offset Page Content

Call the Page.offsetContent() method to move page content horizontally, vertically, or both.

The following code snippet moves page content by an X offset of 50 and a Y offset of 100:

Page page = pdfDocument.getPages().getFirst();

// Move page content by X and Y offsets.
page.offsetContent(50, 100);
See Also