These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Trusted function to print to pdf -- is it possible?

khillebrand
Registered: Apr 24 2006
Posts: 26

I would like to create a trusted function to print a particular document to the Adobe PDF printer -- and I would like to capture a filename and specify a particular path.

I have a document level function which performs this task, using the print params object and printing to pdf. But I can't specify a file name or path -- which is why I'd like to created a trusted function.

I created a trusted function to save a document to a specific location and that works fine.... but I can't seem to get the print to pdf function to work.

Is it possible to print to pdf specifying the filename and path?

My Product Information:
Acrobat Pro 8.1.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Actually no, From a trusted function you can run the print driver silently, but the problem is that the PDF print driver pops up a file save dialog. The printParams object does include a special "fileName" property. But this is a path for the "print to file" option. It doesn't work with the PDF printer.

There is a possibility though. If the "fileName" property is specified and print driver name is left blank the PDF will print to postscript. Then you can convert the postscript file to PDF by opening it in Acrobat. Like this:
var pp = this.getPrintParams();pp.fileName = "/c/temp/myDoc.ps";pp.printerName = "";this.print(pp);app.openDoc({cPath:"/c/temp/myDoc.ps", bUseConv:true})this.saveAs(this.path);

This code can only be run from a trusted function.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

khillebrand
Registered: Apr 24 2006
Posts: 26
Great suggestion... and thanks for the quick response. But that's not going to work for our purposes. I was trying to configure a way to make this part of a workflow process where the final stripped down version ends up in a queue without the user having to direct it there. I currently have a few processes in place, but ultimately the user has to direct the file to a particular location.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the mechanics of creating the "stripped" down version work for you, then it's just a matter of figuring out how to direct things. There is no user interaction in the code I provided above, the paths can be set anyway you want.

If you need more control over the process then JavaScript alone is probably not the answer. Have you looked at Acrobat's Intercommunication interface? You can write a VB app that controls Acrobat and calls folder level JavaScript functions, so you get the best of both worlds.

And for creating a "stripped down" version, have you looked at the "doc.flattenPages()" fucntion. This is much easier than printing to PDF.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

khillebrand
Registered: Apr 24 2006
Posts: 26
If I recall correctly, the doc.flattenPages() function does not get rid of the PageOpen scripting and I need to end up with a document without any scripting whatsoever.... Is this correct?

I've worked with VB before but have no idea how it interfaces with Acrobat. Can you point me in the direction of some resources incorporating both VB and Acrobat so I can check that out? That might be the best answer.

And thank you.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You are correct, the "flattenPages" fucntion does not strip out JS, or many other PDF features. It only flattens interactive elements.

There are a couple of documents all about connecting a VB app to Acrobat. You'll find them here:

http://www.adobe.com/devnet/acrobat/interapplication.php

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

khillebrand
Registered: Apr 24 2006
Posts: 26
Perfect. I will definitely look into it. A little light reading! ha!
Thanks so much.
bennyhill
Registered: Nov 7 2008
Posts: 3
I tried putting this in a batch function

myTrustedFunction = app.trustedFunction(
function()
{
app.beginPriv(); // Explicitly raise privilege
var pp = this.getPrintParams();
pp.pageHandling = pp.constants.handling.nUp;
pp.nUpPageOrders = pp.constants.nUpPageOrders.Horizontal;
pp.nUpNumPagesV = 2;
pp.nUpNumPagesH = 1;
pp.nUpAutoRotate = true;
pp.nUpPageBorder = true;
pp.fileName = "/c/temp/myDoc.ps";
pp.printerName = "";
this.print(pp);
app.openDoc({cPath:"/c/temp/myDoc.ps", bUseConv:true})
this.saveAs(this.path);
app.endPriv();
}
);

Any clues on why this doesn't work.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well for one, batch is a privileged context so it doesn't need a trusted function. Second, all you show here is the function definition. It has to be called to do anything. Is it being called?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script