Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Print Button in Adobe to send Fields directly to labels printer for printing using JavaScript

New Here ,
Jan 30, 2022 Jan 30, 2022

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 

TOPICS
Acrobat SDK and JavaScript
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2022 Jan 30, 2022

Have you created a PDF file for the labels?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

No. I am trying to print the string streem from the same PFF

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

This is not possible with a script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2022 Jan 31, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

You can only print entire pages, not parts of pages.

 

Edit: using a script, that is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

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

 

 

 

   

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 01, 2022 Feb 01, 2022

How can you not know it? It should appear in the JS Console window when you run the code. Post it here, please.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2022 Feb 01, 2022

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

And the error message?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 02, 2022 Feb 02, 2022

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2022 Feb 02, 2022

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

All versions of Acrobat have a debugger. Press Ctrl+J to open it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2022 Feb 02, 2022

You'll find a video here on using the Console Window/Debugger:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2022 Feb 04, 2022

It works now from the adobe reader but it does not work when I open the PDF from Evince reader

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2022 Feb 04, 2022

May that the Evince reader doesn't support this. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines