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.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

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

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay