Skip to main content

Publishing a code sample book from Stackoverflow to LeanPub using Drupal and GitLab

Senior Systems Engineer
Feb 11, 2016

We built a developer portal for iText that helps them to republish questions, answers, and code samples from Stackoverflow in their documentation. The same Drupal site also has an export function that packages the markdown content from the questions in a format that can be published on LeanPub, where it becomes available as a PDF, EPUB or MOBI document.

Stackoverflow is a great content marketing channel for developer evangelists. iText, the company that created the eponymous PDF library, has used Stackoverflow with great success to gain a strong reputation with developers and to build a sustainable business around their open source software.

In this blogpost we want to share how Bruno Lowagie (the original developer of iText) designed a workflow that allows him to publish questions and answers from Stackoverflow on the iText Drupal site and then export them to LeanPub (utilizing a custom Drupal module):

  1. A user posts a question on Stackoverflow, such as “Can’t get Czech characters while generating a PDF”:
  1. To answer this question, we create a standalone example.
  2. The finished sample code is then uploaded to GitLab, the open source code repository that iText uses to manage their project’s source code and example files.

  1. Then - when publishing the example Java file into the Examples section of the iText developers website (as a book node) - we use a custom Drupal module to link to the sample code file in GitLab and display the contents of that file within the node.
  1. Having all the elements in place, we answer the question in Stackoverflow - referring to the example with some information and a link to the source code and the resulting PDFs.
  1. Afterwards, we post the example - containing the code written when answering the Stackoverflow question - into the Q&A section of the iText developers website.
  1. In addition to the content now being accessible through the Q&A and Examples sections of the iText developers website (as well as in the original Stackoverflow post), we are also able to export the structured book content into the format (a ZIP file) required for publishing on LeanPub - utilizing a custom Drupal module developed to handle the Leanpub-specific format:

Contents of LeanPub-specific book export from Drupal:

  1. Next, we are able to take the LeanPub-specific contents of the exported Drupal book and publish them on LeanPub:

See also Bruno Lowagie’s video tutorial:

Jan is responsible for managing hosted customer environments, development workflows, devops processes and the overall IT infrastructure at Pronovix. With 20+ years of experience as a systems engineer including 10+ years in project management, he is well equipped to handle challenges of various sizes in any of the lifecycle phases.


Articles on devportals, DX and API docs, event recaps, webinars, and more. Sign up to be up to date with the latest trends and best practices.