question

ashwinipatil avatar image
ashwinipatil asked Raymond Lee Deactivated commented

How to make text bold while printing manual report data?

I am generating manually report data and able to print also using new TextPrintJob.Builder().text(textDSRReport(objDailyReps)).build().print(myContext, account); but now i wanted to make text bold in somewhere....How can i do text bold...plz help me...
Print
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Raymond Lee avatar image
Raymond Lee Deactivated answered Raymond Lee Deactivated commented
TextPrintJob.Builder() only accepts a string, so you cannot do bolded text using TextPrintJob.

What you can do instead is print a TextView using ViewPrintJob.Builder(), as that will let you customize and format the text inside the TextView however you want.

Here is some sample code for bolding the word "BOLD" in a string:

String str = "TEST BOLD TEST";
SpannableString spannableString = new SpannableString(str);
spannableString.setSpan(new StyleSpan(Typeface.BOLD), str.indexOf("BOLD"), str.indexOf("BOLD") + "BOLD".length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView tv = new TextView(getApplicationContext());
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, 30);
tv.setTextColor(Color.BLACK);
tv.setText(spannableString);

tv.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

new ViewPrintJob.Builder().view(tv).build().print(getApplicationContext(), mAccount);

I used a SpannableString to have only part of the String bolded, but you can use TextView.setTypeface(Typeface.BOLD) if you want the entire String bolded. Or you can use HTML.fromHtml(string) and pass in a html formatted string with <b> and </b> for the portions you want bolded. See: https://stackoverflow.com/questions/14371092/how-to-make-a-specific-text-on-textview-bold.

Hope that helps,

Raymond
2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bryanne Vega avatar image Bryanne Vega commented ·

Can I print a Layout view? How can I set that layout to be the length of the paper (Mini/Station) but my own height (in case it's a long receipt)?

I believe my question could be answered here @Raymond Lee

https://clover.cloud.answerhub.com/questions/10304/viewprintjob-centering-on-receipt.html

0 Likes 0 ·
Raymond Lee avatar image Raymond Lee Bryanne Vega commented ·

Yes, you can print a Layout view, and you can set the layout width to be 576 pixels for Clover Station, and 394 pixels for all other devices (width of receipt paper, see here), and the height to whatever you want.

I answered the question you linked with more details on ViewPrintJob as well.

0 Likes 0 ·

Welcome to the
Clover Developer Community