簡體   English   中英

如何以編程方式將波斯文字寫入PDF?

[英]How can I write Persian text to PDF programmatically?

我寫了一個程序來創建一個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();
}

有什么問題?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM