BVdjV
BVdjV

Reputation: 116

Print html portion into pdf using Java

community!

My project is simple: I have a link to a website that has multiple information on different chemical substances and I want to extract some data and put in into pdf. Thing is that I want to keep the formatting of the original HTML (using it's css, of course). Example of substance: http://www.molbase.com/en/msds_1659-31-0-moldata-2.html#tabs

I used jsoup to read the HTML of the table on the bottom of the page, the MSDS one, containing multiple sections with different information about the substance, but I really don't know how to save the exact HTML format into my pdf file. I have tried with iText too, but it gives me "missing ending tag" error, and if it worked, it would print the full page, not only that msds table.

Here is what I have tried to do, but ain't effective:

Document docu = Jsoup.connect(urlbun).get();
        Element tableHeader = docu.select("div[class=\"msds\"]")
                .first();
        String[] finSyn = tableHeader.text().split(" ");
        String moreText =" ";

I tried to split the text that the webpage has under that div ("class = "msds"") but I cannot find a way to split it the good way.

Please, could you please give me a hint on what to do? Even if the formating is not the same, I would like to be able to display the information in the same way, with indentation and such.

Thank you!

Upvotes: 0

Views: 694

Answers (1)

user1914292
user1914292

Reputation: 1556

You can put the content that you want to convert to PDF inside a CSS ID (such as a DIV) and then use the PDFmyURL API to convert only that section to PDF.

Please refer to this on our website about how to select pieces from a page to convert to PDF

Disclosure: I work for the company that owns this site

Upvotes: 1

Related Questions