{"id":264,"date":"2019-11-15T13:31:25","date_gmt":"2019-11-15T13:31:25","guid":{"rendered":"http:\/\/fredborg.org\/?p=264"},"modified":"2020-12-23T20:45:48","modified_gmt":"2020-12-23T20:45:48","slug":"printing-in-business-central","status":"publish","type":"post","link":"https:\/\/fredborg.org\/?p=264","title":{"rendered":"Printing in Business Central"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Printing is, in my opinion, one of the most lacking features in Business Central, because while you can print using the web browsers printer. However, if you wish to print without being prompted, like when you choose Post and Print, this does not work as intended. If you use the Post and Print function, what Business Central will do is create and download a PDF of your report, which you then manually can print. Now I know that we are living in a modern age where for the most part we do not need to print anything since everything can be handled digitally, sometimes it is just nice to actually be able to have a hard copy of your documents.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So how do we solve this? Well there are a couple of ways, but the one that I will talk about in this post is, by using a third-party product called\u00a0PrintNode\u00a0(<a rel=\"noreferrer noopener\" href=\"https:\/\/www.printnode.com\/en\" target=\"_blank\">https:\/\/www.printnode.com\/en<\/a>) how this product works is by allowing you to send either an URL to a PDF file or a base64 encoded string to\u00a0PrintNodes\u00a0API which in turn will send the request to a locally installed print client on your PC \/ Server.\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"409\" src=\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/PrintNode-flow-1024x409.png\" alt=\"\" class=\"wp-image-265\" srcset=\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/PrintNode-flow-1024x409.png 1024w, https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/PrintNode-flow-300x120.png 300w, https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/PrintNode-flow-768x307.png 768w, https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/PrintNode-flow.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let us take a look at some AL code&nbsp;&#x1f60a;&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First,\u00a0we need to write some code, that can interact with\u00a0PrintNode\u00a0the first function is to create the\u00a0GetAuthString\u00a0function.\u00a0<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nlocal procedure GetAuthString(): Text&#x5B;250] \n    var \n        Base64: Codeunit &quot;Base64 Convert&quot;; \n        AuthString: Text&#x5B;250]; \n    begin \n        AuthString := CopyStr(STRSUBSTNO(&#039;%1:%2&#039;, \u2018{API KEY}\u2019, &#039;&#039;), 1, 250); \n        AuthString := CopyStr(Base64.ToBase64(AuthString), 1, 250); \n        AuthString := CopyStr(STRSUBSTNO(&#039;Basic %1&#039;, AuthString), 1, 250); \n        EXIT(AuthString); \n    end;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">\n\nThe {API KEY} is generated in the&nbsp;PrintNode&nbsp;portal next I use a function called&nbsp;GetJsonToken&nbsp;thank you, Arend-Jan Kauffmann,&nbsp;&#x1f60a;&nbsp;&nbsp;\n\n<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nprocedure GetJsonToken(JsonObject: JsonObject; TokenKey: Text) JsonToken: JsonToken; \n    begin \n        if not JsonObject.GET(TokenKey, JsonToken) then \n            Error(&#039;Could not find token &#039; + TokenKey); \n    end; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">\n\nAnd the last function we are going to need is&nbsp;CallPrintNode&nbsp;which will send our request to&nbsp;PrintNode&nbsp;\n\n<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nprocedure CallPrintNode(Base64: Text; Title: Text) \n    var \n        client: HttpClient; \n        cont: HttpContent; \n        header: HttpHeaders; \n        response: HttpResponseMessage; \n        Jobject: JsonObject; \n        error: JsonToken; \n        tmpString: Text; \n\n    begin \n        client.DefaultRequestHeaders().Add(&#039;Authorization&#039;, GetAuthString()); \n        Clear(Jobject); \n        Jobject.Add(&#039;printerId&#039;, \u2018{printerID}\u2019) \n        Jobject.Add(&#039;title&#039;, Title); \n        Jobject.Add(&#039;contentType&#039;, &#039;pdf_base64&#039;); \n        Jobject.Add(&#039;content&#039;, Base64); \n        Jobject.Add(&#039;source&#039;, &#039;Business Central&#039;); \n        Jobject.WriteTo(tmpString); \n        cont.WriteFrom(tmpString); \n        cont.ReadAs(tmpString); \n        cont.GetHeaders(header); \n        header.Remove(&#039;Content-Type&#039;); \n        header.Add(&#039;Content-Type&#039;, &#039;application\/json&#039;);  \n        client.Post(&#039;https:\/\/api.printnode.com\/printjobs&#039;, cont, response);  \n\n        if not response.IsSuccessStatusCode() then begin \n            response.Content().ReadAs(tmpString); \n            Jobject.ReadFrom(tmpString); \n            Jobject.Get(&#039;error&#039;, error); \n            Error(&#039;Failed: Reason: &#039; + error.AsValue().AsText()); \n        end \n        else \n            response.Content().ReadAs(tmpString); \n    end; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"> And that is all the code that you need, now to use the function you could call it with something like this:\u00a0 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar \n        SalesShip: Record &quot;Sales Shipment Header&quot;; \n        TempBlob: Codeunit &quot;Temp Blob&quot;; \n        Base64Convert: Codeunit &quot;Base64 Convert&quot;;   \n        RecRef: RecordRef; \n        MyOutStream: OutStream; \n        MyInStream: InStream; \n        Base64String: Text; \n    begin \n \n            SalesShip.get(SalesShptHdrNo); \n            SalesShip.SetFilter(&quot;No.&quot;, SalesShptHdrNo); \n            RecRef.GetTable(SalesShip); \n            RecRef.SetView(SalesShip.GetView()); \n\n            TempBlob.CreateOutStream(MyOutStream); \n            Report.SaveAs(Report::&quot;Sales - Shipment&quot;, SalesShip.GetFilters(), ReportFormat::Pdf, MyOutStream, RecRef); \n            TempBlob.CreateInStream(MyInStream);  \n            Base64String := Base64Convert.ToBase64(MyInStream); \n            CallPrintNode(Base64String, &#039;Sales Shipment&#039;); \n\n        end; \n    end; \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">And that is all there is to it&nbsp;&#x1f60a;&nbsp;Now I know there are other ways of handling printing from the cloud, where Google Cloud Print also could be a way to go, however using&nbsp;Google Cloud Print will require you to use OAuth and using tokens, which very fast can become a more complicated solution, however once it is set up,&nbsp;Google Cloud Print is free, for now anyway&nbsp;&#x1f609;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And that is all for now, and happy printing &#x1f609;&nbsp;&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Printing is, in my opinion, one of the most lacking features in Business Central, because while you can print using&#8230; <a class=\"read-more\" href=\"https:\/\/fredborg.org\/?p=264\" rel=\"nofollow\"> Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[],"class_list":["post-264","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>Printing 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=264\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Printing in Business Central - Fredborg\" \/>\n<meta property=\"og:description\" content=\"Printing is, in my opinion, one of the most lacking features in Business Central, because while you can print using... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fredborg.org\/?p=264\" \/>\n<meta property=\"og:site_name\" content=\"Fredborg\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-15T13:31:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-23T20:45:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"644\" \/>\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=264#article\",\"isPartOf\":{\"@id\":\"https:\/\/fredborg.org\/?p=264\"},\"author\":{\"name\":\"dfredborg\",\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\"},\"headline\":\"Printing in Business Central\",\"datePublished\":\"2019-11-15T13:31:25+00:00\",\"dateModified\":\"2020-12-23T20:45:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fredborg.org\/?p=264\"},\"wordCount\":408,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d\"},\"image\":{\"@id\":\"https:\/\/fredborg.org\/?p=264#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png\",\"articleSection\":[\"Business Central\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fredborg.org\/?p=264#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fredborg.org\/?p=264\",\"url\":\"https:\/\/fredborg.org\/?p=264\",\"name\":\"Printing in Business Central - Fredborg\",\"isPartOf\":{\"@id\":\"https:\/\/fredborg.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fredborg.org\/?p=264#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fredborg.org\/?p=264#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png\",\"datePublished\":\"2019-11-15T13:31:25+00:00\",\"dateModified\":\"2020-12-23T20:45:48+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fredborg.org\/?p=264#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fredborg.org\/?p=264\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fredborg.org\/?p=264#primaryimage\",\"url\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png\",\"contentUrl\":\"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png\",\"width\":1200,\"height\":644},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fredborg.org\/?p=264#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fredborg.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Printing 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":"Printing 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=264","og_locale":"en_US","og_type":"article","og_title":"Printing in Business Central - Fredborg","og_description":"Printing is, in my opinion, one of the most lacking features in Business Central, because while you can print using... Read more","og_url":"https:\/\/fredborg.org\/?p=264","og_site_name":"Fredborg","article_published_time":"2019-11-15T13:31:25+00:00","article_modified_time":"2020-12-23T20:45:48+00:00","og_image":[{"width":1200,"height":644,"url":"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.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=264#article","isPartOf":{"@id":"https:\/\/fredborg.org\/?p=264"},"author":{"name":"dfredborg","@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d"},"headline":"Printing in Business Central","datePublished":"2019-11-15T13:31:25+00:00","dateModified":"2020-12-23T20:45:48+00:00","mainEntityOfPage":{"@id":"https:\/\/fredborg.org\/?p=264"},"wordCount":408,"commentCount":0,"publisher":{"@id":"https:\/\/fredborg.org\/#\/schema\/person\/59a5520cbf04c6bd1267f30b4488e71d"},"image":{"@id":"https:\/\/fredborg.org\/?p=264#primaryimage"},"thumbnailUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png","articleSection":["Business Central"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fredborg.org\/?p=264#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fredborg.org\/?p=264","url":"https:\/\/fredborg.org\/?p=264","name":"Printing in Business Central - Fredborg","isPartOf":{"@id":"https:\/\/fredborg.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fredborg.org\/?p=264#primaryimage"},"image":{"@id":"https:\/\/fredborg.org\/?p=264#primaryimage"},"thumbnailUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png","datePublished":"2019-11-15T13:31:25+00:00","dateModified":"2020-12-23T20:45:48+00:00","breadcrumb":{"@id":"https:\/\/fredborg.org\/?p=264#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fredborg.org\/?p=264"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fredborg.org\/?p=264#primaryimage","url":"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png","contentUrl":"https:\/\/fredborg.org\/wp-content\/uploads\/2019\/11\/printing.png","width":1200,"height":644},{"@type":"BreadcrumbList","@id":"https:\/\/fredborg.org\/?p=264#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fredborg.org\/"},{"@type":"ListItem","position":2,"name":"Printing 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\/264","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=264"}],"version-history":[{"count":1,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts\/264\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/posts\/264\/revisions\/267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=\/wp\/v2\/media\/266"}],"wp:attachment":[{"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fredborg.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}