qzind / tray

Browser plugin for sending documents and raw commands to a printer or attached device.
https://qz.io
Other
845 stars 275 forks source link

Out of memory on Windows #471

Closed Shirkit closed 5 years ago

Shirkit commented 5 years ago

Hey,

So it seems that the fix commited on #27 did not solve the issue fully. I'm trying to print a page that's not on my server, it's page response from an API I'm using.

The URL in quesiton I'm trying to print is this: http://nfe.webmaniabr.com/danfe/29190734260638000183650010000000661195144527/

So my implementation is doing an AJAX request to that page, grabbing the HTML code and passing to QZ as type: html and format: plain.

While I can do a java -Xms1024m -Xmx1024m -jar "C:\Program Files\QZ Tray\qz-tray.jar", that will not work if QZ-Tray is closed and is launched via the browser (via the wss protocol), which is very likely to happen.

I'm running Windows 10, latest update. Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Google Chrome Canary V77

Any help is appreciated.


2019-07-17 16:05:21,169 [DEBUG] Executing: [C:\Windows\system32\reg.exe, query, HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1, /v, Flags]
2019-07-17 16:05:21,209 [DEBUG] Executing: [C:\Windows\system32\reg.exe, query, HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge\ExperimentalFeatures, /v, AllowLocalhostLoopback]
2019-07-17 16:05:21,379 [INFO] Main properties file C:\Program Files\QZ Tray\qz-tray.properties
2019-07-17 16:05:21,429 [DEBUG] Using trusted root certificate: CN=qzindustries.com, O=QZ Industries, LLC (8ef2c0b2fe3f75754245b3fb9d54c0caa1b46bb3)
2019-07-17 16:05:21,429 [INFO] Loading CRL from https://crl.qz.io
2019-07-17 16:05:21,549 [DEBUG] Executing: [C:\Windows\system32\reg.exe, query, HKCU\Software\Microsoft\Windows\CurrentVersion\Run\, /v, QZ Tray]
2019-07-17 16:05:22,104 [INFO] Successfully loaded 2 CRL entries from https://crl.qz.io
2019-07-17 16:05:22,191 [DEBUG] Checking for a running instance of QZ Tray on port 8283
2019-07-17 16:05:22,219 [DEBUG] Checking for a running instance of QZ Tray on port 8384
2019-07-17 16:05:22,229 [DEBUG] Checking for a running instance of QZ Tray on port 8485
2019-07-17 16:05:22,239 [INFO] Server started on port(s) 8182, 8181
2019-07-17 16:05:35,578 [INFO] Connection opened from /0:0:0:0:0:0:0:1:54797 on socket port 8181
2019-07-17 16:05:35,585 [DEBUG] Message: {"certificate":null,"promise":{},"timestamp":1563390335577,"uid":"1ytdd3","position":{"x":960,"y":520}}
2019-07-17 16:05:35,625 [DEBUG] Calculated dialog centered at: java.awt.Point[x=795,y=437]
2019-07-17 16:05:36,867 [INFO] Allowed An anonymous request to connect to QZ Tray
2019-07-17 16:05:39,719 [DEBUG] Message: {"call":"printers.find","promise":{},"params":{"query":"foxit"},"timestamp":1563390339718,"uid":"k3w1vy","position":{"x":960,"y":520}}
2019-07-17 16:05:39,728 [DEBUG] Calculated dialog centered at: java.awt.Point[x=779,y=437]
2019-07-17 16:05:40,293 [INFO] Allowed An anonymous request to access connected printers
2019-07-17 16:05:40,298 [DEBUG] Searching for PrintService matching foxit
2019-07-17 16:05:40,310 [DEBUG] Found 6 printers
2019-07-17 16:05:40,310 [DEBUG] Found match: Foxit Reader PDF Printer
2019-07-17 16:05:51,676 [DEBUG] Message: {"call":"print","promise":{},"params":{"printer":{"name":"Foxit Reader PDF Printer"},"options":{"colorType":"color","copies":1,"density":0,"duplex":false,"fallbackDensity":null,"interpolation":"bicubic","jobName":null,"legacy":false,"margins":0,"orientation":null,"paperThickness":null,"printerTray":null,"rasterize":true,"rotation":0,"scaleContent":true,"size":null,"units":"in","altPrinting":false,"encoding":null,"endOfDoc":null,"perSpool":1,"_id":88,"_state":1,"_result":"HP LaserJet Professional P1102w","_subscribers":[]},"data":[{"type":"html","format":"plain","data":"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><style>body {    font-family:Arial;    font-size: 9px;}h5, p {    margin: 0pt;}table.items {    font-size: 9px;    border-collapse: collapse;    border: 3px solid #880000;}td {    font-size: 9px;    vertical-align: top;    text-align: center;}table thead td {    background-color: #EEEEEE;    text-align: center;}table tfoot td { background-color: #AAFFEE;    text-align: center;}.barcode {    padding: 1.5mm;    margin: 0;    vertical-align: top;    color: #000000;}.barcodecell {    text-align: center;    vertical-align: middle;    padding: 0;}.menor { font-size: 8px; text-align: center; }</style>\n</head>\n<body>\n<div class='container' style='max-width:300px;padding:5px 5px;'<table width=\"100%\">\n<tr>\n<h2 style='text-align:center;font-size: 16px;margin-top:0px;margin-bottom:5px;'><i>NFC-e</i></h2>\n<td colspan=\"2\"><div style='font-size:8px;'>RESTAURANTE TORRE MOLINOS LTDA<br>CNPJ:34.260.638/0001-83 I.E.:027071003<br>R FRANCISCO GONCALVES, 3  - 1 Andar<br>Comércio, Salvador - BA</div><hr></td>\n</tr>\n<tr>\n<td colspan=\"3\" class=\"menor\"><div style='text-align:center;font-size:9px;'>DANFE NFC-E - Documento auxiliar<br> da Nota Fiscal de Consumidor Eletrônica</td>\n</tr>\n<tr>\n<td colspan=\"3\" class=\"menor\"><br><b>Ambiente de Testes - SEM VALOR FISCAL</b></td>\n</tr>\n</div></table>\n<hr>\n<table width='100%'>\n<tr>\n<td><div style='text-align:left;font-size:8px;'>#</div></td>\n<td><div style='text-align:left;font-size:8px;'>CÓDIGO</div></td>\n<td><div style='text-align:left;font-size:8px;'>DESCRIÇÃO</div></td>\n<td><div style='text-align:right;font-size:8px;'>QTD.</div></td>\n<td><div style='text-align:right;font-size:8px;'>VL.UNIT.</div></td>\n<td><div style='text-align:right;font-size:8px;'>VL.TOTAL</div></td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;font-size:8px;'>1</div></td>\n<td align=\"left\"><div style='text-align:left;font-size:8px;'>f-onca-1-1</div></td>\n<td align=\"left\"><div style='text-align:left;font-size:8px;'>NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</div></td>\n<td align=\"right\"><div style='text-align:right;font-size:8px;'>1 UN</div></td>\n<td align=\"right\"><div style='text-align:right;font-size:8px;'>R$35,00</div></td>\n<td align=\"right\"><div style='text-align:right;font-size:8px;'>R$35,00</div></td>\n</tr>\n</table>\n<hr>\n<table width=\"100%\">\n<tr>\n<td align=\"left\"><div style='text-align:left;'>QTD. TOTAL DE ITENS</div></td>\n<td align=\"right\"><div style='text-align:right;'>1</div></td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;'>VALOR TOTAL R$</div></td>\n<td align=\"right\"><div style='text-align:right;'>35,00</div></td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;'>DESCONTO R$</div></td>\n<td align=\"right\"><div style='text-align:right;'>0,00</div></td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;'><strong>VALOR A PAGAR R$</strong></div></td>\n<td align=\"right\"><div style='text-align:right;'><strong>35,00</strong></div></td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;'>FORMA DE PAGAMENTO</div></td>\n<td align=\"right\"><div style='text-align:right;'>VALOR PAGO R$</div></td>\n</tr>\n<tr>\n<td align=\"left\" style='text-align:left;'>Cartão de Débito</td>\n<td align=\"right\" style='text-align:right;'>35,00</td>\n</tr>\n<tr>\n<td align=\"left\" style='text-align:left;'>Troco R$</td>\n<td align=\"right\" style='text-align:right;'>0,00</td>\n</tr>\n<tr>\n<td align=\"left\"><div style='text-align:left;'>Informação dos Tributos Incidentes<br>(Lei Federal 12.741/2012)</div></td>\n<td align=\"right\"><div style='text-align:right;'>8,40</div></td>\n</tr>\n</table>\n<hr><table width=\"100%\"'>\n<tr>\n<td  colspan=\"3\"><div style='word-break: break-all;font-size:9px'>Consulte pela Chave de Acesso em <br>http://hinternet.sefaz.ba.gov.br/nfce/consulta<br />29190734260638000183650010000000211151363175</div></td>\n</tr>\n</table>\n<table width=\"80%\" align=\"center\">\n<tr>\n<td colspan=\"3\"><b>CONSUMIDOR NÃO IDENTIFICADO</b></td>\n</tr>\n</table>\n<table width=\"80%\" align=\"center\">\n<tr>\n<td>NFCe nº 21</td>\n<td>Série: 001</td>\n<td>10/07/2019 00:34:05</td>\n</tr>\n<tr>\n<td colspan=\"3\">Protocolo de autorização: 329190000156828<br />Data de autorização: 10/07/19 00:34:09</td>\n</tr>\n</table>\n<table width=\"100%\">\n<tr>\n<td  colspan=\"3\"><img src=\"data: image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAADcAQMAAAAhlF3CAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAACz0lEQVRYhe2YMa7jMAxEGbhw6SP4IkZ8LXdOl2sp8EV8BJUugnDfUF4g+xfYbb6i5qswIo8DEBpyOJTZz/rfmt39vj14JHZL555t0stUD5zMhluXzO/+cH285z5dzfqa4OyDYlEEI595gGOJrxmo41jm15gXu7B9fgLc3OOXx3tvC4oyu+zWby8jbne2f/D5/eCZmntepus4nL++5O1HwbMO94hx8C2Nfxfpd4N6f0+z28rDb/NL79LJSiNQR7JD3mXPOrDcP6HRK4Ldw8uPXoTwBaE9yZq1Iqi1wgWEoI5UguXVH7st1ghEJuBCu0kiNenbhHTWBCkC9EkJCYhcvyyUuiF42f0gRnZ81m++h1JZTXAmHfTDS4uAEA4slKoRaJJmlJo0oTRVNUR72aOFVQORA+tgZVVPQKnGQkjfCqRaCQ/BWLrXGCEPR6eH1QMVi6jJ8ixBiPXPGaVK9UCMQSyolxgrltiXTGgAzg+Fp2PS4dws0sTGopqVwNKMUYIVWzYc09XevUkDkOQImRiOOZIDEOk8BaMWqJ6AEoRPchJyDFaCsCYgK/eu2QHVoFMlKwe21ARJyEONOx7ok4c3Of/XBsSuyCJNkmvAHAzeKoJqjFiEHVsqi4BcRWrWBeWOtiRHIqsmzVp0MKVWWoBiJXqWmhQh0x3gJ8fpVQJRJQQpBhQ9CiFQUxxjAxBp9pCJUishnZi5Qlk1cMzyybzCOx6altGJ0ye0AEOVtuif+Dj1rDiw8/jqgJ0XbzKESydDSq0Ub9ICnHSBEMaNBPYY32KKMqsHajG5y728yqg2qGcXs1QJVBhnT1RbRofLvUkzMO4wSju46l6LUXJ92vu9SQVwxpvhSLCIkiuNL2W1BLEICKYsHJ9JP39zWROkPonqstMdU8yNNrzdZn0YVKImBQpvWBjSRLND7iuCUZVh1REGKfWoycVOq94A/Fn/Xr8ArBioDCUH1m8AAAAASUVORK5CYII=\" style='max-width:150px;'></td>\n</tr>\n</table>\n</div></body>\n</html>\n"}]},"timestamp":1563390351672,"uid":"xf66zw","position":{"x":960,"y":520}}
2019-07-17 16:05:51,686 [DEBUG] Calculated dialog centered at: java.awt.Point[x=763,y=437]
2019-07-17 16:05:52,375 [INFO] Allowed An anonymous request to print to Foxit Reader PDF Printer
2019-07-17 16:05:52,427 [DEBUG] Allowing 1 simultaneous processors based on memory available (518 MB)
2019-07-17 16:05:52,434 [DEBUG] Using qz.printer.action.PrintHTML to print
2019-07-17 16:05:52,434 [DEBUG] Searching for PrintService matching Foxit Reader PDF Printer
2019-07-17 16:05:52,436 [DEBUG] Found 6 printers
2019-07-17 16:05:52,436 [DEBUG] Found match: Foxit Reader PDF Printer
2019-07-17 16:05:52,449 [DEBUG] Found Resolution: 60000x60000 dphi
2019-07-17 16:05:52,628 [DEBUG] Started JavaFX
2019-07-17 16:05:52,734 [DEBUG] Parsed 1 html records
2019-07-17 16:05:53,330 [DEBUG] Attempting image capture
2019-07-17 16:05:54,756 [INFO] Starting printing (1 copies)
2019-07-17 16:05:56,658 [DEBUG] Scaling image up by x1.0
2019-07-17 16:05:56,858 [DEBUG] Paper area: 0,0:612,792
2019-07-17 16:05:56,859 [DEBUG] Memory: 333m/494m
2019-07-17 16:05:57,960 [ERROR] Connection error
java.lang.RuntimeException: Cannot call method public void qz.ws.PrintSocketClient#onMessage(org.eclipse.jetty.websocket.api.Session, java.io.Reader) with args: [org.eclipse.jetty.websocket.common.WebSocketSession, org.eclipse.jetty.websocket.common.message.MessageReader]
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.unwrapRuntimeException(CallableMethod.java:93)
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:75)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:68)
    at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver$2.run(JettyAnnotatedEventDriver.java:210)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferInt.<init>(Unknown Source)
    at java.awt.image.Raster.createPackedRaster(Unknown Source)
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
    at java.awt.image.BufferedImage.<init>(Unknown Source)
    at sun.java2d.pipe.DrawImage.makeBufferedImage(Unknown Source)
    at sun.java2d.pipe.DrawImage.renderImageXform(Unknown Source)
    at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
    at sun.java2d.pipe.DrawImage.scaleImage(Unknown Source)
    at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
    at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
    at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
    at sun.java2d.SunGraphics2D.copyImage(Unknown Source)
    at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
    at sun.awt.windows.WPathGraphics.drawImageToPlatform(Unknown Source)
    at sun.print.PathGraphics.drawImage(Unknown Source)
    at sun.print.PathGraphics.drawImage(Unknown Source)
    at qz.printer.action.PrintImage.print(Unknown Source)
    at qz.printer.action.PrintHTML.print(Unknown Source)
    at sun.print.RasterPrinterJob.printPage(Unknown Source)
    at sun.print.RasterPrinterJob.print(Unknown Source)
    at qz.printer.action.PrintPixel.printCopies(Unknown Source)
    at qz.printer.action.PrintImage.print(Unknown Source)
    at qz.printer.action.PrintHTML.print(Unknown Source)
    at qz.utils.PrintingUtilities.processPrintRequest(Unknown Source)
    at qz.ws.PrintSocketClient.processMessage(Unknown Source)
    at qz.ws.PrintSocketClient.onMessage(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:70)
    at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:68)
2019-07-17 16:06:07,932 [INFO] Connection closed: 1005 - null
2019-07-17 16:06:07,934 [INFO] Closing all communication channels for An anonymous request
2019-07-17 16:06:07,939 [WARN] The web socket server is no longer running```
klabarge commented 5 years ago

Java(TM) SE Runtime Environment (build 1.8.0_211-b12)

@Shirkit can you please let us know if you are using the 32-bit or 64-bit version of Java? As explained in this comment, the 32-bit version of Java has a much, much lower heap space.

I was able to print your HTML content fine using AdoptOpenJDK 11.0.4 64-bit

Shirkit commented 5 years ago

Yep, I feel kinda stupid right now. Installing the 64bits Java solved the issue.

Thanks for this awesome software!

tresf commented 5 years ago

Yep, I feel kinda stupid right now. Installing the 64bits Java solved the issue.

Oracle doesn't really explain why, but they made the 64-bit version of Java grab a heap spaced based on available memory. 32-bit is based on a fixed value. It's very confusing! 😄