Skip to content

Add pdf generation capabilities to the pdfbox module#17

Draft
gayaldassanayake wants to merge 5 commits into
xlibb:mainfrom
gayaldassanayake:add-pdf-gen
Draft

Add pdf generation capabilities to the pdfbox module#17
gayaldassanayake wants to merge 5 commits into
xlibb:mainfrom
gayaldassanayake:add-pdf-gen

Conversation

@gayaldassanayake
Copy link
Copy Markdown

Purpose

Fixes ballerina-platform/ballerina-library#7917

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

Comment thread ballerina/pdDocument.bal Outdated
Comment thread ballerina/pdRectangle.bal
Comment thread ballerina/pdDocument.bal
# The class that coresponds to org.apache.pdfbox.pdmodel.PDDocument.
# This is the in-memory representation of a PDF document.
public distinct class PDDocument {
private handle jObj;
Copy link
Copy Markdown
Contributor

@Nuvindu Nuvindu May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of maintaining a variable for handle instance, we can store the object as a native data from the java side

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the PDDocument corresponds to the org.apache.pdfbox.pdmodel.PDDocument class coming from the apache pdfbox library. Therefore, to avoid having a handle here and to move it to Java side, we need to create a java wrapper for each pdfbox class.

Furthermore, if the purpose of not having a handle instance in the Ballerina PDDocument class is to avoid letting user pass a handle to the init method, in this case, I am accepting only ballerina types in the init method. Hence, this will not be an issue.

WDYT?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gayaldassanayake convention is to write a java-wrapper whenever we need to access Java objects/clients to perform a particular actions. And we usually hide the relevant Java object/client instance as the native data. IMO adding fields with non-ballerina types (like handle) inside Ballerina classes is an anti-pattern.

@gayaldassanayake gayaldassanayake requested a review from Nuvindu May 22, 2025 05:52
Copy link
Copy Markdown

@ayeshLK ayeshLK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove the handle usage from the Ballerina classes and hide the Java objects/clients inside native data.

@gayaldassanayake
Copy link
Copy Markdown
Author

Lets remove the handle usage from the Ballerina classes and hide the Java objects/clients inside native data.

I am working on this in my free time. Since there are a lot of functions to change, might take some time. For the time being, will convert this to a draft.

@gayaldassanayake gayaldassanayake marked this pull request as draft June 2, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a ballerina module for working with PDFs

3 participants