How do I obtain html of the current page (with dynamic data)?

Hi,

I’m trying to send html of a page (with dynamic data) to a PDF-print service. I see many variables that I can send, but which variable contains the STANDALONE html of the page/section/div/whatever that I can send (STANDALONE, without the external PDF-print service having to refer back to Weweb) ?

Best regards,
Thijs

Hey @thijs :wave:

Not sure how your PDF service works but you can get the current page’s HTML with some custom code.
wwLib.getFrontDocument().documentElement.outerHTML

Hi @jptrinh,

Thank you, this is perfect!

Is there a way to limit this function to just a specific section/div (and everything therein contained) of the webpage?

Perhaps I have to mark certain HTML attributes of the section/div ? And then refer to that in the code?

Nice! Yes, you can add a specific id, class or attribute in the Settings pannel of an element :slight_smile:

Hi @jptrinh,

I would expect that, but I don’t know how exactly to do that… can you help me with:

  1. Can I just name any field-type within the HTML attributes? For example, if I give the Id a name is fine?
    image

  2. How do I adjust the code that you provided to apply only to that attribute?
    wwLib.getFrontDocument().documentElement.outerHTML

Thank you!

Yes, that’s the correct way of adding an id to an element.

Then the selector can be adjusted to query the id like this:
wwLib.getFrontDocument().querySelector("#printpagina1").outerHTML

Hi @jptrinh,

Thank you very much, but somehow the selector (to query the id) changes the document into an inconsistent mess (too many things: layout, margins, font type). Do you recognize this might be an issue - and how to resolve this?

I can’t use the selector this way, but it would mean to me the difference between automation in the background vs. (now) having to open the print-section into a new tab to be able to use the wwLib.getFrontDocument().documentElement.outerHTML

Hopefully there is a fix for getting a true clean HTML print of a section?

Regards,
Thijs