<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Piotr Żaba</title>
    <description>The latest articles on Forem by Piotr Żaba (@piotrzaba).</description>
    <link>https://forem.com/piotrzaba</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F899751%2F3b063d0d-3d0d-483c-8939-e553f4f9463e.jpeg</url>
      <title>Forem: Piotr Żaba</title>
      <link>https://forem.com/piotrzaba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/piotrzaba"/>
    <language>en</language>
    <item>
      <title>Convert html to pdf with a retry mechanism</title>
      <dc:creator>Piotr Żaba</dc:creator>
      <pubDate>Mon, 17 Oct 2022 15:36:22 +0000</pubDate>
      <link>https://forem.com/piotrzaba/convert-html-to-pdf-or-image-using-htmleerdev-api-498e</link>
      <guid>https://forem.com/piotrzaba/convert-html-to-pdf-or-image-using-htmleerdev-api-498e</guid>
      <description>&lt;p&gt;Now that you know what is HTMLeer.dev we can learn how to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get your API key
&lt;/h2&gt;

&lt;p&gt;If you don't have an account, just head to &lt;a href="https://app.htmleer.dev/register"&gt;Register page&lt;/a&gt;. &lt;br&gt;
After registration go to API keys using navigation bar and create new one.&lt;/p&gt;
&lt;h2&gt;
  
  
  API documeentation
&lt;/h2&gt;

&lt;p&gt;You can find available options &lt;a href="https://api.htmleer.dev/"&gt;in our swagger documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Usage of the API
&lt;/h2&gt;

&lt;p&gt;It's really simple, all you need to do is call HTMLeer API with your API key. Here's an example how you can create and download pdf file using HTMLeer API (with a help of p-retry in case of any failures).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pRetry, { AbortError } from 'p-retry';

const generatePDF = async () =&amp;gt; {
    const response = await fetch('https://api.htmleer.dev/v1/generate/pdf', {
        method: 'POST',
        body: JSON.stringify({
            savePdf: false,
            filename: 'my-file',
            html: `&amp;lt;div&amp;gt;Hello {{ name }}!&amp;lt;/div&amp;gt;`,
            arguments: { name: 'HTMLeer' },
            options: { format: 'A4' }
        }),
        headers: {
            'content-type': 'application/json',
            'api-key': process.env.HTMLEER_API_KEY
        },
    });

    // we are stopping retrying because its custom api error
    if (!response.ok &amp;amp;&amp;amp; response.status &amp;lt; 500) {
        throw new AbortError(response.statusText);
    }

    if (!response.ok) {
        throw new Error(response.statusText);
    }

    return response.arrayBuffer();
};

try {
    const result = await pRetry(generatePDF, { retries: 5 });
    const blob = new Blob([result], { type: "application/pdf" });
    const objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
} catch (err) {
    console.log(err);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do you think?&lt;/p&gt;

</description>
      <category>html</category>
      <category>puppeteer</category>
      <category>handlebars</category>
      <category>htmleer</category>
    </item>
    <item>
      <title>About HTMLeer.dev API</title>
      <dc:creator>Piotr Żaba</dc:creator>
      <pubDate>Tue, 20 Sep 2022 12:33:44 +0000</pubDate>
      <link>https://forem.com/piotrzaba/htmleerdev-api-for-converting-html-to-pdfimage-2ge9</link>
      <guid>https://forem.com/piotrzaba/htmleerdev-api-for-converting-html-to-pdfimage-2ge9</guid>
      <description>&lt;p&gt;&lt;a href="https://htmleer.dev"&gt;HTMLeer&lt;/a&gt; provides REST API for your next application, which will make it easier for you to generate pdfs and images without worrying much about architecture, cost and scaling issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;generating pdf/image based on html input&lt;/li&gt;
&lt;li&gt;saving generated file on s3&lt;/li&gt;
&lt;li&gt;streaming a file back to the client without saving on s3&lt;/li&gt;
&lt;li&gt;possibility to use options provided by puppeteer&lt;/li&gt;
&lt;li&gt;possibility to use handlebars syntax&lt;/li&gt;
&lt;li&gt;use of dynamic arguments&lt;/li&gt;
&lt;li&gt;management panel for your api keys, allowed origins, saved files and subscription status&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How it works?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;client creates his account on &lt;a href="https://app.htmleer.dev"&gt;HTMLeer management panel&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;client sets up new api key&lt;/li&gt;
&lt;li&gt;client uses &lt;a href="https://api.htmleer.dev"&gt;HTMLeer documentation&lt;/a&gt; and makes his request to the api with already created api key&lt;/li&gt;
&lt;li&gt;api in response returns buffer of the file or object with link to saved file&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;There are free 100 API generations each month, it should be enough for small applications.&lt;/p&gt;

&lt;p&gt;You can also buy additional API generations, which does not have any use time limitations:&lt;br&gt;
&lt;strong&gt;1000 generations&lt;/strong&gt;: 5$ + tax&lt;br&gt;
&lt;strong&gt;5000 generations&lt;/strong&gt;: 15$ + tax&lt;br&gt;
&lt;strong&gt;25000 generations&lt;/strong&gt;: 50$ + tax&lt;br&gt;
&lt;strong&gt;100000 generations&lt;/strong&gt;: 100$ + tax&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>html</category>
      <category>puppeteer</category>
      <category>handlebars</category>
      <category>htmleer</category>
    </item>
  </channel>
</rss>
