Pandoc html to pdf

Step 2: Open a terminal

Pandoc is a command-line tool. There is no graphic user interface. So, to use it, you’ll need to open a terminal window:

  • On OS X, the Terminal application can be found in /Applications/Utilities . Open a Finder window and go to Applications , then Utilities . Then double click on Terminal . (Or, click the spotlight icon in the upper right hand corner of your screen and type Terminal – you should see Terminal under Applications .)
  • On Windows, you can use either the classic command prompt or the more modern PowerShell terminal. If you use Windows in desktop mode, run the cmd or powershell command from the Start menu. If you use the Windows 8 start screen instead, simply type cmd or powershell , and then run either the “Command Prompt” or “Windows Powershell” application. If you are using cmd , type chcp 65001 before using pandoc, to set the encoding to UTF-8.
  • On Linux, there are many possible configurations, depending on what desktop environment you’re using:
    • In Unity, use the search function on the Dash , and search for Terminal . Or, use the keyboard shortcut Ctrl-Alt-T .
    • In Gnome, go to Applications , then Accessories , and select Terminal , or use Ctrl-Alt-T .
    • In XFCE, go to Applications , then System , then Terminal , or use Super-T .
    • In KDE, go to KMenu , then System , then Terminal Program (Konsole) .

    You should now see a rectangle with a “prompt” (possibly just a symbol like % , but probably including more information, such as your username and directory), and a blinking cursor.

    Let’s verify that pandoc is installed. Type

    and hit enter. You should see a message telling you which version of pandoc is installed, and giving you some additional information.

    Step 3: Changing directories

    First, let’s see where we are. Type

    on Windows, and hit enter. Your terminal should print your current working directory. (Guess what pwd stands for?) This should be your home directory.

    Let’s navigate now to our Documents directory: type

    (or echo %cd% on Windows) again. You should be in the Documents subdirectory of your home directory. To go back to your home directory, you could type

    Go back to your Documents directory if you’re not there already. Let’s try creating a subdirectory called pandoc-test :

    Now change to the pandoc-test directory:

    If the prompt doesn’t tell you what directory you’re in, you can confirm that you’re there by doing

    OK, that’s all you need to know for now about using the terminal. But here’s a secret that will save you a lot of typing. You can always type the up-arrow key to go back through your history of commands. So if you want to use a command you typed earlier, you don’t need to type it again: just use up-arrow until it comes up. Try this. (You can use down-arrow as well, to go the other direction.) Once you have the command, you can also use the left and right arrows and the backspace/delete key to edit it.

    Most terminals also support tab completion of directories and filenames. To try this, let’s first go back up to our Documents directory:

    and hit the tab key instead of enter. Your terminal should fill in the rest ( test ), and then you can hit enter.

    • pwd (or echo %cd% on Windows) to see what the current working directory is.
    • cd foo to change to the foo subdirectory of your working directory.
    • cd .. to move up to the parent of the working directory.
    • mkdir foo to create a subdirectory called foo in the working directory.
    • up-arrow to go back through your command history.
    • tab to complete directories and file names.

    Step 4: Using pandoc as a filter

    and hit enter. You should see the cursor just sitting there, waiting for you to type something. Type this:

    When you’re finished (the cursor should be at the beginning of the line), type Ctrl-D on OS X or Linux, or Ctrl-Z followed by Enter on Windows. You should now see your text converted to HTML!

    What just happened? When pandoc is invoked without specifying any input files, it operates as a “filter,” taking input from the terminal and sending its output back to the terminal. You can use this feature to play around with pandoc.

    By default, input is interpreted as pandoc markdown, and output is HTML. But we can change that. Let’s try converting from HTML to markdown:

    and hit Ctrl-D (or Ctrl-Z followed by Enter on Windows). You should see:

    Now try converting something from markdown to LaTeX. What command do you think you should use?

    Step 5: Text editor basics

    You’ll probably want to use pandoc to convert a file, not to read text from the terminal. That’s easy, but first we need to create a text file in our pandoc-test subdirectory.

    Important: To create a text file, you’ll need to use a text editor, not a word processor like Microsoft Word. On Windows, you can use Notepad (in Accessories ). On OS X, you can use TextEdit (in Applications ). On Linux, different platforms come with different text editors: Gnome has GEdit , and KDE has Kate .

    Start up your text editor. Type the following:

    --- title: Test . # Test! This is a test of *pandoc*. - list one - list two

    Now save your file as test1.md in the directory Documents/pandoc-test .

    Step 6: Converting a file

    Go back to your terminal. We should still be in the Documents/pandoc-test directory. Verify that with pwd .

    (or dir if you’re on Windows). This will list the files in the current directory. You should see the file you created, test1.md .

    To convert it to HTML, use this command:

    pandoc test1.md -f markdown -t html -s -o test1.html

    The filename test1.md tells pandoc which file to convert. The -s option says to create a “standalone” file, with a header and footer, not just a fragment. And the -o test1.html says to put the output in the file test1.html . Note that we could have omitted -f markdown and -t html , since the default is to convert from markdown to HTML, but it doesn’t hurt to include them.

    Check that the file was created by typing ls again. You should see test1.html . Now open this in a browser. On OS X, you can type

    You should see a browser window with your document.

    To create a LaTeX document, you just need to change the command slightly:

    pandoc test1.md -f markdown -t latex -s -o test1.tex

    Try opening test1.tex in your text editor.

    Pandoc can often figure out the input and output formats from the filename extensions. So, you could have just used:

    pandoc test1.md -s -o test1.tex

    Pandoc knows you’re trying to create a LaTeX document, because of the .tex extension.

    Now try creating a Word document (with extension docx ).

    If you want to create a PDF, you’ll need to have LaTeX installed. (See MacTeX on OS X, MiKTeX on Windows, or install the texlive package on Linux.) Then do

    pandoc test1.md -s -o test1.pdf

    Step 7: Command-line options

    Here’s an example. The —mathml option causes pandoc to convert TeX math into MathML. Type

    then enter this text, followed by Ctrl-D ( Ctrl-Z followed by Enter on Windows):

    Now try the same thing without —mathml . See the difference in output?

    If you forget an option, or forget which formats are supported, you can always do

    to get a list of all the supported options.

    On OS X or Linux systems, you can also do

    to get the pandoc manual page. All of this information is also in the User’s Guide.

    If you get stuck, you can always ask questions on the pandoc-discuss mailing list. But be sure to check the FAQs first, and search through the mailing list to see if your question has been answered before.

    Источник

    How to Convert Documents With Pandoc

    According to official site, Pandoc is your swiss-army knify to convert files from one markup format into another.

    Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, TWiki markup, OPML, Emacs Org-Mode, Txt2Tags, Microsoft Word docx, EPUB, or Haddock markup to

    • HTML formats: XHTML, HTML5, and HTML slide shows using Slidy, reveal.js, Slideous, S5, or DZSlides.
    • Word processor formats: Microsoft Word docx, OpenOffice/LibreOffice ODT, OpenDocument XML
    • Ebooks: EPUB version 2 or 3, FictionBook2
    • Documentation formats: DocBook, GNU TexInfo, Groff man pages, Haddock markup
    • Page layout formats: InDesign ICML
    • Outline formats: OPML
    • TeX formats: LaTeX, ConTeXt, LaTeX Beamer slides
    • PDF via LaTeX
    • Lightweight markup formats: Markdown, reStructuredText, AsciiDoc, MediaWiki markup, DokuWiki markup, Emacs Org-Mode, Textile
    • Custom formats: custom writers can be written in lua.

    How to Install Pandoc

    As for Windows users, download a package installer at pandoc’s download page and install on your computer. After that, run pandoc -v in command prompt to verify if it is correctly installed.

    NOTE: The default package doesn’t support PDF output, additional tool LaTeX is needed. MiKTeX is recommended by official site. However, it does have some issues with Chinese characters exporting. In this case, CTeX Full instead is a better choice.

    For users of Mac OS X or Linux, refer to offcial site for more information about installation.

    How to Convert Document With Pandoc

    pandoc -f html -t docx -o savefile.docx http://www.baidu.com
    pandoc -f html -t markdown -o savefile.md fromfile.html
    pandoc -f html -t latex -o savefile.pdf fromfile.html pandoc -o savefile.pdf fromfile.html
    pandoc -f markdown_github -t mediawiki -o savefile.wiki fromfile.md

    How to Export Document with Chinese Characters to PDF

    If your task is all about documents with English characters only, you can skip this section. This part talks about problems of exporting documents with Chinese characters to PDF.

    1. Install CTeX Full instead of MiKTeX
    2. Define template Export Pandoc standard template using the following command:
    pandoc -D latex > template.tex

    Open the template template.tex and find phrase % if luatex or xelatex , add the code below after this phrase.

    % SUPPORT for Chinese \usepackage[boldfont,slantfont,CJKsetspaces,CJKchecksingle] \usepackage \defaultfontfeatures \punctstyle \setCJKmainfont \setCJKsansfont \setCJKmonofont

    Note:
    In my version of Pandoc(1.13.2), below is the default code after phrase % if luatex or xelatex .

    20. \else % if luatex or xelatex 21. \ifxetex 22. \usepackage 23. \usepackage 24. \else 25. \usepackage 26. \fi 27. 28. \defaultfontfeatures 29. \newcommand

    Errors occur if just add code after Line#20. Finally, it turns out to be OK to add the code at Line#27.

    pandoc -o savefile.pdf fromfile.html --latex-engine=xelatex --template=template.tex

    Thanks to this blog for solving the problem.

    According to another blog, it’s also possible to download pm-template.latex and use this template to export documents to PDF. For this template, the only thing needs to be noticed is, replace LiHei Pro to a Chinese font you have installed in your machine.

    Pandoc’s Markdown

    Pandoc’s author is really proud of its extension of markdown, or he wouldn’t put 2/3 of the document talking about it.

    How to Produce Slide Shows with Pandoc

    It’s fantastic to find that simple and concise slides can be made by Pandoc. One could keep collecting knowledges while occasionly transform them to slides to share with other people, without put so much time considering how to write PPT.

    This is a magic phrase. You CANNOT see it(I’ll really FULE you if you do that), but it does work. Why? You may feel confused. OK, at least it doesn’t afftect your experience and it works. That is what we call MAGICE!

    Hosted on GitHub Pages — Theme by orderedlist

    Источник

    Читайте также:  Python 64 bit window
Оцените статью