-
-
Save parzibyte/6faa56c33ef75280f16132b407c402c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
____________________________________ | |
/ Si necesitas ayuda, contáctame en \ | |
\ https://parzibyte.me / | |
------------------------------------ | |
\ ^__^ | |
\ (oo)\_______ | |
(__)\ )\/\ | |
||----w | | |
|| || | |
Creado por Parzibyte (https://parzibyte.me). | |
------------------------------------------------------------------------------------------------ | |
Si el código es útil para ti, puedes agradecerme siguiéndome: https://parzibyte.me/blog/sigueme/ | |
Y compartiendo mi blog con tus amigos | |
También tengo canal de YouTube: https://www.youtube.com/channel/UCroP4BTWjfM0CkGB6AFUoBg?sub_confirmation=1 | |
------------------------------------------------------------------------------------------------ | |
--> | |
<!DOCTYPE html> | |
<html lang="es"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Ejemplo 4 - Imprimir PDF desde la nube según URL</title> | |
</head> | |
<body> | |
<h1>Ejemplo 4 - Imprimir PDF desde la nube según URL</h1> | |
<br> | |
<a href="//parzibyte.me/blog">By Parzibyte</a> | |
<p id="estado"></p> | |
<script> | |
// Estos parámetros podrían venir de cualquier lugar | |
const urlPdf = "https://parzibyte.github.io/plugin-silent-pdf-print-examples/ticket.pdf"; | |
const nombreImpresora = "Microsoft Print to PDF"; | |
const url = `http://localhost:8080/url?urlPdf=${urlPdf}&impresora=${nombreImpresora}`; | |
// Elemento DOM, solo es para depurar | |
const $estado = document.querySelector("#estado"); | |
// Hacer petición... | |
$estado.textContent = "Imprimiendo..."; | |
fetch(url) | |
.then(respuesta => { | |
// Si la respuesta es OK, entonces todo fue bien | |
if (respuesta.status === 200) { | |
$estado.textContent = "Impreso correctamente (salvo que se haya indicado un error por parte de PDFtoPrinter"; | |
console.log("Impresión OK"); | |
} else { | |
// Si no, decodificamos el mensaje para ver el error | |
respuesta.json() | |
.then(mensaje => { | |
$estado.textContent = "Error imprimiendo: " + mensaje; | |
console.log("Error: " + mensaje); | |
}); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment