Is there a way to print a single post in a topic, rather than the entire topic?
Not really, you can do something like https://meta.discourse.org/raw/79562/78
to get the raw markdown, but it’s raw markdown and not pretty.
I raised the question of better print support in today’s AMA session, here’s an old topic where I raised similar issues on META that I offered to revive. (I think there may have been a second one, too.)
Something that would allow selecting which posts to include when printing a thread would be very helpful.
Options for formatting of printed output would be helpful too, because good formatting for on-screen presentation isn’t necessarily the same thing as good formatting for printed output.
There is separate css for print.
Selective printing of posts is not something I’m sure how to do.
I did try to experiment with this. It kind of works, but it has some drawbacks I would need to address.
You would have different ways to print a post as PDF:
-
Using a third-party library that converts HTML to PDF (usually reads the HTML node, tries to clone the CSS, and generates a PDF from scratch (or it converts to a canvas, then a PDF) – Usually heavy and prone to limitations.
-
Opening a window and cloning HTML/CSS. Then, you trigger the OS print function for that window. Extracting/setting CSS properly seems unreliable/slow, doesn’t honor the print style, and the window may be blocked.
-
Using the native OS print function “Save to PDF”: – The main issue is telling the OS what to print.
(I did not investigate everything)
I tried the latter and found a CSS trick (not from me) that essentially isolates the post (meaning hiding everything else) and then programmatically runs the OS print function.
Demo:
Few issues as it is:
- You lose the previous post position when styles are unhidden.
- Sometimes, elements are not hidden fast enough before the print window is opened.
It’s a little tricky, but it works, and relying on the OS is a big prop, in my opinion.
Well, there’s a way for moderators to select posts when moving them, so the code for selecting posts already exists, what would (probably) be needed is a way to turn those selected posts into something printable.
That’s true! It should be possible to make that code callable for the print all function. If you have a budget and are self hosted (or on enterprise) it should be possible.
EDIT: Wait. Wait. Wait. As I remember, Control-P gives a view of an entire topic, but I tried it just now and it has just
I thought it might be something just on meta, but I tried a couple of other forums and it’s not providing all of the posts. This seems like a bug, but I obviously haven’t paid close attention to this in some years.
And what’s odd is if you’re NOT logged in, it seems to give you the whole topic. That’s still not what I’d like but it might be an improvement over just doing a print from within the browser.
This is a bug we noticed today already and a fix is in the works.
I shared the idea of selecting posts to print or export internally. No idea of if or when we will work on this but that something should be done is on our radar.