<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Caio Rulli on Medium]]></title>
        <description><![CDATA[Stories by Caio Rulli on Medium]]></description>
        <link>https://medium.com/@caiorulli?source=rss-c1b669eefb6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uPZwKXAZiNEHD-UK9Pxfnw.jpeg</url>
            <title>Stories by Caio Rulli on Medium</title>
            <link>https://medium.com/@caiorulli?source=rss-c1b669eefb6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:59:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@caiorulli/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Converting large HTML documents to PDF at QuintoAndar]]></title>
            <link>https://medium.com/quintoandar-tech-blog/converting-large-html-documents-to-pdf-at-quintoandar-101eabe6ba02?source=rss-c1b669eefb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/101eabe6ba02</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[puppeteer]]></category>
            <category><![CDATA[wkhtmltopdf]]></category>
            <category><![CDATA[pdf-converter]]></category>
            <dc:creator><![CDATA[Caio Rulli]]></dc:creator>
            <pubDate>Fri, 01 Mar 2019 20:45:55 GMT</pubDate>
            <atom:updated>2019-03-01T20:45:55.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lvW-YgEoWs1T-vEv" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=medium&amp;utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At QuintoAndar, we run an inspection service for newly rented houses. Every time a contract is signed, we dispatch an inspector to take pictures and notes regarding the state of the house prior to the tenant’s entry, so we can compare when the tenant leaves and guarantee everything is okay.</p><p>After an inspection is concluded and feedback from the inspection is received from both the owner and tenant, we generate a report with all the pictures and comments for that inspection, and send it to both parties.</p><h4>Problem</h4><p>The report itself was implemented in <em>HTML</em>, and the first solution to making it a <em>PDF</em> was to make it a <em>DOCX</em> Google Document, and then using Google Drive features to make the <em>DOCX</em> a <em>PDF</em>. So far so good, and even if it took one extra step from direct conversion, having an intermediate <em>DOCX</em> would sometimes grant us the benefit of adding last-hour updates if needed.</p><p>We soon noticed this solution wouldn’t always work. Partway through the conversion from <em>DOCX</em> to <em>PDF</em>, we realized the conversion tool would fail to render images, and the resulting <em>PDF </em>(more often than not) would contain lots of missing images.</p><p>A careful reader might suspect how could a Google service fail consistently like this, and the answer is: it does not, for most cases. Our use case happens to be a very particular one: inspections have an average of 300–500 pictures, some reaching as high as 1000 pictures, and the conversion tool had to render them all at once.</p><p>For some time we tried to live with it, and correct it through manual retries whenever the conversion tool would fail. However, due to QuintoAndar’s demand growth, we had to investigate how to implement a more permanent fix, and we started investigating other conversion tools that could do the job.</p><h4>Solutions</h4><p>We first investigated commercial services that handled this kind of document conversion, but none would suit our needs. We wanted asynchronous interaction, so Restful services were ruled out; some other services stored the resulting document in Amazon’s S3, but we wanted to keep using Google Drive instead for operational reasons; and there were services that just couldn’t handle large documents such as ours. We then moved on to search for libraries that could be used within a system of our own.</p><p>Among the possible solutions, two of them managed to successfully convert our huge HTML: <a href="https://wkhtmltopdf.org/"><em>WkHtmlToPdf</em></a>, an open-source <em>CLI</em> that converts <em>HTML</em> using the Qt <em>WebKit</em> engine, and Google’s <a href="https://github.com/GoogleChrome/puppeteer"><em>Puppeteer</em></a>, a Node high-level API to control headless Chrome instances (and possibly print pages in <em>PDF</em>).</p><p><em>WkHtmlToPdf</em> has become a popular way of converting documents, as we would find out in many articles (such as <a href="https://medium.com/@kabitakis/the-html-to-pdf-painful-conversion-7be620ac4d2">this</a> or <a href="https://medium.com/@factoryhr/how-to-efficiently-transfer-html-to-pdf-6222432bbd14">this</a>). It is a CLI tool (also offering a C library API), so running it involves installing it on the host OS and calling the OS directly. When converting our reports, it took from 1 to 2.5 minutes in average-sized reports and 4.5 minutes in worst cases. The resulting <em>PDF</em> had the average size of 10 MB, which was very reasonable. The only con with using it was having to deal with OS interaction.</p><p>The <em>Puppeteer</em> solution, often quoted alongside <em>WkHtmlToPdf </em>(as seen<em> </em><a href="https://medium.com/paperplane-app/whats-the-best-way-to-convert-html-to-pdf-in-2018-4da8d2c85d7">here</a>), can be used to fire a headless Chrome or Chromium instance, access the <em>HTML</em> and “print it”, making it a PDF. It sounded good, as it didn’t involve any OS dependencies, but it didn’t perform well with our larger reports.</p><p>We managed to make it work by printing individual pages and joining them through another library, but this other one required OS dependencies, and the resulting PDF would weight around 45 MB, much more than the <em>WkHtmlToPdf </em>solution.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F7401366&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fcharlie-chaplin-modern-times-production-gif-7401366&amp;image=https%3A%2F%2Fmedia.tenor.com%2FDipUDnw2p6UAAAAF%2Fcharlie-chaplin.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/373bfb9413648aff7d6314b01160918a/href">https://medium.com/media/373bfb9413648aff7d6314b01160918a/href</a></iframe><h4>Implementation</h4><p>What we decided to build, then, was a separate micro-service to wrap document conversion logic. We would use <em>WkHtmlToPdf</em> to convert documents, <em>SQS</em> queues for input and output, and the Google Drive SDK to save the documents.</p><p>We chose to input and output asynchronously through queues due to the expected long waiting time to process a single document (which could easily reach 5 minutes). <em>SQS</em> queues, in particular, gave us retry functionality, valuable due to the occasional 503 failure from fetching images from Cloudfront, and a Dead-Letter-Queue functionality, that would help us investigating general failures and keeping track of missed conversions.</p><p>By the time the micro-service was ready for launch, we were trying to convert a batch of around 1000 inspection reports using the old conversion tool. With it, over the weekend we managed to process 200 inspection reports. When the new micro-service went live, the same number of inspection reports were converted within 2 hours.</p><p><em>HTML</em> to <em>PDF</em> conversion seems to be a trivial matter but, since our case was a very particular one, careful solution benchmark and architectural consideration was required. With the resulting product, we managed to scale the inspection process and unburden operation analysts from the retry work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=101eabe6ba02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quintoandar-tech-blog/converting-large-html-documents-to-pdf-at-quintoandar-101eabe6ba02">Converting large HTML documents to PDF at QuintoAndar</a> was originally published in <a href="https://medium.com/quintoandar-tech-blog">Blog Técnico QuintoAndar</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>