-1

I want to convert a Jekyll markdown page to PDF, but it doesn't work with Pandoc because I have used the Jekyll-scholar plugin to compile some bibtex citations. Using a browser to convert from html to pdf doesn't look good either. The source code is on my github repo. You can find the viat.md for the page which I want to convert to pdf. Let me know if there is a way to do the conversion. Thank you in advance!

Update on 2017-1-19: Here are some challenges if you think this question is trivial. Since I have used the Jekyll-scholar plugin, all my publication lists are called up in markdown by {% bibliography --file PublicationsFile --query @article %} format which cannot be recognized by Pandoc for markdown compiling; If I use a browser to save the HTML page as a pdf, then those buttons like "Download" and "Link" will appear as Download (https://downloadlinke.com) where I don't even want to have the meaningless Download buttons to show up in the pdf, and I want to have the links rendered for the article titles instead; finally, I certainly want to filter out the header, footer and sidebar from the HTML page for the pdf file. You can preview the vita page here and try out by yourself for working solutions. Ideally, I hope all of the works can be done automatically in Travis-CI for both my current HTML and a PDF version for downloading. Hopefully, you can point out some way to solve these problems.

Xiaodong Qi
  • 359
  • 6
  • 11
  • Is there any reason why you can't use Pandoc to convert the (Jekyll generated) HTML to PDF? – Waylan Jan 18 '17 at 19:23
  • Also, what specifically is the problem with the browser generated PDF? How do you expect any other tool to provide a better result? – Waylan Jan 18 '17 at 19:26
  • @Waylan, since I have used the Jekyll-scholar plugin, all my publication lists are called up in markdown by `{% file=xx.bib --all %}` format which cannot be recognized by Pandoc for markdown; if I use a browser to save the page as a pdf, then those buttons like "download" will appear as `Download (https://downloadlinke.com)` where I don't even want to have the meaningless Download buttons to show up in the pdf. I really don't know how to handle this. You can try by yourself on [my vita page](https://www.qixiaodong.tk/en/pubs/) for working options. I really appreciate your insights. – Xiaodong Qi Jan 20 '17 at 05:27

1 Answers1

2

Due to your Jekyll specific content, you will need use Jekyll to convert from Markdown to HTML. From there you can convert from HTML to PDF. You have a few options for how to accomplish that.

  1. You could create a custom Jekyll theme which does not include the page header/footer and other elements you don't want. Then tell Jekyll to use that custom theme before converting to PDF. For more info about Jekyll themes, see here.

  2. You could use the existing theme and define a print CSS stylesheet which hides the elements you do not want when printing. That way when you use your browsers print function, the page will display as you desire. You can find a few articles about this here and here.

  3. Combine both of the above for completely custom output.

Personally I would start with option 2 and work from there. Note that Pandoc has a --css option where you can point it as a CSS stylesheet to use to style HTML input as you desire.

Waylan
  • 37,164
  • 12
  • 83
  • 109
  • This seems requiring to duplicate a second markdown page with a different front matter which calls up the specific template and css style files under Jekyll. Could this be done without duplicating a markdown page in some automatic way? – Xiaodong Qi Jan 20 '17 at 18:26
  • Pandoc can convert directly from HTML to PDF. No need for duplicating your Markdown. Markdown to HTML with Jekyll and HTML to PDF with Pandoc. Unless Jekyll has some PDF plugin (which skips the HTML step), this is the only way you can use Jekyll specific stuff in your content. – Waylan Jan 20 '17 at 18:48
  • I mean, to generate the HTML page for the purpose of generating the PDF file from the markdown, I need to write the markdown page specifying the new template in the front matter (layout including the css definitions) using your method, which is an additional markdown page besides the one using my current layout to generate the HTML page not for generating PDF which I do need to keep. I feel this is redundant and there might be a way to generate the two different types of the HTML pages with a shared markdown file. But I am not sure how to do it. Appreciate your insight! – Xiaodong Qi Jan 20 '17 at 22:06
  • Ah I see. That is where the print stylesheet comes in. The browser will ignore the print stylesheet except when printing so you can define it in your "normal" template and it won't have any effect on how the pages look in the browser. As I stated before, that would be where I would start anyway. You should only need to explore the other options if that isn't enough. I expect it will work just fine. – Waylan Jan 21 '17 at 00:43
  • Ok. Let me think about it more carefully. I think not all those parts which I want to hide in print are defined as distinguishable classes. I guess I can redesign them in some way. Thank you for the hint. I will report back if this works out in the end. – Xiaodong Qi Jan 21 '17 at 04:42