# HTML Printing

**URL:** <https://forum.inductiveautomation.com/t/html-printing/1189>\
**Category:** Archived Topics\
**Created:** [June 21, 2009, 4:13pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189 "2009-06-21T16:13:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [June 21, 2009, 4:13pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/1 "2009-06-21T16:13:00Z")

</div>

Ok, I have a html doc viewer component. If I do a “select all” and copy the window contents to a text document (i.e. to TextPad or WordPad), I get a plain text copy of what I see on the screen.

Is there a way to automate this? I tried the fpmi.print function, and I can create a pdf document, but that doesn’t help me because the resulting file has to be an editable text file. If I select the “generic/text only” driver and print to file, I just get an empty file. I assume there must be a way to print the clipboard contents or programatically select the contents, but I’m not getting it. Ideas?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [June 22, 2009, 6:38pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/2 "2009-06-22T18:38:04Z")

</div>

Hmm… this sounds hard. I think we can programatically select all, issue a copy action, and get hte clipboard contents, but first…

Aren’t you creating this document programatically? Why don’t you concurrently create a non-formatted version?

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [June 22, 2009, 7:56pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/3 "2009-06-22T19:56:01Z")

</div>

I could do that, but there is an awful lot going on behind the scenes with adding hyperlinks, highlighting, and hrefs on the fly. For instance, there are a lot of mathematical symbols, and as I create the html version, I have to make hex equivilents of things like ‘\<’ and ‘\>’’ so the html comes out right. I guess I coould build two files at once, but man, it was hard enough the first time. 🙂 I guess you’d have to see it.

I don’t know much about what is actually happening during a “select all”, so I just thought the doc component contents must be easily accessible somehow. If is isn’t, no big deal. I’ll see how much work it is to rip through my html doc and convert it to text. Maybe it’s easier than I thought.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [June 22, 2009, 10:16pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/4 "2009-06-22T22:16:08Z")

</div>

Ok, file this one under “try it before I say that its hard”.

Here you go,

[code]doc = event.source.parent.getComponent(“Document Viewer”).viewport.view  
doc.selectAll()  
doc.copy()

from java.awt import Toolkit  
from java.awt.datatransfer import DataFlavor

clipboard=Toolkit.getDefaultToolkit().getSystemClipboard()  
t = clipboard.getContents(None)  
print t.getTransferData(DataFlavor.stringFlavor)[/code]

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [June 23, 2009, 12:17am UTC](https://forum.inductiveautomation.com/t/html-printing/1189/5 "2009-06-23T00:17:23Z")

</div>

That is just so cool. I even added it to my quasi-tree control in the other thread, and can also now print html list output. I can’t say here exactly what I’m doing with this, but I just got done showing it to someone and it’s a real head-turner.

Thanks very much for your effort on this.

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [December 8, 2009, 5:15pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/6 "2009-12-08T17:15:12Z")

</div>

Ok, to take this one step further, I now have to write to the clipboard. Looking at the Java API, I have to use java.awt.datatransfer.Clipboard, but need an instance to pass in as the third argument. getDefaultToolkit() is used to satisfy this in the getSystemClipboard code, but I don’t know what to use with setContent. Here’s what I have so far:

```auto
Faults = 'This is a fault'
from java.awt import Toolkit
from java.awt.datatransfer import DataFlavor
from java.awt.datatransfer import Clipboard

clipboard=Toolkit.getDefaultToolkit().getSystemClipboard()
Clipboard.setContents(Faults,clipboard)
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [December 10, 2009, 10:57pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/7 "2009-12-10T22:57:31Z")

</div>

Try this:

[code]Faults = ‘This is a fault’  
from java.awt import Toolkit  
from java.awt.datatransfer import StringSelection

clipboard=Toolkit.getDefaultToolkit().getSystemClipboard()  
clipboard.setContents(StringSelection(Faults),None)[/code]

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [December 11, 2009, 5:51pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/8 "2009-12-11T17:51:06Z")

</div>

That works great. Thanks.

This is to replace a VB program that passes fault data to another program via the clipboard (hey, I didn’t design it). My fpmi project already had the fault data, so it really made sense to replace the VB app and get rid of the second Kepware instance.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [December 11, 2009, 5:58pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/9 "2009-12-11T17:58:18Z")

</div>

Yeah, sometimes you have to bring your elegance standards down to inter-operate, huh?

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [December 11, 2009, 6:32pm UTC](https://forum.inductiveautomation.com/t/html-printing/1189/10 "2009-12-11T18:32:58Z")

</div>

Yep, but it’s also nice to prove that I can replace any legacy stuff out there with minimal effort and without telling the customer “Sorry, but I can’t interface to that thing”.

Having access to the java libraries really opens up possibilities. I just have to get better at it.
