<?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: developercheese</title>
    <description>The latest articles on DEV Community by developercheese (@developcheese).</description>
    <link>https://dev.to/developcheese</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%2F1021998%2Fbd8a1be7-172e-415e-8ba8-b278823910c1.png</url>
      <title>DEV Community: developercheese</title>
      <link>https://dev.to/developcheese</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/developcheese"/>
    <language>en</language>
    <item>
      <title>Automatic reading Swiss QR bills</title>
      <dc:creator>developercheese</dc:creator>
      <pubDate>Mon, 06 Feb 2023 22:19:49 +0000</pubDate>
      <link>https://dev.to/developcheese/automatic-reading-swiss-qr-bills-19ik</link>
      <guid>https://dev.to/developcheese/automatic-reading-swiss-qr-bills-19ik</guid>
      <description>&lt;p&gt;The banking sector is an important part of the Swiss economy. Electronic wire transfers for the settlement of bills had been standardized several decades ago. Most of the payments done until 2022 were based on a standard defined by the Swiss Post. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii0dcuu7151oy32rkrek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii0dcuu7151oy32rkrek.png" alt="Old style payment slip" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This standard defined what information the paper slips needed to contain and also defined a single line of numbers that contained the most important routing information which could be read electronically. The amount of information was very limited, which meant that a lot of data still needed to be entered manually to register an invoice in any accounting system.&lt;/p&gt;

&lt;p&gt;With the introduction of the Swiss QR bill standard in 2020 and the phasing out of the previous standard in 2022, all software that handles invoices either in the way of producing invoices or processing incoming invoices is be able to handle these new type of invoices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb33uvlo8d1iz0ixtoa1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb33uvlo8d1iz0ixtoa1g.png" alt="New style payment slip" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While the payments slips contain also human readable information about the payment, this information is now included as a machine readable QR code as well.&lt;/p&gt;

&lt;p&gt;The content of the QR code the highly standardized to allow processing of incoming invoices fully automatically.&lt;/p&gt;

&lt;p&gt;The QR bill structure contains defined rows of data with line breaks. Every QR bill starts with the letters SPC on the first line, followed by the version on the second line.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SPC&lt;br&gt;
0200&lt;br&gt;
1&lt;br&gt;
CH4431999123000889012&lt;br&gt;
S&lt;br&gt;
Robert Schneider AG&lt;br&gt;
Rue du Lac&lt;br&gt;
1268/2/22&lt;br&gt;
2501&lt;br&gt;
Biel&lt;br&gt;
CH&lt;br&gt;
S&lt;br&gt;
Robert Schneider Services Switzerland AG&lt;br&gt;
Rue du Lac&lt;br&gt;
1268/3/1&lt;br&gt;
2501&lt;br&gt;
Biel&lt;br&gt;
CH&lt;br&gt;
...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because the QR codes included all the information needed, additional OCR or manual entry of data is not required to read, recognize, categorize and process incoming invoices.&lt;/p&gt;

&lt;p&gt;Aspose with its two component Aspose.Pdf and Aspose.Barcode provides all the required components for implementation in .NET to process incoming invoices and extract all the required information in just a few lines of code.&lt;/p&gt;

&lt;p&gt;In the first step you initialize the incoming PDF document that you might have received by email or which was received by post and scanned into a PDF file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kc6kqg8jvcg2ol3kzx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kc6kqg8jvcg2ol3kzx4.png" alt="Initialization" width="581" height="52"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are also setting up the resolution and PngDevice to allow us to render the PDF page to a image that can then be used for the QR recognition code.&lt;/p&gt;

&lt;p&gt;The QR code can be on any page, so we are looping using a foreach to go through the pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach (Page p in pdfDocument.Pages) // loop through pages
{
   using (MemoryStream imageStream = new MemoryStream())
   {
      pngDevice.Process(p, imageStream); // write pdf page to PNG
      imageStream.Position = 0;
      using (BarCodeReader reader = new BarCodeReader(imageStream, DecodeType.QR))
      {
         foreach (BarCodeResult result in reader.ReadBarCodes())
         {
            code = result.CodeText;
            if (code.StartsWith("SPC"))
            {
               qrcode = code;
               imageStream.Close();
               return qrcode;
            }
            else
            {
               code = "";
            }
         }
      }
      imageStream.Close();
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Aspose libraries allow the full reading of the PDF document, conversion of the pages to bitmaps and recognize the contained QR codes with high reliability.&lt;/p&gt;

&lt;p&gt;After extracting the content of the QR code, split the resulting string into the individual parts (creditor, accounts, reference numbers, amount, currency etc.) that are contained in the complete content of the QR code.&lt;/p&gt;

&lt;p&gt;This process can be either implemented in a user facing application or also in a background service that either monitors email inboxes for incoming invoices or drive folders for scans coming in from a centralized mail office.&lt;/p&gt;

&lt;p&gt;The complete structure of the QR bill code is described in the official implementation guidelines from SIX which be can be found at &lt;a href="https://www.six-group.com/en/products-services/banking-services/payment-standardization/standards/qr-bill.html" rel="noopener noreferrer"&gt;SIX&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With the help of the underlying Aspose libraries, implementing the business logic can be done within one hour. Don't forget to look for blocked files and handle errors nicely when coming across corrupt pdf files or things like this.&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>discuss</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
