When attempting to generate a barcode in Adobe InDesign, I encounter the following error:
JavaScript Error!
Error Number: 80651
Error Message: Please select at least one character that can be converted to outlines.
Line: 5
Source: barcode.createOutlines();
Below is the code that is causing this error to occur
function generateBarcode(value) {
var barcode = app.activeDocument.pages.add().textFrames.add();
barcode.contents = value;
barcode.visibleBounds = ["0mm", "0mm", "30mm", "5mm"];
barcode.createOutlines();
return barcode;
}
function addBarcodeToPDF() {
var doc = app.activeDocument;
var lastPage = doc.pages[doc.pages.length - 1];
var barcodeValue = doc.name.split(".")[0];
var barcode = generateBarcode(barcodeValue);
var rect = lastPage.rectangles.add({
geometricBounds: ["0mm", "0mm", "30mm", "5mm"]
});
var pdfFilePath = "filepath.pdf"; // Path to file!
rect.place(File(pdfFilePath));
var pdfFileName = doc.name.replace(".indd", ".pdf");
doc.exportFile(ExportFormat.PDF_TYPE, new File(pdfFileName), false);
barcode.remove();
rect.remove();
}
addBarcodeToPDF();
Here is how the code works:
Automating Barcode Generation
- The PDF file name is taken, and a barcode is generated based on it.
- The barcode format is EAN-13.
This means that there are, let’s say, 13 digits here that correspond to this format. It would be great if the script could understand that the file name exists, we take it as a variable, and then we insert this barcode in the middle at the bottom of the last page of the document file.
2
Answers
It’s not quite clear from your question what exactly you’re trying to gain. So here is a guess. Probably you mean something like this:
The script takes current document’s name, adds a new page at the end, puts the name at the bottom of the page, exports the document as a pdf, and removes the last page.
Here is the modified version of the excellent Konstantin Smorodsky’s script https://sites.google.com/site/multiprintjs/ean-barcode-generator
The script takes current document’s name, adds a new page at the end, puts the name at the bottom of the page, exports the document as a pdf, and removes the last page.