简体   繁体   中英

How to make the custom printed document in android studio direction rtl not ltr?

I am creating a simple custom PDF document to send it to printer.
I reached a phase where I can write on the document but I want it to be from right to left. this is the code of the function that writes the document:

private void drawPage(PdfDocument.Page page,int pagenumber)
{
Canvas canvas = page.getCanvas();


pagenumber++; // Make sure page numbers start at 1

int titleBaseLine = 72;
int leftMargin = 54;

Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(40);
canvas.drawText("Costumer Inventory Information",leftMargin,titleBaseLine,paint);

paint.setTextSize(14);
canvas.drawText("שם פרטי: "+ tmp.get(0).firstname, leftMargin, titleBaseLine + 35, paint);

canvas.drawText("שם משפחה: "+ tmp.get(0).secondname, leftMargin, titleBaseLine + 70, paint);
canvas.drawText("ת.ז.: "+ tmp.get(0).idNumber, leftMargin, titleBaseLine + 105, paint);
canvas.drawText("מספר פניה: "+ tmp.get(0).callNumber, leftMargin, titleBaseLine + 145, paint);
canvas.drawText("סוג תקלה: "+ tmp.get(0).faultType, leftMargin, titleBaseLine + 180, paint);
canvas.drawText("תאריך: "+ tmp.get(0).date, leftMargin, titleBaseLine + 215, paint);

}

Can anyone tell me how to draw or write in another way from right to left?

Although it is not the perfect answer, you could rotate the text:

https://stackoverflow.com/a/14294899/5249209

Also, you could set the letter to be written in any position. Therefore, it is possible to get the letter width and place it on the left from the previous one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM