You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Al firmar, la firma aparece válida en el menú de firmas, pero no se ve "dibujada" en el pdf.
Les comparto mi código:
"
<title>Firma de PDF con AutoFirma</title>
<script type="text/javascript" src="js/autoscript.js"></script>
<script type="text/javascript">
window.onload = function () {
AutoScript.cargarAppAfirma();
AutoScript.setServlets(
window.location.origin + "/afirma-signature-storage/StorageService",
window.location.origin + "/afirma-signature-retriever/RetrieveService"
);
};
function showLog(message) {
document.getElementById('console').value += message + '\n';
}
function showSignResultCallback(signatureB64, certificateB64, extraData) {
showLog("Firma OK");
if (extraData) {
var extras = JSON.parse(extraData);
showLog("Fichero cargado: " + extras.filename);
}
document.getElementById('resultField').value = signatureB64;
}
function showErrorCallback(errorType, errorMessage) {
showLog("Type: " + errorType + "\nMessage: " + errorMessage);
}
function doSign() {
const extraParams = {
"signaturePositionOnPageLowerLeftX": 100,
"signaturePositionOnPageLowerLeftY": 100,
"signaturePositionOnPageUpperRightX": 400,
"signaturePositionOnPageUpperRightY": 200,
"signaturePage": 1, // Página donde aparecerá la firma (comienza desde 1)
"signingReason": "Aprobación",
};
AutoScript.sign(
data,
"SHA512withRSA",
"PAdES",
JSON.stringify(extraParams),
showSignResultCallback,
showErrorCallback
);
}
function saveSignature() {
var signature = document.getElementById('resultField').value;
if (!signature) {
alert("No hay firma para guardar.");
return;
}
AutoScript.saveDataToFile(
signature,
"Guardar firma electrónica",
"firma.pdf",
null,
null,
function () { showLog("Guardado OK"); },
showErrorCallback
);
}
</script>
Firma de PDF con AutoFirma
<pre id="response">trayendo pdf …</pre>
<script>
var data = null;
window.addEventListener("load", function () {
fetch("http://localhost:8080/certificados/generar/2/bs64")
.then(response => {
if (!response.ok) {
throw new Error("Error en la solicitud: " + response.status);
}
console.log(response)
return response.text();
})
.then(base64Data => {
data = base64Data;
var binary = atob(base64Data.replace(/\s/g, ''));
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
for (var i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i);
}
const pdfBlob = new Blob([view], { type: "application/pdf" });
const fileURL = URL.createObjectURL(pdfBlob);
const iframe = document.getElementById("pdfIframe");
iframe.src = fileURL;
iframe.onload = () => URL.revokeObjectURL(fileURL);
document.getElementById("response").innerText = "PDF cargado correctamente.";
})
.catch(error => {
console.error("Error:", error.message);
const iframe = document.getElementById("pdfIframe");
iframe.contentDocument.body.innerHTML = "Error al cargar el PDF: " + error.message;
});
});
</script>
<iframe id="pdfIframe" width="600" height="800"></iframe>
<br><br>
<button type="button" onclick="doSign()">Firmar PDF</button>
<br><br>
<textarea id="console" cols="100" rows="10" readonly></textarea>
<br>
<input type="hidden" id="resultField" value="">
<br>
<button type="button" onclick="saveSignature()">Guardar Documento Firmado</button>
"
The text was updated successfully, but these errors were encountered:
Veo que indicas la posición de la firma pero no estás indicando lo que quieres mostrar en la firma, probablemente por eso no "dibuja" nada. Para mostrar un texto tendrías que añadir lo siguiente:
layer2Text=Firmado por $$SUBJECTCN$$ el día $$SIGNDATE=dd/MM/yyyy$$
Eso mostraría el campo Subject del certificado y la fecha en la que se realiza la firma.
Al firmar, la firma aparece válida en el menú de firmas, pero no se ve "dibujada" en el pdf.
Les comparto mi código:
<title>Firma de PDF con AutoFirma</title> <script type="text/javascript" src="js/autoscript.js"></script> <script type="text/javascript"> window.onload = function () { AutoScript.cargarAppAfirma(); AutoScript.setServlets( window.location.origin + "/afirma-signature-storage/StorageService","
}
Firma de PDF con AutoFirma
The text was updated successfully, but these errors were encountered: