diff --git a/frappe/printing/page/print/print.js b/frappe/printing/page/print/print.js
index e0d021ce3e..8be828d032 100644
--- a/frappe/printing/page/print/print.js
+++ b/frappe/printing/page/print/print.js
@@ -483,7 +483,14 @@ frappe.ui.form.PrintView = class {
this.$print_format_body
.find("body")
.html(`
${out.html}
`);
-
+ const iframeDoc = this.$print_format_body[0];
+ iframeDoc.querySelectorAll("svg[data-barcode-value]").forEach((el) => {
+ const get_options = frappe.ui.form.ControlBarcode.prototype.get_options.bind({
+ df: { options: el.dataset.options },
+ });
+ JsBarcode(el, el.dataset.barcodeValue, get_options(el.dataset.barcodeValue));
+ el.setAttribute("width", "100%");
+ });
this.show_footer();
this.$print_format_body.find(".print-format").css({
diff --git a/frappe/public/js/frappe/form/controls/barcode.js b/frappe/public/js/frappe/form/controls/barcode.js
index a819384773..06a547395d 100644
--- a/frappe/public/js/frappe/form/controls/barcode.js
+++ b/frappe/public/js/frappe/form/controls/barcode.js
@@ -64,7 +64,7 @@ frappe.ui.form.ControlBarcode = class ControlBarcode extends frappe.ui.form.Cont
options.height = "50";
if (frappe.utils.is_json(this.df.options)) {
- options = JSON.parse(this.df.options);
+ Object.assign(options, JSON.parse(this.df.options));
if (options.format && options.format === "EAN") {
options.format = value.length == 8 ? "EAN8" : "EAN13";
}
diff --git a/frappe/public/js/print.bundle.js b/frappe/public/js/print.bundle.js
new file mode 100644
index 0000000000..de1eb49f73
--- /dev/null
+++ b/frappe/public/js/print.bundle.js
@@ -0,0 +1,25 @@
+import JsBarcode from "jsbarcode";
+
+function get_options(value, df_options = null) {
+ let options = {};
+ options.fontSize = "16";
+ options.width = "3";
+ options.height = "50";
+ if (df_options) {
+ Object.assign(options, JSON.parse(df_options));
+ if (options.format && options.format === "EAN") {
+ options.format = value.length == 8 ? "EAN8" : "EAN13";
+ }
+ }
+ return options;
+}
+
+window.render_barcode = (el) => {
+ const value = el.dataset.barcodeValue;
+ try {
+ JsBarcode(el, value, get_options(value, el.dataset.options));
+ el.setAttribute("width", "100%");
+ } catch (e) {
+ console.log(e);
+ }
+};
diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html
index 4aeb657edf..b5fb774e00 100644
--- a/frappe/templates/print_formats/standard_macros.html
+++ b/frappe/templates/print_formats/standard_macros.html
@@ -157,6 +157,8 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}"
{% elif df.fieldtype=="Signature" %}
+ {% elif df.fieldtype=="Barcode" and not doc[df.fieldname].startswith("
{% elif df.fieldtype in ("Attach", "Attach Image") and frappe.utils.is_image(doc[df.fieldname]) %}
diff --git a/frappe/www/printview.html b/frappe/www/printview.html
index 17e6380baa..ffa89d677e 100644
--- a/frappe/www/printview.html
+++ b/frappe/www/printview.html
@@ -6,6 +6,7 @@
{{ title }}
{{ include_style('print.bundle.css') }}
+ {{ include_script('print.bundle.js') }}
{% if print_style %}