java - 如何以编程方式将波斯语文本写入 PDF?

标签 java android pdf

我编写了一个程序,可以将 PDF 文件创建到 SD 卡上。然后它会向其中写入一些文本。我想写一些波斯语文本,但 PDF 中没有显示该文本。 这是我的 Android 代码:

// Create a document and set it's properties
Document objDocument = new Document();

objDocument.setCreator("اپلیکیشن فرهنگیان");
objDocument.setAuthor("فرهنگیان");
objDocument.setTitle("تاریخچه اپلیکیشن فرهنگیان");

// Create a page to add to the document
Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT, 54.0f);

printstr = "این یک متن تستی است ." ;
Label objLabel = new Label(printstr, 0, 0, 504, 100, 
    Font.getHelvetica(), 18, TextAlign.RIGHT);

// Add label to page
objPage.getElements().add(objLabel);

// Add page to document
objDocument.getPages().add(objPage);

try {
    // Outputs the document to file
    objDocument.draw(FILE);
    Toast.makeText(this, "فایل متنی در مسیر  :" + FILE + " ذخیره شد .",
            Toast.LENGTH_LONG).show();
} catch (Exception e) {
    Toast.makeText(this, "فایل ساخته نمیشود\n" + e.getMessage(), Toast.LENGTH_LONG).show();
}

问题是什么?

最佳答案

看不到您指定 PDF 格式的位置,请尝试在您的代码中实现

// open a new document
PrintedPdfDocument document = new PrintedPdfDocument(context,
     printAttributes);

// start a page
Page page = document.startPage(0);

// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());

// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());

//close the document
document.close();

SRC:AndroidDevelopers

关于java - 如何以编程方式将波斯语文本写入 PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47478232/

相关文章:

android - 如何使用 MuPDF 在密码保护的 pdf 上保存注释

r - 如何在 R 中启动新的图形窗口和/或图形页面

java - 我在 Apache Kylin 中构建 Cube 时遇到错误

java - UserService NullPointerException Spring/Hibernate

java - 使用 Android 语音识别无法收到超过 5 个结果

javascript - 使用 Javascript 将 PDF 表单转换为 self 更正作业

pdf - 是否可以在没有鼠标的情况下在 zathura 中选择文本?

java - JFrame 弹出窗口未显示在 JAR 中

java - Lombok 搞砸了 - IntelliJ IDEA

android - Jacoco - 如何在 jacoco Android gradle 中排除继承的类