如何以编程方式将波斯文写入PDF?

时间:2017-11-24 18:05:19

标签: java android pdf

我编写了一个为SD卡创建PDF文件的程序。然后它会写一些文字。我想写一些波斯语文本,但文本没有显示在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();
}

什么是问题?

1 个答案:

答案 0 :(得分:0)

无法看到您指定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

相关问题