Home > Software design >  How do I redraw a barcode object on a pdf document?
How do I redraw a barcode object on a pdf document?

Time:12-22

I'm trying to make a pdf document that will display the current date and 5 business days from now in the form of a barcode object.

I was able to get the value of my barcode to update to the current date with a bit of javascript:

var today = new Date();
event.value = util.printd("dd-mmm-yy", today);

But of course that just sets the value of the barcode and not the appearance of it so it just displays as text. Does the barcode object have an attribute or function to redraw it or update the appearance?

I used this bit of code to get the 5 business days from today works the same as above:

var today = new Date();
var numToAdd = 5;
var i = 1;

for (i = 1; i <= numToAdd; i  ) {
  today.setDate(today.getDate()   1);
  if (today.getDay() === 6) {
    today.setDate(today.getDate()   2);
  }
  else if (today.getDay() === 0) {
    today.setDate(today.getDate()   1);
  }
}
event.value = util.printd("dd-mmm-yy", today);

CodePudding user response:

You can print from html to PDF here is an example just for Monday but you can remove the unwanted outputs and add your other days by multiple entries

For details and options like colours see https://lindell.me/JsBarcode/ and https://github.com/lindell/JsBarcode

var now = new Date();
var next_week_start = new Date(now.getFullYear(), now.getMonth(), now.getDate() (8 - now.getDay()));
var barStringMonday = next_week_start.toDateString()

JsBarcode("#barcodeMonday", barStringMonday , {format: "code39"});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/JsBarcode.all.min.js"></script>
Hello Dear World!</br>
Here are your Bare Codes
<p>
SVG<svg id="barcodeMonday"></svg>
</p>
Canvas<canvas id="barcodeMonday"></canvas>
<p>
Image<img id="barcodeMonday" alt="code39 barcode value as of Monday" />
</p>

  • Related