-13

I followed this/this to Print Receipts in part of POS(Point of Sale) from EPSON Printer

Here I am getting data Json from URL (inside the Json Object I am getting a html print template):

{
    "response": {
        "status": "<table>.... </table>"
    }
}

so with intent I used the above json response to a string and converted it to html:

method = "addFeedLine";
mPrinter.addFeedLine(1);

textData.append("Test print Sample string\n");**//this is sample text**

textData.append(Html.fromHtml(status + "\n"));
**//this is JSON response which is nothing but HTML code, so I am converting it to string**

Over there I have used status as a string so that whatever the content is inside that string, it is printed.

If it's is not a html but just a plain text I will print it like this

method = "addFeedLine";
mPrinter.addFeedLine(1);
textData.append(status);

Here is an example of what status looks like

"status": "The store list Sample\nSTORE DIRECTOR – XYZ\n01/01/01 16:58 6153 05 0191 134\nST# 21 OP# 001 TE# 01 TR# 747\n------------------------------\n400 OHEIDA 3PK SPRINGF 9.99 R\n410 3 CUP BLK TEAPOT 9.99 R\n445 EMERIL GRIDDLE/PAN 17.99 R\n438 CANDYMAKER ASSORT 4.99 R\n474 TRIPOD 8.99 R\n433 BLK LOGO PRNTED ZO 7.99 R\n458 AQUA MICROTERRY SC 6.99 R\n493 30 L BLK FF DRESS 16.99 R\n407 LEVITATING DESKTOP 7.99 R\n441 ** Blue Overprint P 2.99 R\n476 REPOSE 4 PCPM CHOC 5.49 R\n461 WESTGATE BLACK 25 59.99 R\n------------------------------\nSUBTOTAL 160.38\nTAX 14.43\nTOTAL 174.81\nCASH 200.00\nCHANGE 25.19\n------------------------------\nPurchased item total number\nSign Up and Save!\nWith Preferred Saving Card\n"

Now, here I have a plain HTML page:

Search Images Maps Play YouTube News Gmail Drive More »
Web History | Settings | Sign in

                  Louisa May Alcott’s 184th birthday

       [                                                         ] Advanced
                                                                   searchLanguage
                   [Google Search][I'm Feeling Lucky]              tools

 Advertising ProgrammesBusiness Solutions+GoogleAbout GoogleGoogle.com

                       © 2016 - Privacy - Terms

I need to print this from an url.

Can anyone suggest me how to print this plain text? There is no HTML tags and no JSON data.

2
  • those mentioned links are not accessible.. so better to post the name and proper description of the sdk you are using rather than referring the links like you did. Commented Dec 9, 2016 at 4:56
  • I have Updated Link at bottom we have download link of sdk.....All the Persons Who downvoted Please upvote and All the Answers People Please Upvote I have already loosed in bounty Commented Dec 10, 2016 at 10:30

4 Answers 4

1

By Html.fromHtml method you can convert HTML to String -

String strToHtml = Html.fromHtml(htmlContentInStringFormat)

Log.e(TAG,"strToHtml :: "+strToHtml);
Sign up to request clarification or add additional context in comments.

Comments

0

If you really want to print it like the html it really is, I recommend you to get the primary html code status (before parsing it and so on) and to push it into a WebView like this:

webview.loadDataWithBaseURL("", status, "text/html", "UTF-8", "");

Otherwise, if you just want to print it into the screen, you can use a simple TextView to do that by text_view.setText(textData.toString())

3 Comments

Yes I want to Print Not view... Its theremal Print
Please, explain yourself better. First of all, what do you mean by "Print" (is it to print in the screen? or to send it for a printing service?). Second of all, what do you mean when you say "or How to add this plain text to a string", cause you already have the "status" String. Do you really need to send the String to a given printing service?
I dont Konw how do you print Thermal print screen ?????? I said Its thermal Print and I followed EPSON thermal Printer SDK Here there is no webview
0

This is the original html value:

String  htmldescription = school2.getJSONObject(0).getString("description");

This is the html formatted value:

Spanned spanned = Html.fromHtml(formattedText);

And this is the String conversion:

String formattedText = spanned.toString();

Got it from here: how to save encoded html in string
If this doesn't work out you should check out the developer docs

Hope it Helps, Good Luck!

Comments

0

You can use a simple Regex to convert HTML template to a plain text. It detects all types of HTML tags, but there may be loopholes.

For example:

// Regex pattern
private static final String STR_PATTERN = "\\<[^\\>]*\\>";

public static String htmlToPlainText(final String template) {

  // replaceAll(String regex, String replacement)
  return (template.replaceAll(STR_PATTERN, ""));
}

I hope it helps

1 Comment

Actually Have URL I want to print the contents inside that url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.