<?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>DEV Community: Akshay Vadher</title>
    <description>The latest articles on DEV Community by Akshay Vadher (@akshayvadher).</description>
    <link>https://dev.to/akshayvadher</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%2F286420%2F65c8ea1a-73bc-4fba-9f53-007f619593c3.png</url>
      <title>DEV Community: Akshay Vadher</title>
      <link>https://dev.to/akshayvadher</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akshayvadher"/>
    <language>en</language>
    <item>
      <title>How to Generate QR Codes using Prawn-QRcode in Ruby?</title>
      <dc:creator>Akshay Vadher</dc:creator>
      <pubDate>Tue, 10 Dec 2019 09:39:23 +0000</pubDate>
      <link>https://dev.to/botreetechnologies/how-to-generate-qr-codes-using-prawn-qrcode-in-ruby-4c3a</link>
      <guid>https://dev.to/botreetechnologies/how-to-generate-qr-codes-using-prawn-qrcode-in-ruby-4c3a</guid>
      <description>&lt;p&gt;This tutorial will guide you on how to generate &lt;a href="https://en.wikipedia.org/wiki/QR_code"&gt;QR codes&lt;/a&gt; using for &lt;a href="https://www.botreetechnologies.com/ruby-on-rails-development"&gt;Ruby on Rails application development&lt;/a&gt;.&lt;br&gt;
Let’s have a brief introduction to QR codes. If you are familiar with &lt;a href="https://github.com/jabbrwcky/prawn-qrcode"&gt;prawn-qrcode&lt;/a&gt; directly go to the implementation section.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is QR Code?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;QR code is a type of barcode(two-dimensional) for the automotive industry.&lt;/li&gt;
&lt;li&gt;It contains information about the item to which it is attached(i.e. Numbers, names or any secret information).&lt;/li&gt;
&lt;li&gt;It has black squares which are arranged in a square grid and has a white background, which can be read by an imaging device such as a camera.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why QR code?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If the information you want to store in a QR code is made of only alphanumeric characters, a single QR code can hold up to 4000 characters.&lt;/li&gt;
&lt;li&gt;The other key feature of QR Codes is that we do not require a chunky hand-held scanner to scan them, our modern cell phones can scan them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Technology Stack&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Technology: Ruby&lt;/li&gt;
&lt;li&gt;Version:  2.6.3p62&lt;/li&gt;
&lt;li&gt;Git Repo: &lt;a href="https://github.com/akshayvadher-BTC/QR-codes"&gt;https://github.com/akshayvadher-BTC/QR-codes&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High capacity encoding of data&lt;/li&gt;
&lt;li&gt;Small printout size&lt;/li&gt;
&lt;li&gt;Readable from any direction("360")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;note: you should have installed &lt;a href="https://gorails.com/setup/ubuntu/18.04#ruby-rvm"&gt;ruby&lt;/a&gt; in your system.&lt;/em&gt;&lt;br&gt;
&lt;code&gt;gem install prawn-qrcode&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;After installation of gem, create ruby file let's say sample.rb and add below method into it and run&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ ruby sample_qr.rb&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’ll generate a PDF named sample.pdf.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you do not want to use number units(i.e. mm, cm, m, etc.) then you do not need to &lt;strong&gt;require prawn/ measurement_extensions&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It will Generate PDF which looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OrTHTXGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.botreetechnologies.com/blog/wp-content/uploads/2019/12/prawn-qrcode-in-ruby-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OrTHTXGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.botreetechnologies.com/blog/wp-content/uploads/2019/12/prawn-qrcode-in-ruby-1.png" alt="pdf of generated QR codes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Qr code, there are 4 methods which are used most as below,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dot (module size):&lt;/strong&gt; This method used to change blocks(black dots) size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alignment of QR:&lt;/strong&gt; We have aligned methods to align QR code on the specific side. (i.e top, right, bottom and left).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Size of string:&lt;/strong&gt; Depending on the number of characters of string you can change it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Page size:&lt;/strong&gt; As per requirement, You can set the page size of QR code. (i.e. A4, A8). You can also set a margin in it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can change the module size by changing dot value and depending on the number of characters in the string you need to increase the size.&lt;/p&gt;

&lt;p&gt;You may get error as below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s4v9h2ko--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.botreetechnologies.com/blog/wp-content/uploads/2019/12/error.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s4v9h2ko--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.botreetechnologies.com/blog/wp-content/uploads/2019/12/error.png" alt="error"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are getting this error because you have more string size than you have specified in code. Reach out to learn more about the &lt;a href="https://www.botreetechnologies.com/usa/web-development-company-new-york"&gt;web development NYC experts&lt;/a&gt; for the various ways to improve or build the quality of projects and across your company.&lt;br&gt;
So, if you have fixed document size and larger string than you need to reduce &lt;strong&gt;dot&lt;/strong&gt; and increase &lt;strong&gt;size&lt;/strong&gt; attributes and that’s it.&lt;/p&gt;

&lt;p&gt;As you can see, I used many methods. You can use it as per your requirement. Here’s some,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;render_qr_code&lt;/strong&gt; render’s generated QR code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;move_up &amp;amp; move_down&lt;/strong&gt; used to move cursor up &amp;amp; down respectively.&lt;/li&gt;
&lt;li&gt;As we do indentation in our code you can also indent text or QR code using &lt;strong&gt;indent&lt;/strong&gt; method.&lt;/li&gt;
&lt;li&gt;For more details For more details you can &lt;a href="https://www.botreetechnologies.com/hire-ruby-on-rails-developers"&gt;hire Ruby on Rails developers&lt;/a&gt; from BoTree Technologies for more assistance on generating QR codes using Ruby.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Read Also: &lt;a href="https://www.botreetechnologies.com/blog/must-have-visual-studio-code-extensions"&gt;Must have Visual Studio Code extensions!&lt;/a&gt;
&lt;/h3&gt;

</description>
      <category>ruby</category>
      <category>qrcode</category>
      <category>rails</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
