1

I would like to implement this PDFBox example in PHP Java Bridge but I'm stuck on the PDType1Font.HELVETICA_BOLD field:

How to create this in PHP Java Bridge:

PDFont font = PDType1Font.HELVETICA_BOLD;

https://pdfbox.apache.org/1.8/cookbook/workingwithfonts.html

// Create a document and add a page to it
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage( page );

// Create a new font object selecting one of the PDF base fonts
PDFont font = PDType1Font.HELVETICA_BOLD;

// Start a new content stream which will "hold" the to be created content
PDPageContentStream contentStream = new PDPageContentStream(document, page);

// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 100, 700 );
contentStream.drawString( "Hello World" );
contentStream.endText();

// Make sure that the content stream is closed:
contentStream.close();

// Save the results and ensure that the document is properly closed:
document.save( "Hello World.pdf");
document.close();

And in PHP Java Bridge

<?php require_once("http://localhost:8080/JavaBridge/java/Java.inc");

$PDDocument= new Java("org.apache.pdfbox.pdmodel.PDDocument");
$PDPage= new Java("org.apache.pdfbox.pdmodel.PDPage");

$PDDocument->addPage( $PDPage);
// Start a new content stream which will "hold" the to be created content
$PDPageContentStream= new Java("org.apache.pdfbox.pdmodel.PDPageContentStream",$PDDocument, $PDPage);

$PDFont= new Java("org.apache.pdfbox.pdmodel.font.PDFont");
// !!!!Stuck on the syntax to use a static field?
$PDFont= $PDFont->PDType1Font("HELVETICA");

?>

1 Answer 1

1

I was missing the jar for fonts, fontbox. Also, available for download on the PDFbox site.

https://pdfbox.apache.org/download.cgi

$CourierFont = Java("org.apache.pdfbox.pdmodel.font.PDType1Font");
$CourierFont = $CourierFont->COURIER;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.