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

JavaScript Needed - Print Button with Custom Print Settings

Explorer ,
Oct 12, 2023 Oct 12, 2023

Hi Smart People...

 

I have a document I need to add a PRINT TO PDF Button to for the team to use after filling in the form fields.  The document will be faxed and returned to us signed and sometimes has important info cut off due to the form running too close to the edges.  There are Visable but does not print fields on the document as well.

What I am thinking is I can create a PRINT TO PDF button the team can click that will print the document with a Custom Scale of 90% to the Adobe PDF printer.  I am assuming I will need to add a Mouse Up trigger to the button to Run a JavaScript to accomplish this.  Any chance someone can help me with the JavaScript?

TOPICS
How to , JavaScript , PDF , PDF forms
2.9K
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 13, 2023 Oct 13, 2023

You can, but you can't specify the file-name. The user will have to do that manually.

You can use something like this for that:

 

var pp = this.getPrintParams();
pp.printerName = "Adobe PDF";
pp.pageHandling = pp.constants.handling.fit;
this.print(pp);

View solution in original post

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 ,
Oct 12, 2023 Oct 12, 2023

You can't set the Scale to an exact percentage using a script. You can set it to the Fit option, which will mean all the document's contents will be scaled to fit on the page. But why are you printing to the Adobe PDF printer? Why not print it directly to the physical printer?

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
Explorer ,
Oct 12, 2023 Oct 12, 2023

Hello Try67.  I am asking the team to print to PDF so they can fax out using eFax without the "Visable but doesn't print" fields showing on the document.  They can print to Adobe PDF to save the document on their desktop without those fields before sending to the recipient.

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 ,
Oct 12, 2023 Oct 12, 2023

There are much easier ways to do that. You can use a script to change those fields to hidden, then flatten the form fields, for example.

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
Explorer ,
Oct 12, 2023 Oct 12, 2023

Hi again...  I need the fields to be visable while the team is filling out the form as they contain instructions and checkboxes that activate javascript.  After the document is complete, i need them removed so the recipient does not see them.

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 ,
Oct 12, 2023 Oct 12, 2023

I understood, and that's what the code I suggested will do.

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
Explorer ,
Oct 13, 2023 Oct 13, 2023

I'm intrigued and would love to learn how to do that.  For most of our documents, we also have to print to PDF because we merge the documents in to a packet of other documents that sometimes have form fields with the same name causing the information typed in to them to overwrite info on the document we are adding to the packet.

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 ,
Oct 13, 2023 Oct 13, 2023

You can do it using this code:

 

for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	var f = this.getField(fname);
	if (f==null) continue;
	if (f.display!=display.visible) f.display = display.hidden;
}
this.flattenPages();

 

Note that the flatten command is NOT reversible, so make sure to save the file under a new name, or to keep a backup copy of the original, just in case.

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
Explorer ,
Oct 13, 2023 Oct 13, 2023

perfect...  you're the best!  Ill give it a shot.  Any chance you know if I can make the print button still to print to Adobe PDF, even if I can't choose 90% scale?

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 ,
Oct 13, 2023 Oct 13, 2023

You can, but you can't specify the file-name. The user will have to do that manually.

You can use something like this for that:

 

var pp = this.getPrintParams();
pp.printerName = "Adobe PDF";
pp.pageHandling = pp.constants.handling.fit;
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
Explorer ,
Oct 13, 2023 Oct 13, 2023
LATEST

Perfect...  thank you very much!!

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