Update
This commit is contained in:
@@ -888,13 +888,10 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
function jQueryOpenBarCode(item, nofoto) {
|
function jQueryOpenBarCode(item, nofoto) {
|
||||||
// Pastikan library sudah termuat
|
|
||||||
if (typeof window.jspdf === 'undefined' || typeof JsBarcode === 'undefined') {
|
if (typeof window.jspdf === 'undefined' || typeof JsBarcode === 'undefined') {
|
||||||
alert('Kesalahan: Library jsPDF atau JsBarcode belum dimuat.');
|
alert('Kesalahan: Library jsPDF atau JsBarcode belum dimuat.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Parsing data (sama seperti sebelumnya)
|
|
||||||
const itemParts = item.split('<>');
|
const itemParts = item.split('<>');
|
||||||
const asalpasien = itemParts[0]?.trim() || "xx";
|
const asalpasien = itemParts[0]?.trim() || "xx";
|
||||||
const kd_spesimen = itemParts[1]?.trim() || "xx";
|
const kd_spesimen = itemParts[1]?.trim() || "xx";
|
||||||
@@ -906,15 +903,12 @@
|
|||||||
if (nama.length > 12) {
|
if (nama.length > 12) {
|
||||||
nama = nama.substring(0, 12) + ".";
|
nama = nama.substring(0, 12) + ".";
|
||||||
}
|
}
|
||||||
// 2. Inisialisasi dokumen PDF
|
|
||||||
const { jsPDF } = window.jspdf;
|
const { jsPDF } = window.jspdf;
|
||||||
const doc = new jsPDF({
|
const doc = new jsPDF({
|
||||||
orientation: 'landscape',
|
orientation: 'landscape',
|
||||||
unit: 'mm',
|
unit: 'mm',
|
||||||
format: [50, 35]
|
format: [50, 35]
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. Pengaturan Teks dan Posisi
|
|
||||||
const leftMargin = 2;
|
const leftMargin = 2;
|
||||||
const contentWidth = 50 - (leftMargin * 2);
|
const contentWidth = 50 - (leftMargin * 2);
|
||||||
let yPosition = 4;
|
let yPosition = 4;
|
||||||
@@ -924,34 +918,24 @@
|
|||||||
doc.text(`${kd_spesimen} / ${asalpasien}`, leftMargin, yPosition, {
|
doc.text(`${kd_spesimen} / ${asalpasien}`, leftMargin, yPosition, {
|
||||||
maxWidth: contentWidth,
|
maxWidth: contentWidth,
|
||||||
});
|
});
|
||||||
yPosition += 4; // Geser posisi Y ke bawah untuk barcode
|
yPosition += 4;
|
||||||
|
|
||||||
// 4. Generate Barcode dan tambahkan ke PDF (BAGIAN YANG DIUBAH)
|
|
||||||
try {
|
try {
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
JsBarcode(canvas, nofoto, {
|
JsBarcode(canvas, nofoto, {
|
||||||
format: "CODE128",
|
format: "CODE128",
|
||||||
displayValue: false, // DIUBAH: Tidak menampilkan teks bawaan
|
displayValue: false,
|
||||||
height: 40,
|
height: 40,
|
||||||
width: 1.5,
|
width: 1.5,
|
||||||
margin: 5 // Beri sedikit margin agar tidak terpotong
|
margin: 5
|
||||||
});
|
});
|
||||||
const barcodeDataUrl = canvas.toDataURL('image/png');
|
const barcodeDataUrl = canvas.toDataURL('image/png');
|
||||||
const barcodeHeight = 10; // Tinggi gambar barcode di PDF (dalam mm)
|
const barcodeHeight = 10;
|
||||||
|
|
||||||
// Tambahkan gambar barcode ke PDF
|
|
||||||
doc.addImage(barcodeDataUrl, 'PNG', leftMargin, yPosition, contentWidth, barcodeHeight);
|
doc.addImage(barcodeDataUrl, 'PNG', leftMargin, yPosition, contentWidth, barcodeHeight);
|
||||||
|
|
||||||
// Pindahkan posisi Y ke bawah gambar barcode
|
|
||||||
yPosition += barcodeHeight + 3;
|
yPosition += barcodeHeight + 3;
|
||||||
|
doc.setFont('helvetica', 'bold');
|
||||||
// DITAMBAHKAN: Tulis teks nofoto secara manual di bawah barcode
|
doc.setFontSize(8);
|
||||||
doc.setFont('helvetica', 'bold'); // Set font biasa (tidak bold)
|
const centerX = 50 / 2;
|
||||||
doc.setFontSize(8); // Atur ukuran font agar jelas
|
doc.text(nofoto, centerX, yPosition, { align: 'center' });
|
||||||
const centerX = 50 / 2; // Titik tengah horizontal halaman
|
|
||||||
doc.text(nofoto, centerX, yPosition, { align: 'center' }); // Teks dibuat rata tengah
|
|
||||||
|
|
||||||
// Pindahkan posisi Y untuk baris selanjutnya
|
|
||||||
yPosition += 4;
|
yPosition += 4;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -959,9 +943,7 @@
|
|||||||
doc.text("Error Barcode", leftMargin, yPosition);
|
doc.text("Error Barcode", leftMargin, yPosition);
|
||||||
yPosition += 12;
|
yPosition += 12;
|
||||||
}
|
}
|
||||||
|
doc.setFont('helvetica', 'bold');
|
||||||
// 5. Menambahkan sisa teks
|
|
||||||
doc.setFont('helvetica', 'bold'); // Kembalikan font menjadi bold
|
|
||||||
doc.setFontSize(6.5);
|
doc.setFontSize(6.5);
|
||||||
doc.text(`${noregister} / ${nama} / ${tgllahir}`, leftMargin, yPosition, {
|
doc.text(`${noregister} / ${nama} / ${tgllahir}`, leftMargin, yPosition, {
|
||||||
maxWidth: contentWidth,
|
maxWidth: contentWidth,
|
||||||
@@ -970,8 +952,6 @@
|
|||||||
doc.text(`${reques} ( ${daftartgl} )`, leftMargin, yPosition, {
|
doc.text(`${reques} ( ${daftartgl} )`, leftMargin, yPosition, {
|
||||||
maxWidth: contentWidth,
|
maxWidth: contentWidth,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 6. Tampilkan PDF di tab baru
|
|
||||||
doc.output('dataurlnewwindow');
|
doc.output('dataurlnewwindow');
|
||||||
}
|
}
|
||||||
$(window).on('load', function () {
|
$(window).on('load', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user