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

Saving PDF with Javascript does not Compress the PDF

New Here ,
Apr 24, 2020 Apr 24, 2020

Copy link to clipboard

Copied

To make life easier for our users we have created a button in Adobe that allows the user to save the file in a shared drive with a single click.   

 

// checkFD function checks to make sure the user has access to the shared drive
function checkFD(){

	var checkd = false;
	var checkn = false;

	app.beginPriv();

	try{
//checks for the file		
this.importDataObject("myFile", "/192.168.3.57/checkthisfile.txt");
		var myData = this.getDataObject("myFile");
	}catch(e){
//alerts user if the shared drive is not found
		app.alert("F Drive not found, please establish VPN connection to office before using button.");
		app.endPriv();
		return;
	}

	while (checkd == false){
//it asks the user to enter two parameters for the file name - deal number and document name
		var d = app.response("Enter Deal Number:", "Enter Deal Number", "");			
		if (d && d.length > 0){
			var temp = d.replace(/[|&*;$%@"<>+,]/g, "");
			if (temp.length != d.length){
// it checks for special characters
				app.alert("Special characters detected, please do not use symbols such as |&*;$%@<>+,.");
			}else{
				checkd = true;	
			}
		}else if (d == ""){
// it checks if the user entered blank
			app.alert("No Deal Number was entered.");
		}else if (d == null){
			//cancel
			checkd = true;
			app.endPriv();
			return;
		}
	}

	while (checkn == false){
		var n = app.response("Enter Document Name:", "Enter Document Name", "");	
		if (n && n.length > 0){
			var temp = n.replace(/[|&*;$%@"<>+,]/g, "");			
			if (temp.length != n.length){
				app.alert("Speical characters detected, please do not use symbols such as |&*;$%@<>+,.");
			}else{
				checkn = true;	
			}
		}else if (n == ""){
			app.alert("Please enter valid Document Name.");
		}else if (n == null){
			//cancel
			checkn = true;
			app.endPriv();
			return;
		}
	}
	
	try{
// it calls the savePDF fucntion if all conditions are met
		savePDF(d, n);
	}catch (e){
		app.alert("Folder not found, please ensure Folder exists on F Drive.");
		app.endPriv();
		return;
	}
	app.endPriv();
}

function savePDF(d, n){
//it renames the file with the parameters
	var fname = n + "-" + d + ".pdf";
	var dr = d.substring(0,2);
	
	if (dr == "DR"){
//if the file starts with the letters DR it saves them here
		var fpath = "/c/testpdf/DR/" + d + "/" + fname;
	}else{
//if the file doesn't start with DR it saves them here
		var fpath = "/c/testpdf/Existing/" + d + "/" + fname;
	}	
// it saves the file to the shared drive
	this.saveAs(fpath);	
}
//Un-Comment this to enable Console Menu Item (For Debugging)
//app.addMenuItem({cName:"Console Window", cParent:"View", cExec:"console.show()"});
app.addMenuItem({cName:"Save to F Drive", cParent:"File", nPos:9, cExec:"checkFD()"});

//Doesn't work for current versions of DC
//app.addToolButton({cName:"myButton", cToolText:"Save to F Drive", cExec:"checkFD()"});

  However, when using the SaveAs command we realize it isn't compressing the PDF like just a normal Save in Acrobat would do - so for example a file saved through the normal adobe Save As script is about 850KB - a file saved through my javascript above is about 34MB. 

 

are there any JS commands that will compress the file as it is being saved?

 

Thanks


Shane Kelly

 

TOPICS
Acrobat SDK and JavaScript

Views

88

Likes

Translate

Translate

Report

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 ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

Unfortunately, no.

Likes

Translate

Translate

Report

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 ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

Did you test this script with Acrobat Reader and with Acrobat Pro?

The first one sometimes lacks the functions found in the second.

Likes

Translate

Translate

Report

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 ,
Apr 25, 2020 Apr 25, 2020

Copy link to clipboard

Copied

LATEST

Yes - we have tried it with both.

 

Likes

Translate

Translate

Report

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