Página web
GenerarImagenAPartirDePaginaWebEImprimir
Genera una imagen a partir del html generado por la página web ubicada en la dirección indicada usando el ancho provisto como el ancho de la pantalla del navegador web para renderizar la imagen. Después, imprime esa imagen generada. Es necesario que wkhtmltoimage se encuentre en la PATH o en el mismo directorio que el plugin. La imagen será convertida a blanco y negro. Si el ancho de la imagen es mayor que el máximo ancho especificado, la imagen será redimensionada para que coincida. El algoritmo se refiere al algoritmo utilizado al imprimir la imagen, que puede ser 0 para usar el método Raster Bit Image, 1 para Bit Image Column Format y 2 para NV Graphics. Las impresoras más recientes soportan NV Graphics, las antiguas soportan Raster Bit Image e Image Column Format. Lo recomendable es que el usuario pruebe con los 3 algoritmos para encontrar el más adecuado. Más información sobre los algoritmos: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ . El parámetro sobre el dithering indica si se debe aplicar el algoritmo Floyd-Steinberg-Dithering a la imagen antes de ser impresa. Es recomendado aplicarlo en fotografías, así se mantiene la iluminación y los detalles incluso al ser convertida a blanco y negro. Más información sobre dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
Aviso
wkhtmltoimage debe existir en la PATH para que esta operación funcione, necesitas wkhtmltoimage en la PATH o en el mismo directorio donde el plugin se ejecuta
Pruébalo en el área de pruebas
Argumentos
URL de la página públicamente accesible (argumentos[0]
)
Descripción: URL de la página públicamente accesible
Índice: 0
Tipo: string
Ejemplo: https://example.com
Ancho de página del navegador web (argumentos[1]
)
Descripción: Ancho de página del navegador web
Índice: 1
Tipo: float64
Ejemplo: 380
Máximo ancho de la imagen. Si el verdadero ancho es mayor, se reducirá (argumentos[2]
)
Descripción: Máximo ancho de la imagen. Si el verdadero ancho es mayor, se reducirá
Índice: 2
Tipo: float64
Ejemplo: 380
Algoritmo para convertir imagen a bytes ESC POS (0, 1 o 2) (argumentos[3]
)
Descripción: Algoritmo para convertir imagen a bytes ESC POS (0, 1 o 2)
Índice: 3
Tipo: float64
Ejemplo: 0
Aplicar algoritmo dithering. Recomendado en fotografías, no ilustraciones (argumentos[4]
)
Descripción: Aplicar algoritmo dithering. Recomendado en fotografías, no ilustraciones
Índice: 4
Tipo: bool
Ejemplo: false
Ejemplo
Agrega esta operación a la lista de operaciones que enviarás en la clave operaciones
.
Su nombre es GenerarImagenAPartirDePaginaWebEImprimir
, así que ese valor va en la clave nombre
. Después coloca los argumentos en el arreglo argumentos
No olvides revisar el tipo de dato de cada argumento
{
"nombre": "GenerarImagenAPartirDePaginaWebEImprimir",
"argumentos": [
"https://example.com",
380,
380,
0,
false
]
}
Consejos
Recuerda: la lista de operaciones (operaciones
) puede tener infinitas operaciones, esta es solo una de ellas
Ejemplo (JavaScript lado del cliente)
Área de pruebas
Pruébalo en el área de pruebas
Select an operation below
const payload = {
"serial": "",
"nombreImpresora": "",
"operaciones": []
};
const httpResponse = await fetch("http://localhost:8000/imprimir", {
method: "POST",
body: JSON.stringify(payload)
});
const response = await httpResponse.json();
if (respuesta.ok) {
console.log("Printed successfully")
} else {
console.error("Request OK but plugin error: " + respuesta.message);
}
Iniciar: Initialize printer.Clean the data in the buffer and restart the printer to the state it was when it was turned on. In some printers it is recommended to invoke this function before and after printing images.
EscribirTexto: Write text in the printer. The text will not be printed until a line jump (\n) is found or Feed is invoked
Pulso: It generates an electric pulse (used to open the cash drawer) taking into account the on time which are the milliseconds to turn on and the milliseconds to turn off according to the off time. The pin can be 48 or 49. The recommended pin is 48, on time of 60 and off time of 120.
CorteParcial: Partial cut
Corte: Full cut
Feed: Print the data stored in the printer buffer (stored when writing text) and feeds paper a number of lines
TextoSegunPaginaDeCodigos: Allows you to write diacritic text. You have to specify the page number (according to the printer) and the Character Code Page for ICONV. It is suggested to try every combination if it does not work at first. This function has no effect if the used plugin version is the version that has no iconv
EstablecerAlineacion: Set text, images, barcodes and QR codes justification according to the alignment providad. Left is 0, center 1 and right 2
EstablecerTamañoFuente: Set the font size according to the width and height multiplier. Both values can range from 1 to 8. It also affects personalized characters
EstablecerSubrayado: Enable or disable underlined text mode
EstablecerEnfatizado: Enable or disable bold text mode
EstablecerImpresionAlReves: Enable or disable upside down print
EstablecerRotacionDe90Grados: Enable or disable 90 degrees rotation
EstablecerImpresionBlancoYNegroInversa: Enable or disable inverse print. In reverse mode, the background is black and the text is white
EstablecerFuente: Set the font, which can be 0 or 1. In my case it only supports a source that is the A. Be careful when changing the font and trying to print a personalized character, because at the moment it only works with the source to
HabilitarCaracteresPersonalizados: Enable custom characters. If it is enabled then you will print the custom character instead of the character that was supplied to be replaced
DeshabilitarCaracteresPersonalizados: Disable custom characters
DeshabilitarElModoDeCaracteresChinos: Disable chinese character mode. Use it when printing diacritic text and you have a chinese printer. Use it along with TextoSegunPaginaDeCodigos
HabilitarElModoDeCaracteresChinos: Enable chinese character mode
DefinirCaracterPersonalizado: Defines a custom 24x12 character. It is useful for printing characters not supported by some printers, either the euro, penny or what you can draw in a 24x12 box. This function establishes the personalized character but does not print it. Only It is necessary to call it once, and then every time the replaced character is printed, the custom character will be printed instead. The matrix as string must be, as its name says, a matrix as a string. You must have exactly 24 lines (separated by a line jump) and in each line there must be exactly 12 digits, each digit must be a 1 or 0. There should be no tabulations or extra spaces Note: The matrix is 24x12 because this is the source A. If it were the source B would be 17x9, but that source doesn't work in my printer so I haven't tried. So, do not try this if you have source B select. For this operation to work, you need to call HabilitarCaracteresPersonalizados before
CargarImagenLocalEImprimir: Prints an existing image on the file system, provided that the plugin has the permissions to access it. The image will be converted to black and white. If the width of the image is greater than the maximum width specified, the image will be resized to match. Algorithm refers to the algorithm used when printing an image, which can be 0 for using the Raster Bit Image method, 1 for Bit Image Column Format and 2 for NV Graphics. Newer printers support NV Graphics, older ones support Raster Bit Image and Image Column Format. It is recommended that the user tries all 3 algorithms to find the most suitable one. More information about the algorithms: https://parzibyte.me/blog/2024/01/17/methods-for-printing-images-thermal-printers/ . The dithering parameter indicates whether the Floyd-Steinberg-Dithering algorithm should be applied to the image before it is printed. It is recommended to apply it to pictures (and no illustrations), so that the lighting and details are maintained even when converted to black and white. More information about dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
DescargarImagenDeInternetEImprimir: Download an internet image and print it. The image must be publicly accessible using only the URL. The image will be converted to black and white. If the width of the image is greater than the maximum width specified, the image will be resized to match. Algorithm refers to the algorithm used when printing an image, which can be 0 for using the Raster Bit Image method, 1 for Bit Image Column Format and 2 for NV Graphics. Newer printers support NV Graphics, older ones support Raster Bit Image and Image Column Format. It is recommended that the user tries all 3 algorithms to find the most suitable one. More information about the algorithms: https://parzibyte.me/blog/2024/01/17/methods-for-printing-images-thermal-printers/ . The dithering parameter indicates whether the Floyd-Steinberg-Dithering algorithm should be applied to the image before it is printed. It is recommended to apply it to pictures (and no illustrations), so that the lighting and details are maintained even when converted to black and white. More information about dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
GenerarImagenAPartirDeHtmlEImprimir: It generates an image from the HTML using the page width as the width of the screen of the web browser to render the image, and then prints the generated image. The image will be converted to black and white. If the width of the image is greater than the maximum width specified, the image will be resized to match. Algorithm refers to the algorithm used when printing an image, which can be 0 for using the Raster Bit Image method, 1 for Bit Image Column Format and 2 for NV Graphics. Newer printers support NV Graphics, older ones support Raster Bit Image and Image Column Format. It is recommended that the user tries all 3 algorithms to find the most suitable one. More information about the algorithms: https://parzibyte.me/blog/2024/01/17/methods-for-printing-images-thermal-printers/ . The dithering parameter indicates whether the Floyd-Steinberg-Dithering algorithm should be applied to the image before it is printed. It is recommended to apply it to pictures (and no illustrations), so that the lighting and details are maintained even when converted to black and white. More information about dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
GenerarImagenAPartirDePaginaWebEImprimir: It generates an image from the HTML generated by the website located in the provided URL using the providad width as the width of the screen of the web browser to render the image. Then, that generated image is printed. You need wkhtmltoimage located on the PATH or in the same directory of the plugin. The image will be converted to black and white. If the width of the image is greater than the maximum width specified, the image will be resized to match. Algorithm refers to the algorithm used when printing an image, which can be 0 for using the Raster Bit Image method, 1 for Bit Image Column Format and 2 for NV Graphics. Newer printers support NV Graphics, older ones support Raster Bit Image and Image Column Format. It is recommended that the user tries all 3 algorithms to find the most suitable one. More information about the algorithms: https://parzibyte.me/blog/2024/01/17/methods-for-printing-images-thermal-printers/ . The dithering parameter indicates whether the Floyd-Steinberg-Dithering algorithm should be applied to the image before it is printed. It is recommended to apply it to pictures (and no illustrations), so that the lighting and details are maintained even when converted to black and white. More information about dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
ImprimirImagenEnBase64: Convert the base64 string to an image. The encoded image in Base64 can be JPG or PNG and may or may not have the "base64,". The image will be converted to black and white. If the width of the image is greater than the maximum width specified, the image will be resized to match. Algorithm refers to the algorithm used when printing an image, which can be 0 for using the Raster Bit Image method, 1 for Bit Image Column Format and 2 for NV Graphics. Newer printers support NV Graphics, older ones support Raster Bit Image and Image Column Format. It is recommended that the user tries all 3 algorithms to find the most suitable one. More information about the algorithms: https://parzibyte.me/blog/2024/01/17/methods-for-printing-images-thermal-printers/ . The dithering parameter indicates whether the Floyd-Steinberg-Dithering algorithm should be applied to the image before it is printed. It is recommended to apply it to pictures (and no illustrations), so that the lighting and details are maintained even when converted to black and white. More information about dithering: https://parzibyte.me/blog/2024/07/28/algoritmo-floyd-steinberg-dithering-golang/
ImprimirCodigoDeBarrasCode39: Print a bar code in CODE39 format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasCode93: Print a bar code in CODE93 format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasPdf417: Print a barcode in PDF417 format. The algorithm refers to the algorithm used to convert the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm Note: The security level is related to the barcode generation algorithm itself, not to the plugin. It must be between 0 and 8
ImprimirCodigoDeBarrasUpcA: Print a bar code in UPCA format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasUpcE: Print a bar code in UPC E format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasEan: Print a bar code in EAN format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasEan8: Print a bar code in EAN8 format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasTwoOfFiveITF: Print a barcode on TWO of Five Itf format (interleaved 2 of 5). The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm Note: The "interleaved" parameter is typical of the barcode algorithm, not the plugin
ImprimirCodigoDeBarrasCodabar: Print a barcode in Codabar format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoDeBarrasCode128: Print a bar code in CODE128 format. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm
ImprimirCodigoQr: Print a QR code. The algorithm refers to the algorithm used to print the image, which can be 0 to use the Raster Bit Image method, 1 for BIT Image Column Format and 2 for NV Graphics. The most recent printers support NV Graphics, the old support Raster Bit Image and Image Column Format. More information about algorithms: https://parzibyte.me/blog/2024/01/17/metodos-imprimir-imagenes-impresoras-termicas/ The other parameters are related to the code generation algorithm Note: The error correction is related to the QR generating algorithm, not the plugin. It can be 0 (low), 1 (medium), 2 (high) and 3 (Highest). Medium is recommended
Beep: Beeps the buzzer. Produces a sound in the thermal printer. Also take a look at BeepAndSound
BeepAndAlarm: Beeps the buzzer (Produces a sound in the thermal printer) and turns on the integrated LED (alarm). It is useful for making a beep and notify something. In my printer, Beep ignores the duration of the sound, but BeepAndAlarm takes it into account. With this operation, you can either emit a sound, silently turn on the LED, both, or neither.
Ejemplo de código
const cargaUtil = {
"serial": "",
"nombreImpresora": "Nombre_impresora",
"operaciones": [
{
"nombre": "GenerarImagenAPartirDePaginaWebEImprimir",
"argumentos": [
"https://example.com",
380,
380,
0,
false
]
}
]
};
const respuestaHttp = await fetch("http://localhost:8000/imprimir",
{
method: "POST",
body: JSON.stringify(cargaUtil),
});
const respuestaComoJson = await respuestaHttp.json();
if (respuestaComoJson.ok) {
// Todo bien
console.log("Impreso correctamente");
} else {
// El error está en la propiedad message
console.error(respuestaComoJson.message)
}
JSON de ejemplo sin codificar
Codifica el siguiente JSON y envíalo a http://localhost:8000/imprimir
con el método POST
{
"serial": "",
"nombreImpresora": "Nombre_impresora",
"operaciones": [
{
"nombre": "GenerarImagenAPartirDePaginaWebEImprimir",
"argumentos": [
"https://example.com",
380,
380,
0,
false
]
}
]
}
JSON de ejemplo codificado
Envía esta cadena JSON ya codificada a http://localhost:8000/imprimir
con el método POST
{"serial":"","nombreImpresora":"Nombre_impresora","operaciones":[{"nombre":"GenerarImagenAPartirDePaginaWebEImprimir","argumentos":["https://example.com",380,380,0,false]}]}