gpt4 book ai didi

java - PHP Java Bridge 语法用于创建具有静态字段的对象?

转载 作者:行者123 更新时间:2023-11-30 06:16:18 25 4
gpt4 key购买 nike

我想在 PHP Java Bridge 中实现这个 PDFBox 示例,但我被困在 PDType1Font.HELVETICA_BOLD 字段上:

如何在 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();

在 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");

?>

最佳答案

我缺少字体 jar ,fontbox。另外,也可以在 PDFbox 网站上下载。

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

$CourierFont = Java("org.apache.pdfbox.pdmodel.font.PDType1Font");
$CourierFont = $CourierFont->COURIER;

关于java - PHP Java Bridge 语法用于创建具有静态字段的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49140993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com