tag:support.markedapp.com,2011-09-11:/discussions/questions/3598-saveexport-to-pdf-and-internal-linksMarked: Discussion 2017-07-12T16:14:41Ztag:support.markedapp.com,2011-09-11:Comment/292259212013-10-06T14:38:08Z2013-10-06T14:38:08ZSave/Export to PDF and internal links<div><p>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.</p>
<p>wkhtmltopdf uses it's own patched version of WebKit, which I may
have to resort to at some point.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212013-10-07T08:44:01Z2013-10-07T08:44:01ZSave/Export to PDF and internal links<div><p>Thank you for the explanation.</p></div>Victor Warnertag:support.markedapp.com,2011-09-11:Comment/292259212013-10-23T21:45:39Z2013-10-23T21:45:39ZSave/Export to PDF and internal links<div><p>Perhaps available on Maverick with Safari 7 ?</p>
<p>Currently downloading the upgrade, I'll try tomorrow but it is a
pity that readers can not jump on page 367 in the PDF !</p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-24T07:02:14Z2013-10-24T07:02:15ZSave/Export to PDF and internal links<div><p>I tried with Mavericks and latest version of Marked (2.1/777):
no difference.</p></div>Victor Warnertag:support.markedapp.com,2011-09-11:Comment/292259212013-10-24T07:22:12Z2013-10-24T07:22:12ZSave/Export to PDF and internal links<div><p>What a shame...</p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-24T21:07:25Z2013-10-24T21:07:25ZSave/Export to PDF and internal links<div><p>Ok, it is not so hard to achieve I think...</p>
<p>I have downloaded <code>wkhtmltopdf</code> for mac os x from the
googlecode page.<br>
I have saved my Marked document in HTML instead of PDF.</p>
<p>Then I execute this in a Terminal this command
<code>./wkhtmltopdf marked.html output.pdf</code><br>
I have something like this :<br></p>
<pre>
<code>(potsky@rb-macbookpro:~)$ cd Desktop/
(potsky@rb-macbookpro:~/Desktop)$ cd wkhtmltopdf.app/Contents/MacOS/
(potsky@rb-macbookpro:~/Desktop/wkhtmltopdf.app/Contents/MacOS)$ ./wkhtmltopdf ~/Desktop/ma
MacBookPro.png marked.html
(potsky@rb-macbookpro:~/Desktop/wkhtmltopdf.app/Contents/MacOS)$ ./wkhtmltopdf ~/Desktop/marked.html ~/Desktop/marked.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
(potsky@rb-macbookpro:~/Desktop/wkhtmltopdf.app/Contents/MacOS)$</code>
</pre>
<p>Then when I open my <code>output.pdf</code>, I have all images,
links in the TOC are ok and better... I have a TOC on a drawer in
Preview.app !!!</p>
<p>3 problems :</p>
<ul>
<li>the font of my css is not ok, perhaps I have to include it
somewhere</li>
<li>the Marked rule <em>Replace HR with page breaks</em> does not
work</li>
<li>keyword <em><!--BREAK--></em> does not work</li>
</ul>
<p>So :</p>
<ol>
<li>
<p>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
?</p>
</li>
<li>
<p>Why don't you include <code>wkhtmltopdf</code> in the Marked
binary and use it instead the Mac OSX built in version ?</p>
<ul>
<li>If it is a licence problem, perhaps could you include an option
named <em>Path to the pdf converter</em> and use it instead ?</li>
</ul>
</li>
</ol>
<p>:-) I am happy because there is a solution !</p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-24T21:12:28Z2013-10-24T21:12:28ZSave/Export to PDF and internal links<div><ol>
<li>
<p>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.</p>
</li>
<li>
<p>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…</p>
<p>That being said, I’ll look back into wihtmltopdf and see
if it’s a feasible option.</p>
</li>
</ol></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T14:55:49Z2013-10-25T14:55:49ZSave/Export to PDF and internal links<div><p>Hi Brett,</p>
<p>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 !</p>
<p>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 :-)</p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T14:59:34Z2013-10-25T14:59:34ZSave/Export to PDF and internal links<div><p>I generally use Marked to do the conversion, but if I’m
working from the command line I usually use MultiMarkdown or
Kramdown.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T14:59:59Z2013-10-25T14:59:59ZSave/Export to PDF and internal links<div><p>Or did you mean <em>in</em> Marked? Marked by default uses
MultiMarkdown 4, with the option to use Discount instead.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T15:07:36Z2013-10-25T15:07:36ZSave/Export to PDF and internal links<div><p>Sorry :-)<br>
I was talking about the Marked application...</p>
<p>I would like to change our current workflow on Mac OS X :</p>
<ul>
<li>I write some <code>*.md</code> in Sublime Text</li>
<li>When I save in ST, Marked is refreshed, perfect</li>
<li>I save as HTML in Marked</li>
<li>Then come back in ST to <em>Build</em> the PDF from the HTML
generated by Marked</li>
</ul>
<p>I would like to have this workflow (especially for my
colleagues) :</p>
<ul>
<li>They write some <code>*.md</code> in Sublime Text</li>
<li>When they save in ST, Marked is refreshed, perfect</li>
<li>They <em>Build</em> the PDF in ST from the MD and not from the
HTML generated by Marked</li>
</ul>
<p>The <em>Build</em> now commit, pull, merge and push in the git
repository, send emails to alert people to read the updated
document, etc...</p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T15:09:28Z2013-10-25T15:09:28ZSave/Export to PDF and internal links<div><p><em>MultiMarkdown 4</em> is this ?</p>
<p><a href=
"https://github.com/fletcher/MultiMarkdown-4">https://github.com/fletcher/MultiMarkdown-4</a></p></div>potskytag:support.markedapp.com,2011-09-11:Comment/292259212013-10-25T19:55:04Z2013-10-25T19:55:04ZSave/Export to PDF and internal links<div><p>Correct on MultiMarkdown 4.</p>
<p>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.</p>
<p>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.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212015-04-07T15:43:46Z2015-04-07T15:43:47ZSave/Export to PDF and internal links<div><p>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?</p></div>JRtag:support.markedapp.com,2011-09-11:Comment/292259212015-04-07T16:33:38Z2015-04-07T16:33:38ZSave/Export to PDF and internal links<div><p>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.</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212016-08-09T13:31:05Z2016-08-09T13:31:06ZSave/Export to PDF and internal links<div><p>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.</p></div>Caitag:support.markedapp.com,2011-09-11:Comment/292259212016-10-14T23:28:44Z2016-10-14T23:28:46ZSave/Export to PDF and internal links<div><p>I too need internal links in pdfs. It's the only issue I have
with an otherwise great app.</p></div>Jontag:support.markedapp.com,2011-09-11:Comment/292259212017-05-18T13:55:01Z2017-05-18T13:55:01ZSave/Export to PDF and internal links<div><p>Looks like internal links have finally been fixed in webkit:</p>
<p><a href="https://bugs.webkit.org/show_bug.cgi?id=112081">https://bugs.webkit.org/show_bug.cgi?id=112081</a></p>
<p>and</p>
<pre>
<code>"Made printing to PDF produce internal links when the HTML has internal links"</code>
</pre>
<p>...from <a href="https://developer.apple.com/safari/technology-preview/release-notes/">https://developer.apple.com/safari/technology-preview/release-notes/</a></p>
<p>Any chance you can integrate this Marked 2 early?</p></div>torsten.loulandtag:support.markedapp.com,2011-09-11:Comment/292259212017-05-18T17:22:10Z2017-05-18T17:22:10ZSave/Export to PDF and internal links<div><p>Yeah, that update to the webkit source was made almost 2 years ago now,<br>
but Apple still hasn't incorporated it into the SDK version. In order to<br>
implement it in Marked, I'd have to include a custom webkit, which would<br>
basically mean putting a whole copy of Safari into it. The download size<br>
would go up by 500% and it's just not feasible for me to maintain a<br>
codebase that's split off from the SDK.</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212017-05-18T20:29:34Z2017-05-18T20:29:34ZSave/Export to PDF and internal links<div><p>Hmmm...</p>
<p>"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.</p>
<p>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.</p>
<p>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.)</p>
<p>Worth some digging and/or a radar?</p></div>torsten.loulandtag:support.markedapp.com,2011-09-11:Comment/292259212017-05-24T16:23:25Z2017-05-24T16:23:25ZSave/Export to PDF and internal links<div><p>Safari does use a different webkit than is available in the SDK, though<br>
I should note that Marked runs on the original WebKit and not the<br>
WKWebView that was introduced more recently. I'll take another look at<br>
switching that over and see if it makes a difference (it didn't<br>
previously, and it was a lot of re-coding to adopt the new API for<br>
that).</p>
<p>-Brett</p></div>Bretttag:support.markedapp.com,2011-09-11:Comment/292259212017-07-12T16:13:27Z2017-07-12T16:14:41ZSave/Export to PDF and internal links<div><p>Here's a simple workflow I came up with to work around Marked2 limitation.</p>
<p>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.</p>
<p>Here it is :</p>
<ul>
<li>export from Marked2 as HTML (Cmd-S)</li>
<li>open the resulting HTML file in your web browser of choice</li>
<li>Print to PDF...</li>
</ul>
<p>The resulting PDF includes fully functional internal links.</p>
<p>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.</p>
<p>As an aside, I include page breaks in the Markdown document as HTML :</p>
<pre>
<code><div style="page-break-after: always;"></div></code>
</pre>
<p>There are other ways to achieve page breaks but this one doesn't require any modification to the CSS.</p></div>mantoine.mac