Insert page break when using "markdown-pdf" nodejs module? - node.js

I'm using the node.js module "Markdown-PDF" (https://www.npmjs.com/package/markdown-pdf, version 9.0) to covert markdown to PDF, and I need to add a few page breaks to clean up the presentation in the PDF output.
I tried all the recommendations I could find on this and other forums, including inline HTML tags such as:
<div style="page-break-after: always;"></div>
And some CSS hacks, like applying page breaks to all div tags (as described here: http://forums.apricitysoftware.com/t/include-pdf-pagebreak-instructions-in-markdown/152). None of these are working, all tags in the markdown (source) document appear in the PDF (output) document un-rendered.
Expected (ideal) behavior would be to add the page breaks to the markdown files, and have the PDF reflect the desired changes. Something like this, within my markdown files:
markdown text
markdown text
markdown text
[page break command]
markdown text
markdown text
markdown text
Thanks in advance for any assistance or suggestions that anyone can provide!

Got an assist from a friend and figured this out. Markdown-pdf uses HTML5Boilerplate, so you can edit the index.html file, found here on my system:
/usr/local/lib/node_modules/markdown-pdf/html5bp/index.html
I added the CSS described here: http://forums.apricitysoftware.com/t/include-pdf-pagebreak-instructions-in-markdown/152
And it worked. Was able to include the HTML tags described in the post and force page breaks. Success!

The styled div tag you mentioned only works if the html parameter of remarkable object is set to true in options parameter:
var markdownpdf = require("markdown-pdf")
, fs = require("fs")
let options = {
paperFormat: "A4",
paperOrientation: "landscape",
remarkable: {
html: true
}
}
fs.createReadStream("teste.md")
.pipe( markdownpdf( options))
.pipe( fs.createWriteStream("document.pdf"))
In order to use a md marker (instead of using html div tag), I guess you should use preProcessMd and change a specific pattern to the styled div tag.
Hope I could offer some help!

Related

JODIT displays content with html tags after editing in React js

I am working with Jodit editor on a react project. When I create a note and send to database, and displays the note, it displays fine, but when I try to edit the content and save, the rendered text/content now contains some html tags and this "<p><". I have tried using renderHTML to convert it to only plain text, but that doesn't seem to work. I really need help on converting to plain text alone. The render renderHTML works fine when creating a new note, but doesn't convert to plain text when I try to edit the content.
Before you use the Jodit contents in a non-Jodit environment, you'll need to use a utility that converts the HTML tags.
One library that does this already is html-to-text.
On the backend, the actual code is as simple as
const { conversion } = require('html-to-text');
let adjustedText = conversion('<p>Your string of HTML code here</p>');
... unless you want to feed optional parameters to the conversion() function, like wordwrap. See html-to-text documentation for that.

weasyprint: change href link formatting in PDF

I am using weasyprint 56.1 with django-weasyprint 2.1.0, with vanilla settings.
When my HTML contains an ordinary hyperlink of the form
my link text
I want weasyprint to generate PDF that looks like
my link text
and where that text is a hyperlink to https://example.com.
However, what I get instead is the following format:
my link text (https://example.com)
where both parts are hyperlinked.
The link is correct and works, but I do not want the URL to show.
I could not find anything about this in the weasyprint documentation.
I just spent an hour in the weasyprint source code trying to find the spot where this formatting happens, but to no avail.
What logic is responsible for this formatting and how can I change it?
This isn't an answer to the question you asked, but I had the same issue, and then realized that in my CSS I had this artifact from a template:
a[href]:after {
content: " (" attr(href) ")";
}

Is there a way to generate PDF from specific HTML elements with CSS using Puppeteer?

I am trying to generate a PDF (as an A4 page) from a specific div in my HTML page along with it's style. Is there a way to do that without using addStyleTag? There is a lot of style and addStyleTag simply won't work.
Thank you.

Weasyprint output format issue - how to use CSS #page?

I used to use wkhmtltopdf to print some webpages but unfortunately it doesn't work anymore with some modern websites.
I found weasyprint which I tried in command line. The output has all the contents but text is cropped probably due to page size.
The website tells this is customizable in CSS (https://weasyprint.readthedocs.io/en/stable/tutorial.html#adjusting-document-dimensions). I'm not a web expert and don't really know what to do here. Should I copy and edit the source code of the webpage ? Where should it be inserted then ?
Here is sample webpage I'd like to print properly as a pdf:
https://korben.info/8-clients-alternatifs-pour-spotify.html
Has anyone succeeded in proper printing with weasyprint ?
Thank you for your help.
Adjusting Document Dimensions
Currently, WeasyPrint does not provide support for adjusting page size or document margins via command-line flags. This is best accomplished with the CSS #page at-rule. Consider the following example:
#page {
size: Letter; /* Change from the default size of A4 */
margin: 2.5cm; /* Set margin on each page */
}
#page is a CSS media query, so you have to write down the code in a .css file.
Once done you can call
weasyprint -s path/to/css/file input output
Notice that complex pages are usually bad rendered by weasyprint, as there are few not-supported style tags (calc, var, overflow on precise axis, ecc..).
Let me say that working like taht is a mess, if you need to do complex things consider to use weasyprint as a Python lib and not in standalone mode, so you can process sources and achieve better results in whatever you need to do.
Hope it helps.
Hele.

Delete Html entities or replace tag

when i display ckeditor text the html tags are also displayed. how can a i show only the text? i'm getting this:
<b>Paragraph</b>
Paragraph
I use Jade template and node.
It's possible to delete Tag before save in database ? or remove tag after ?
Thanks.
I found a solution.
Juste use !{value} instead of #{value} with Jade template to decode html entities.
value contains html entities.
use unescape syntax in the pug file.
p
!= 'This code is <strong>not</strong> escaped!'
or
- var riskyBusiness = "<em>This code is <strong>not</strong> escaped!</em>";
.quote
p Joel: !{riskyBusiness}

Resources