DEV Community

Claudio Fior
Claudio Fior

Posted on

4 1

Create ebook on the fly with php and pandoc

I'm digitalizing the Italian flora in the web site http://www.florae.it, but Internet is not everywhere so I produce and epub and I read it with Kobo ereader.

The trick is produce a text file formatted as Markdown

#### Sp. Phalaris canariensis {#t2108}

[Gen. Phalaris](#t1624)

[Scheda aggiornata - Segnala osservazione](http://www.florae.it/?id=2108)

Pianta glabra (!). Culmi ascendenti, glabri, avvolti fino in alto dalle guaine (le sup. sono decisam. rigonfie). Fg. molli, con lamina larga fino a 9 mm e ligula tronca, breve, di 2(3-5) mm; guaine scabre se strisciate dal basso verso l'alto. Pannocchia spiciforme ovale, densa 1-2 X 2-4 cm; sp.tte inf. spesso sterili; glume 6-7(9) mm, biancastre con linee longi-tud. verdi; lemma fertile 4-6 mm, pubescente; lemmi sterili di 3 mm circa.<br /><br />Macarones.<br />In tutto il terr.: C, però nell'It. Sett. per lo più avvent. incostante.<br /><br /><strong>Usi</strong> - Origin. delle Canarie e Medit. Occid. viene comunem. coltivata come alimento per i canarini; con la pulizia delle gabbie i semi finiscono facilmente tra le immondizie e possono quivi germinare dando luogo a brevi avventiziati. Viene pure usata come pianta ornamentale.

![Diffusione](/home/caiofior/Scaricati/florae.it//images/merged_map/0/c/0c7433833c7e9841626ea999f5f152db.png)

**Autore**
:   Linneo

**Nome Italiano**
:   Scagliola comune

**Ciclo riproduttivo**
:   ☉ Annuale

**Altezza**
:   3-5(7) dm

![](/home/caiofior/Scaricati/florae.it//images/merged_altitude/2/7/277819b553a78e6b2c28d9c898b60ff8.png)
**Fioritura**
:   da Aprile a Giugno

![](/home/caiofior/Scaricati/florae.it//images/merged_flower/b/4/b427ebc8ffe2221831c49fa57369653e.png)
Enter fullscreen mode Exit fullscreen mode

and than call (pandoc)[https://pandoc.org/] form php. Something like this:

                    $cmd = 'pandoc --toc-depth=5 -t '.$format.' -f markdown+definition_lists+line_blocks -s -o '.$tempFileName.'.'.$format.' '.$tempFileName.' 2>&1';

                    $error = shell_exec($cmd);
                    unlink($tempFileName);
                    if (!is_file($tempFileName.'.'.$format)) {
                        throw new \Exception('Error on generating pandoc output with command '.$cmd.' '.$error,1509221630);
                    }
                    $fileName = $tempFileName.'.'.$format;
Enter fullscreen mode Exit fullscreen mode

Where $tempFileName is the name of temporary Markdown file, $format is epub or other pandoc formats (doc, pdf, html) and $fileName the output file name.

At the moment I'm able to produce and epub of 150 Mb.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️