Save/Export to PDF and internal links
Purchaser of Marked 1 and Marked 2 and very *non* technical user.
I would like to know if Marked 2 will support internal links on export/save to PDF. At the moment it does not appear to do so.
I can see that in this Forum there has been discussion about this and that it is possible using a utility such as wkhtlmltopdf to support internal linking (see attached file as to what I mean by an internal link).
But knowledge is too limited to work out by wkhtmltopdf can support internal linking but Marked 2 cannot.
Is this something that Marked 2 can do (or will be coming)?
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 06 Oct, 2013 02:38 PM
As mentioned in other discussions, it's a webkit bug, which is what Marked uses to display the preview and export PDFs. The bug has been fixed in the open source version of WebKit, but hasn't been integrated by Apple. When they do, it will work, but until then, not within Marked.
wkhtmltopdf uses it's own patched version of WebKit, which I may have to resort to at some point.
2 Posted by Victor Warner on 07 Oct, 2013 08:44 AM
Thank you for the explanation.
3 Posted by potsky on 23 Oct, 2013 09:45 PM
Perhaps available on Maverick with Safari 7 ?
Currently downloading the upgrade, I'll try tomorrow but it is a pity that readers can not jump on page 367 in the PDF !
4 Posted by Victor Warner on 24 Oct, 2013 07:02 AM
I tried with Mavericks and latest version of Marked (2.1/777): no difference.
5 Posted by potsky on 24 Oct, 2013 07:22 AM
What a shame...
6 Posted by potsky on 24 Oct, 2013 09:07 PM
Ok, it is not so hard to achieve I think...
I have downloaded
wkhtmltopdf
for mac os x from the googlecode page.I have saved my Marked document in HTML instead of PDF.
Then I execute this in a Terminal this command
./wkhtmltopdf marked.html output.pdf
I have something like this :
Then when I open my
output.pdf
, I have all images, links in the TOC are ok and better... I have a TOC on a drawer in Preview.app !!!3 problems :
So :
Could a Marked developer explain us how they convert the BREAK and how they manage font before feeding the safari converter ? Then I could code a small bash or python script to automate this process ?
Why don't you include
wkhtmltopdf
in the Marked binary and use it instead the Mac OSX built in version ?:-) I am happy because there is a solution !
Support Staff 7 Posted by Brett on 24 Oct, 2013 09:12 PM
1. Marked converts hr’s and <!—BREAK—> by replacing it with a div with style "page-break-before:always". This only works when Marked is printing to PDF, it wouldn’t necessarily translate to an exported HTML file. You could easily add (or shell convert) your own divs and embed the styles directly, though.
2. I’ve looked at solutions from Pandoc to wkhtmltopdf to wkpdf, but every time either size or license issues have been a problem. I’d consider adding an export processor, but there are so many options to consider when using those converters that it would require a lot of configuration on the user’s part. If you’re already capable of doing the conversion on the command line, it might just be prudent to export the html from Marked and have a Hazel process do the conversion via script…
That being said, I’ll look back into wihtmltopdf and see if it’s a feasible option.
8 Posted by potsky on 25 Oct, 2013 02:55 PM
Hi Brett,
thank you very much, it works like a charm, I just create a build process in Sublime Text and PDF are now perfect with a TOC and with a footer/header !
Just a curiosity : what do you use to convert the MD to HTML ? Pandoc ? If I could include this in my build keyboard shortcut, I will save a SAVE action in Marked :-)
Support Staff 9 Posted by Brett on 25 Oct, 2013 02:59 PM
I generally use Marked to do the conversion, but if I’m working from the command line I usually use MultiMarkdown or Kramdown.
-Brett
Support Staff 10 Posted by Brett on 25 Oct, 2013 02:59 PM
Or did you mean _in_ Marked? Marked by default uses MultiMarkdown 4, with the option to use Discount instead.
-Brett
11 Posted by potsky on 25 Oct, 2013 03:07 PM
Sorry :-)
I was talking about the Marked application...
I would like to change our current workflow on Mac OS X :
*.md
in Sublime TextI would like to have this workflow (especially for my colleagues) :
*.md
in Sublime TextThe Build now commit, pull, merge and push in the git repository, send emails to alert people to read the updated document, etc...
12 Posted by potsky on 25 Oct, 2013 03:09 PM
MultiMarkdown 4 is this ?
https://github.com/fletcher/MultiMarkdown-4
Support Staff 13 Posted by Brett on 25 Oct, 2013 07:55 PM
Correct on MultiMarkdown 4.
As far as the workflow goes, do you still want the output PDF to have Marked styles? If that’s the case, you’ll need to use a webkit-compatible PDF generator like wkhtmltopdf or wkpdf to do the build as a command line tool. You’ll need to export the CSS from your preferred or custom style and then include it via command line options with the CLI.
Most of Marked’s features, such as Table of Contents and pagination tweaks aren’t available without Marked running. If your needs are simple, though, a wkhtmltopdf workflow with included CSS may work fine.
14 Posted by JR on 07 Apr, 2015 03:43 PM
I am wondering if this has been resolved. I'm using Marked Version 2.4.11 (895), and when I generate a paginated PDF, the links within the document are visible but do not correctly link. If it hasn't been fixed, is there a workaround that can be employed?
Support Staff 15 Posted by Brett on 07 Apr, 2015 04:33 PM
There has been no change to WebKit's handling of intra-document links at this point. The only workaround would still be to export to HTML and use wkhtlm2pdf, but the same problems with certain syntax not being carried over will exist.
16 Posted by Cai on 09 Aug, 2016 01:31 PM
Yes, I would also like this. It's nice to put a table of contents at the start of PDF documentation created from markdown, but this is only useful with internal links.
17 Posted by Jon on 14 Oct, 2016 11:28 PM
I too need internal links in pdfs. It's the only issue I have with an otherwise great app.
18 Posted by torsten.louland on 18 May, 2017 01:55 PM
Looks like internal links have finally been fixed in webkit:
https://bugs.webkit.org/show_bug.cgi?id=112081
and
"Made printing to PDF produce internal links when the HTML has internal links"
...from https://developer.apple.com/safari/technology-preview/release-notes/
Any chance you can integrate this Marked 2 early?
Support Staff 19 Posted by Brett on 18 May, 2017 05:22 PM
Yeah, that update to the webkit source was made almost 2 years ago now,
but Apple still hasn't incorporated it into the SDK version. In order to
implement it in Marked, I'd have to include a custom webkit, which would
basically mean putting a whole copy of Safari into it. The download size
would go up by 500% and it's just not feasible for me to maintain a
codebase that's split off from the SDK.
-Brett
20 Posted by torsten.louland on 18 May, 2017 08:29 PM
Hmmm...
"Made printing to PDF produce internal links when the HTML has internal links" was in release 18 of the Safari technology preview and we're now at release 30. I downloaded it and gave File>Export as PDF… and File>Print…>Save as PDF… a try:
- in a web page with plain unqualified #fragment links within the page, those links come out as URL links in the generated PDF, rather that internal PDF links (/GoTo actions) — bad :-(
- when I open a local HTML file (generated by Marked 2 & containing internal links) the internal #fragment links remain as internal links in the generated PDF — good the bug is indeed fixed.
Then I cross-checked with latest Safari (10.1 on Sierra 10.12.4), and that gave the same behaviour. Does it uses its own more recent webkit? Hard to tell, given the obfuscation inside the bundle. Security-wise it would not make sense to have Safari use a different webkit to the rest of the system - that could allow Safari to have some security fixes that were not available to the rest of the system - they would never do that.
So… is there a possibility that the ability to generate internal links in PDFs is already present in webkit on Sierra, and that Marked 2 is not for some reason benefiting from it? (Perhaps some trick needed to engage it.)
Worth some digging and/or a radar?
Support Staff 21 Posted by Brett on 24 May, 2017 04:23 PM
Safari does use a different webkit than is available in the SDK, though
I should note that Marked runs on the original WebKit and not the
WKWebView that was introduced more recently. I'll take another look at
switching that over and see if it makes a difference (it didn't
previously, and it was a lot of re-coding to adopt the new API for
that).
-Brett
22 Posted by mantoine.mac on 12 Jul, 2017 04:13 PM
Here's a simple workflow I came up with to work around Marked2 limitation.
I post it here for others to use and (why not) improve. Plus (hopefully) it could provide new clues for Brett to implement internal links to PDF exports.
Here it is :
The resulting PDF includes fully functional internal links.
This might not work with any browser though. I've successfully tested it with Safari, but I prefer Vivaldi (or Chrome) because it allows me to set page margins right into de print dialog.
As an aside, I include page breaks in the Markdown document as HTML :
There are other ways to achieve page breaks but this one doesn't require any modification to the CSS.