我正在使用 Android 的内置PrintedPdfDocument使用 Canvas 绘制 PDF,如本文档示例代码中所述:private void drawPage(PdfDocument.Page page) { Canvas canvas = page.getCanvas(); // units are in points (1/72 of an inch) int titleBaseLine = 72; int leftMargin = 54; Paint paint = new Paint(); paint.setColor(Color.BLACK); paint.setTextSize(36); canvas.drawText("Test Title", leftMargin, titleBaseLine, paint); paint.setTextSize(11); canvas.drawText("Test paragraph", leftMargin, titleBaseLine + 25, paint); paint.setColor(Color.BLUE); canvas.drawRect(100, 100, 172, 172, paint);}是否可以在此文档中添加表情符号文本?我不知道如何设置字符集/编码。每当我尝试添加表情符号输出时,它都会在 pdf 中显示为乱码。这是保存pdf的代码:mPdfDocument = new PrintedPdfDocument(context, printAttributes);mCurrentPage = mPdfDocument.startPage(1);Canvas canvas = mCurrentPage.getCanvas();... // add stuff to canvasmPdfDocument.finishPage(mCurrentPage);FileOutputStream fos = new FileOutputStream(new File(path));mPdfDocument.writeTo(fos);fos.close();谢谢!
2 回答
冉冉说
TA贡献1877条经验 获得超1个赞
使用表情符号的 unicode 值创建一个字符串。然后将字符串传递给 drawText 方法:
String smileyFace = new String(Character.toChars(0x1F603))); //0x1F603 = Smile emoji
canvas.drawText(smileyFace, leftMargin, titleBaseLine, paint);
添加回答
举报
0/150
提交
取消