Print Button in Adobe to send Fields directly to labels printer for printing using JavaScript
Copy link to clipboard
Copied
Hi Everyone
I have the following request where I want to collect a number of fields in an Adobe doc then compine them in an array so I can compose a list of lables and send it to a sticky lables printer EPSON L90 for printing .
I wrote the following script in a "Print Button" to collect the requested fileds in two arrayes "P_FieldName" & "V_FieldName".
var P_FieldName=[];
var V_FieldName=[];
var pRowStr="";
for (var p=1; p<4; p++) {
if (p>1) pRowStr="_"+p;
for (var i=1; i<13; i++) {
var pField=this.getField("Part NumRow"+i+pRowStr);
var vField=this.getField("Part VendorRow"+i+pRowStr);
if (pField != null){
P_FieldName.push(pField.valueAsString);
V_FieldName.push(vField.valueAsString);
}
}
Would you please help me with the needed code to compine and send those arrays to the EPSON L90 printer for printing them as lables
Copy link to clipboard
Copied
Have you created a PDF file for the labels?
Copy link to clipboard
Copied
No. I am trying to print the string streem from the same PFF
Copy link to clipboard
Copied
This is not possible with a script.
Copy link to clipboard
Copied
The key thing is that Acrobat can't print raw or formatted data, it can only print a PDF. So you have to make a PDF. But JavaScript cannot create normal PDF content. It sounds as if filling a form may be your solution.
Copy link to clipboard
Copied
If I create a form what if the user selected or filled few fields to print. Is the whole form will be printed. Is there a way where I can control how much of the form need to be printed as I am only printing lables on a lables role printer and I just want to print the filled fields to save lables roles.
Copy link to clipboard
Copied
You can only print entire pages, not parts of pages.
Edit: using a script, that is.
Copy link to clipboard
Copied
If you want to print texts what you need to do is create a new (temporary) file, write those texts to it, and then print it, and close it when done. You can also create a template file in advance with the desired layout, open it using a script, fill in the fields in it with the texts, and then print it. All of that will require an advanced, custom-made script, though.
Copy link to clipboard
Copied
I have decided to create three pages at the end of the PDF, add a text field is each page, then I will append the field with the fields that the user will fill out. However whenever I try to print the last 3 pages silently and predefine the range of pages to be printed using the following script unfortunatly the print window opens and there is no any predefined rage of pages for printing. Any ideas why this function does not work. Given that I am using Nitro Pro 7.5.0.22
this.print({
bUI: fales,
bSilent: true,
bShrinkToFit: true,
nStart: 4,
nEnd: pr
}); // pr is a variable of the last page to print
Copy link to clipboard
Copied
You misspelled "false" under bUI, but regardless, did you see this note under that method's documentation?
Outside of batch, console, and menu events, the values of bUI and of interactive are ignored
and a print dialog box will always be presented.
Copy link to clipboard
Copied
Thank you for the comments.
Could you please advise me on how to silently print out a range of pages?
I appreciate if you could provide me with a sample code.
Copy link to clipboard
Copied
To print silently, and to also create a new label document, you need a folder level automation script. Scripts inside a PDF are heavily restricted. But a folder level automation script could create a new, temporary PDF of the labels and silently print it. Here's an article that explains automation in more detail:
https://www.pdfscripting.com/public/Automating-Acrobat.cfm
This is an advanced scripting task.
A simpler alternative is to do as you've suggest, add label pages at the end of the form, or create a PDF with fields pre-placed for the labels. This separate 'label' PDF will need to be "disclosed". A document level script, such as your print button can open the label document and copy data from the PDF form into the prepositioned fields, then print it, but not silently.
To print silently you could use a folder level trusted function helper.
Here is an article on the topic.
https://www.pdfscripting.com/public/Using-Trusted-Functions.cfm
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you so much for this valuable information. I will go with second approach where I will call the this.print() funtion to luach the Print window. Can I load the Print window with a predefined Printer Name and printing pages range. The following fuction does not work:
this.print({
bUI: false,
bShrinkToFit: true,
nStart: FisrtPage,
nEnd: LastPage
// });
Also the following fuvtion did not work:
var pp = this.getPrintParams ();
pp.firstPage = FisrtPage;
pp.lastPage = LastPage;
pp.printerName = "Printer1";
this.print (pp);
Copy link to clipboard
Copied
Saying "it doesn't work" is not very helpful to us. You need to provide exact details.
Does the print dialog appear at all, but without any of the settings you specified to it?
Are there any error messages in the JS Console when you run the code?
From where are you running the code, and what's the full code?
Copy link to clipboard
Copied
This code is under the Print Button:
The following function opens the Print Window but does not predefine the printing range. Also I need to be able to predefine the Printer Name:
this.print({
bUI: false,
bShrinkToFit: true,
nStart: 4,
nEnd: 7
});
The following function does not work at all. There is an error happen at the first line but I do not know the error number or description.
var pp = this.getPrintParams ();
pp.firstPage = 4;
pp.lastPage = 7;
pp.printerName = "Printer1";
this.print (pp);
Copy link to clipboard
Copied
How can you not know it? It should appear in the JS Console window when you run the code. Post it here, please.
Copy link to clipboard
Copied
Here is my code
this.print({
bUI: false,
bSilent: true,
bShrinkToFit: true,
nStart: 4,
nEnd: 7
// });
var pp = this.getPrintParams ();
pp.firstPage = 4;
pp.lastPage = 7;
pp.printerName = "Printer1";
//pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);
Copy link to clipboard
Copied
And the error message?
Copy link to clipboard
Copied
Why did you comment out the last line of the first part? Why are you using that first part in the first place? It can't do what you want. Only use this:
var pp = this.getPrintParams();
pp.firstPage = 4;
pp.lastPage = 7;
pp.printerName = "Printer1";
//pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);
Copy link to clipboard
Copied
I'm confused about what is actually under the print button. You first showed two "print" commands as alternative, saying one doesn't work. But now it seems you have both together (with an error caused by a // as eagle-eyed try67 has found). When we ask for code it's important to copy/paste all of it and be clear. There are no generic answers, only the exact details, as we look for mistakes and misunderstandings (which all we programmers make).
Copy link to clipboard
Copied
I am using only one function in my code. I just shared both of them in my previouse post to show you what I am doing. also I do not have a debuger on my adobe.
Whenever I use the following function it opens the Print window but there is no any predefined range of pages:
this.print({
bUI: false,
bSilent: true,
bShrinkToFit: true,
nStart: 4,
nEnd: 7
});
Whenever I use the following one nothing happends and I do not know the error number because I do no thave a debuger.
var pp = this.getPrintParams ();
pp.firstPage = 4;
pp.lastPage = 7;
pp.printerName = "Printer1";
pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);
Copy link to clipboard
Copied
All versions of Acrobat have a debugger. Press Ctrl+J to open it.
Copy link to clipboard
Copied
You'll find a video here on using the Console Window/Debugger:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
It works now from the adobe reader but it does not work when I open the PDF from Evince reader
Copy link to clipboard
Copied
May that the Evince reader doesn't support this.


-
- 1
- 2