Print different documents and copies of each in the same page

111 views
Skip to first unread message

Itzayana Arzola

unread,
Jun 1, 2021, 5:24:56 PM6/1/21
to qz-print
Hello Everybody, 

Hope this emails finds you well

I need your help. Right now I've been working with an old version (1.9) but now I want to change it. Honestly I don't know how the latest version works, that's the reason why I decided to work with version 2.0.7 and I have a problem . I'm gonna explain myself ...

I changed the original demo for this, 
image.png
and I don't know how to make it print different documents with different numbers of copies in each. Attached the code with the "progress" that I did but I don't know if it is correct or not. 

The variables I get them with a session of php. 

I hope you can help me. 
Thank you in advance, and I will be awaiting your response.  
nuevo.php

Tres Finocchiaro

unread,
Jun 2, 2021, 12:15:43 AM6/2/21
to Itzayana Arzola, qz-print
Hi,

Please see this feature, which is only available with QZ Tray 2.1:


You will need to use the qz-tray.js file from QZ Tray 2.1 as well.

I understand you've started to work with QZ Tray 2.0.7, but this new API was designed to do exactly as you're trying.

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qz-print/CAM4c54YY249rb3UFp%2ByNt_57UXUCo00feboeYNb%3Dvhx8tPAnxw%40mail.gmail.com.

Tres Finocchiaro

unread,
Jun 2, 2021, 12:18:59 AM6/2/21
to Itzayana Arzola, qz-print
If you would rather use 2.0.7, you can chain your promises using:

var config = ...;
var data = ...;
qz.print(config, data).then(() => {
   var config = ...;
   var data = ...;
   return qz.print(config, data);
}).then(() => {
   var config = ...;
   var data = ...;
   return qz.print(config, data);
})
... and so on.

We also can provide a promise loop snippet if that is preferred, but 2.1 will simply this allowing array of configs and array of data arrays.

Itzayana Arzola

unread,
Jun 2, 2021, 2:56:22 PM6/2/21
to Tres Finocchiaro, qz-print
Hi, 

Thank you for your help, but I think that I'm pretty lost with the code. 

I saw the feature with the version 2.1 but the function "qz.configs.create('PDFWriter');" I have to create in the qz.tray.js ? how? The function PrintPDF is called with the same button ? What about the number of copies with each file? 

I´m sorry for don´t understanding but I can't catch it yet. =(

Could you help me a little bit more?, Please. 

Thank you in advance again, and I will be awaiting your response.  

Tres Finocchiaro

unread,
Jun 2, 2021, 3:57:15 PM6/2/21
to Itzayana Arzola, qz-print
What about the number of copies with each file? 

Copies is a parameter supplied with the config: https://qz.io/wiki/pixel#copies

This means you should send an array of configs and an array of data to the qz.print(...) API.

How you provide this is up to you.   If you're controlling it from PHP, it would be the same as any other PHP->JavaScript variables.

Normally, qz.print(...) is called with two parameters:
  • config (print options)
  • data[] (array of content to print)
... however QZ Tray 2.1 supports:
  • config[] (array of configs)
  • data[][] (array of arrays of content to print)
This means you can specify copies in an array the same size as the data[][] and QZ will handle them in the order they are received.

If you don't want to use this, you can use the Promise ".then()" chaining method from my previous email, but this may prove harder to control.

Note, we generally don't help with PHP->JavaScript on this mailing list as it's out of scope.  QZ Tray is just a JavaScript API so we try to focus on that and not any nuances caused by the back-end language.  I hope you understand.
 

Itzayana Arzola

unread,
Jun 4, 2021, 3:30:23 PM6/4/21
to Tres Finocchiaro, qz-print
Hi Tres 

I get it, now I have another question and I hope you can help me. 

Exists a way to change the defaults of copies equal 0, that is, I changed the value in the function resetPixelOptions,  updateConfig  and qz-tray.js file too, but it is still printing one copy. The reason for this is because I don't want the function sent to print if my variable that I get from PHP is 0.  But for now I write manually as you can see , the function prints one copy each anyway. 

image.png

Thanks again and  I will be awaiting your response -



Tres Finocchiaro

unread,
Jun 4, 2021, 3:48:10 PM6/4/21
to Itzayana Arzola, qz-print
I'd recommend a loop and use array.push if > copies 0.    We don't currently expect copies to be less than zero.

Reply all
Reply to author
Forward
0 new messages