{"id":435,"date":"2020-12-02T10:59:08","date_gmt":"2020-12-02T10:59:08","guid":{"rendered":"http:\/\/fredborg.org\/?p=435"},"modified":"2021-01-11T06:46:28","modified_gmt":"2021-01-11T06:46:28","slug":"barcodes-and-qr-codes-in-business-central","status":"publish","type":"post","link":"https:\/\/fredborg.org\/?p=435","title":{"rendered":"Barcodes and QR codes in Business Central"},"content":{"rendered":"\n<p><span class=\"has-inline-color has-vivid-red-color\">OBS: barcodes4me has closed their service<\/span><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/www.linkedin.com\/in\/michael-francois-knudsen-3b47052\/\" target=\"_blank\">Michael Francois Knudsen<\/a> Has made me aware that one of the largest downsides to using third party has occurred, barcodes4.me has decided to close their service from January 2021, luckily <a rel=\"noreferrer noopener\" href=\"https:\/\/www.linkedin.com\/in\/michael-francois-knudsen-3b47052\/\" target=\"_blank\">Michael Francois Knudsen<\/a> has been so kind as to share his barcode code, which you can see below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nlocal procedure GenerateBarcode(ItemNo: Text&#x5B;20])\nvar\n  ClientHttp: HttpClient;\n  Request: HttpRequestMessage;\n  Response: HttpResponseMessage;\n  Instr: InStream;\n  Method: text;\n  Outstr: Outstream;\n  TypeHelper: Codeunit &quot;Type Helper&quot;;\nbegin\n  Method := (STRSUBSTNO(&#039;https:\/\/barcode.tec-it.com\/barcode.ashx?data=&#039;+TypeHelper.UrlEncode(ItemNo)+&#039;&amp;code=Code128&amp;translate- \n  esc=on&amp;imagetype=Jpg&#039;));\n  Request.SetRequestUri(Method);\n\n  if not clienthttp.send(Request, Response) then\n    Error(&#039;Call failed&#039;);\n  \n  response.content.ReadAs(Instr);\n  clear(TenantMedia);\n  TenantMedia.Content.CreateOutStream(Outstr);\n  copystream(outstr,Instr);\nend;\n<\/pre><\/div>\n\n\n<p>Once again all credit should go to <a rel=\"noreferrer noopener\" href=\"https:\/\/www.linkedin.com\/in\/michael-francois-knudsen-3b47052\/\" target=\"_blank\">Michael Francois Knudsen<\/a> for providing this code<\/p>\n\n\n\n<p>To update my code example to use the new webservice your code could look something like this<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nprocedure CreateBarcode(ItemNo : Text) : Text \n     var  \n        Base64Convert: Codeunit &quot;Base64 Convert&quot;;  \n        TempBlob: Codeunit &quot;Temp Blob&quot;;\n        TypeHelper: Codeunit &quot;Type Helper&quot;;  \n        client: HttpClient;  \n        response: HttpResponseMessage;  \n        InStr: InStream;  \n\n    begin  \n        client.Get(&#039;https:\/\/barcode.tec-it.com\/barcode.ashx?data=&#039; + TypeHelper.UrlEncode(BarCode) + &#039;&amp;code=Code128&amp;translate-esc=on&amp;imagetype=Jpg&#039;, response);  \n        TempBlob.CreateInStream(InStr);  \n        response.Content().ReadAs(InStr);  \n        BarCode := Base64Convert.ToBase64(InStr);  \n        exit(BarCode); \n    end; \n<\/pre><\/div>\n\n\n<p>I recently had a Business Central Cloud customer, who wanted to add barcodes to their reports, now at first you might think that is no big deal &#x1f937;&#x200d;&#x2640;&#xfe0f;, you just use a barcode font, and everyone is happy&#x1f60a; . But sadly, when it comes to the cloud you cannot just use any font, so what do you do&#x1f914; ? Well, there are some great apps on app source that you can use which can generate barcodes for you, but to be honest I was a little skeptical &#x1f612; to create a dependency in my extension just to get a barcode. So, what other options are there, well you can call a webservice which will generate a barcode for you which you then can use&#x1f913; , now this might sound very complicated but fear not it is not and I will show you just how you can\u00a0accomplish\u00a0this with very little code.\u00a0<\/p>\n\n\n\n<p><span class=\"has-inline-color has-vivid-red-color\">&#8212;&#8211; barcodes4me not longer provides this service &#8212;-><\/span><\/p>\n\n\n\n<p>First off, we are going to use the free API provide by\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/barcodes4.me\/\" target=\"_blank\">http:\/\/barcodes4.me<\/a>\u00a0they have some fantastic documentation both for barcode and QR codes where you can choose the size of the barcode and the font. For a very simple barcode you could use the following code:\u00a0<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nprocedure CreateBarcode(ItemNo : Text) : Text \n     var  \n        Base64Convert: Codeunit &quot;Base64 Convert&quot;;  \n        TempBlob: Codeunit &quot;Temp Blob&quot;;  \n        client: HttpClient;  \n        response: HttpResponseMessage;  \n        InStr: InStream;  \n\n    begin  \n        client.Get(&#039;http:\/\/barcodes4.me\/barcode\/c39\/&#039; + ItemNo + &#039;.png&#039;, response);  \n        TempBlob.CreateInStream(InStr);  \n        response.Content().ReadAs(InStr);  \n        BarCode := Base64Convert.ToBase64(InStr);  \n        exit(BarCode); \n    end; \n<\/pre><\/div>\n\n\n<p><span class=\"has-inline-color has-vivid-red-color\">&lt;&#8212;&#8211; barcodes4me not longer provides this service &#8212;-<\/span><\/p>\n\n\n\n<p>This will leave you with a Base64 string in your barcode variable which you can then use as your image source in you report\u00a0<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"526\" src=\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/image.png\" alt=\"\" class=\"wp-image-436\" srcset=\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/image.png 571w, https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/image-300x276.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure><\/div>\n\n\n\n<p>And that was it for this very short post, you can of course extend the function to take font and size, so that it is more generic, but I think you get the idea, until next time stay safe.&nbsp;&#x1f637;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OBS: barcodes4me has closed their service Michael Francois Knudsen Has made me aware that one of the largest downsides to&#8230; <a class=\"read-more\" href=\"https:\/\/fredborg.org\/?p=435\" rel=\"nofollow\"> Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-central","category-uncategorized","shapla-grid-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Barcodes and QR codes in Business Central - Fredborg<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fredborg.org\/?p=435\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Barcodes and QR codes in Business Central - Fredborg\" \/>\n<meta property=\"og:description\" content=\"OBS: barcodes4me has closed their service Michael Francois Knudsen Has made me aware that one of the largest downsides to... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fredborg.org\/?p=435\" \/>\n<meta property=\"og:site_name\" content=\"Fredborg\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-02T10:59:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-11T06:46:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"dfredborg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dfredborg\" \/>\n<meta name=\"twitter:site\" content=\"@dfredborg\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dfredborg\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fredborg.org\/?p=435#article\",\"isPartOf\":{\"@id\":\"https:\/\/fredborg.org\/?p=435\"},\"author\":{\"name\":\"dfredborg\",\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\"},\"headline\":\"Barcodes and QR codes in Business Central\",\"datePublished\":\"2020-12-02T10:59:08+00:00\",\"dateModified\":\"2021-01-11T06:46:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fredborg.org\/?p=435\"},\"wordCount\":390,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\"},\"image\":{\"@id\":\"https:\/\/fredborg.org\/?p=435#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png\",\"articleSection\":[\"Business Central\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fredborg.org\/?p=435#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fredborg.org\/?p=435\",\"url\":\"https:\/\/fredborg.org\/?p=435\",\"name\":\"Barcodes and QR codes in Business Central - Fredborg\",\"isPartOf\":{\"@id\":\"https:\/\/fredborg.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fredborg.org\/?p=435#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fredborg.org\/?p=435#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png\",\"datePublished\":\"2020-12-02T10:59:08+00:00\",\"dateModified\":\"2021-01-11T06:46:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fredborg.org\/?p=435#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fredborg.org\/?p=435\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fredborg.org\/?p=435#primaryimage\",\"url\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png\",\"contentUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png\",\"width\":1536,\"height\":768},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fredborg.org\/?p=435#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fredborg.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Barcodes and QR codes in Business Central\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fredborg.org\/#website\",\"url\":\"https:\/\/fredborg.org\/\",\"name\":\"Fredborg\",\"description\":\"Business Central and Azure\",\"publisher\":{\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fredborg.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\",\"name\":\"dfredborg\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2023\/06\/download.png\",\"contentUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2023\/06\/download.png\",\"width\":256,\"height\":256,\"caption\":\"dfredborg\"},\"logo\":{\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:fredborg.org\",\"https:\/\/www.linkedin.com\/in\/dfredborg\/\",\"https:\/\/x.com\/dfredborg\",\"https:\/\/www.youtube.com\/channel\/UCUNZglLDMjBlOK_T9JtI8UA\"],\"url\":\"https:\/\/fredborg.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Barcodes and QR codes in Business Central - Fredborg","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fredborg.org\/?p=435","og_locale":"en_US","og_type":"article","og_title":"Barcodes and QR codes in Business Central - Fredborg","og_description":"OBS: barcodes4me has closed their service Michael Francois Knudsen Has made me aware that one of the largest downsides to... Read more","og_url":"https:\/\/fredborg.org\/?p=435","og_site_name":"Fredborg","article_published_time":"2020-12-02T10:59:08+00:00","article_modified_time":"2021-01-11T06:46:28+00:00","og_image":[{"width":1536,"height":768,"url":"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png","type":"image\/png"}],"author":"dfredborg","twitter_card":"summary_large_image","twitter_creator":"@dfredborg","twitter_site":"@dfredborg","twitter_misc":{"Written by":"dfredborg","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fredborg.org\/?p=435#article","isPartOf":{"@id":"https:\/\/fredborg.org\/?p=435"},"author":{"name":"dfredborg","@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d"},"headline":"Barcodes and QR codes in Business Central","datePublished":"2020-12-02T10:59:08+00:00","dateModified":"2021-01-11T06:46:28+00:00","mainEntityOfPage":{"@id":"https:\/\/fredborg.org\/?p=435"},"wordCount":390,"commentCount":0,"publisher":{"@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d"},"image":{"@id":"https:\/\/fredborg.org\/?p=435#primaryimage"},"thumbnailUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png","articleSection":["Business Central"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fredborg.org\/?p=435#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fredborg.org\/?p=435","url":"https:\/\/fredborg.org\/?p=435","name":"Barcodes and QR codes in Business Central - Fredborg","isPartOf":{"@id":"https:\/\/fredborg.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fredborg.org\/?p=435#primaryimage"},"image":{"@id":"https:\/\/fredborg.org\/?p=435#primaryimage"},"thumbnailUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png","datePublished":"2020-12-02T10:59:08+00:00","dateModified":"2021-01-11T06:46:28+00:00","breadcrumb":{"@id":"https:\/\/fredborg.org\/?p=435#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fredborg.org\/?p=435"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fredborg.org\/?p=435#primaryimage","url":"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png","contentUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2020\/12\/Barcodes-and-Qr-for-BC.png","width":1536,"height":768},{"@type":"BreadcrumbList","@id":"https:\/\/fredborg.org\/?p=435#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fredborg.org\/"},{"@type":"ListItem","position":2,"name":"Barcodes and QR codes in Business Central"}]},{"@type":"WebSite","@id":"https:\/\/fredborg.org\/#website","url":"https:\/\/fredborg.org\/","name":"Fredborg","description":"Business Central and Azure","publisher":{"@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fredborg.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d","name":"dfredborg","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fredborg.org\/#\/schema\/person\/image\/","url":"https:\/\/fredborg.org\/wp-content\/uploads\/2023\/06\/download.png","contentUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2023\/06\/download.png","width":256,"height":256,"caption":"dfredborg"},"logo":{"@id":"https:\/\/fredborg.org\/#\/schema\/person\/image\/"},"sameAs":["https:fredborg.org","https:\/\/www.linkedin.com\/in\/dfredborg\/","https:\/\/x.com\/dfredborg","https:\/\/www.youtube.com\/channel\/UCUNZglLDMjBlOK_T9JtI8UA"],"url":"https:\/\/fredborg.org\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=435"}],"version-history":[{"count":2,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions\/492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/media\/438"}],"wp:attachment":[{"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}