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

Need a script to display print dialog

Enthusiast ,
Mar 31, 2025 Mar 31, 2025

FrameMaker 2022. Should be simple, but I couldn't find an example.

 

I don't want to use File>Save as PDF. Some of our authors don't have the Adobe PDF printer and it errors out, and I've also had it hang sometimes.

 

I don't want to use Doc.SilentPrintDoc() b/c we don't always use the defaults, and also the selected printer might be Adobe PDF, Power PDF, Microsoft Print to PDF, and that might NOT be the default printer on the users system.

I thought Fcodes([FCodes.KbdPrint]); would at least bring up the menu, but it doesn't seem to.

Ideallly, what I want is to display the menu with the following settings:

  • Page Range - All
  • Do Not Skip Blank Pages
  • Do Not Print to File
  • Do Not Generate Acrobat Data
  • User will select the correct printer
  • Also - some of our documents use an odd paper size (8x5 inches). The documents should be printed at this size. I think the default menu picks this up from the document settings, and if not, I think it would need to be from the printer settings, but we can work around this if necessary.

Example attached:

TOPICS
Scripting
2.4K
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

correct answers 3 Correct answers

Community Expert , Mar 31, 2025 Mar 31, 2025

Documents have a bunch of printer properties that you can set. Did you try these?

image.png

Translate
Community Expert , Mar 31, 2025 Mar 31, 2025

This works:

Fcodes ([FCodes.KBD_PRINT]);
Translate
Enthusiast , Apr 01, 2025 Apr 01, 2025

@frameexpert- Got it, but it wasn't easy. For me, I went to https://adobe.fandom.com/wiki/Adobe_FrameMaker_Developer_Kit - follow the link to https://web.archive.org/web/20181023130035/https://www.adobe.com/devnet/framemaker.html - That downloads, but it gets 182 of 183 MB and fails with a network errror, but it leaves a .zip.part file. Rename that to .zip and you can open it and the file is inside the zip at \products\FDK\FDK15.zip\1\Application\include.

I'm attaching it here, unless that isn't

...
Translate
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Image isn't uploading for me ...

Image: https://github.com/Marshall-Brooks/Sandbox/issues/1

 

 

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 ,
Mar 31, 2025 Mar 31, 2025

In FM2022, Save As PDF and Publish to PDF both use the same new PDF creation tool. Print to PDF is the only thing that uses the older Windows printer instance.

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Okay - I don't want to use Save As PDF or Publish to PDF. How would I code a script to automate the Print to PDF interface? Thanks!

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 ,
Mar 31, 2025 Mar 31, 2025

Documents have a bunch of printer properties that you can set. Did you try these?

image.png

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

@frameexpert - No, not yet. I saw some of those, but I wasn't sure if I just typed doc.printblankpages=1 or if I had to use a GetProps/SetProps menu, and I didn't see how to bring up the print dialog, which I need to select the 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
Community Expert ,
Mar 31, 2025 Mar 31, 2025

There is a PrinterName property. Here is an example from the FDK docs.

image.png

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Again, for some authors, the printer name will be "Adobe PDF", for others it will be "Power PDF", for others, it will be "Microsoft Print to PDF". I'm not sure how to set one of those, test for error, set the other one if error.

Really, I just want to pull up the print dialog, but if I can preset the values that can be controlled, that would be a huge plus.

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 ,
Mar 31, 2025 Mar 31, 2025

You could test for app.UserName and based on the user, select the appropriate printer. Or, you could present a scrollbox with all the printer names and have the user select the appropriate 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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Scrollbox can work! (Is there no easy way to show the diaglog with properties selected?).

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 ,
Mar 31, 2025 Mar 31, 2025

I would have suggested the FCode, but you tried it and it didn't work?

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Thanks - KbdPrint might have been incorrect, I was using an old document for reference.

Specifically this: https://framescr.com/Downloads/ElmScript/RefManual.pdf - Page 328

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 ,
Mar 31, 2025 Mar 31, 2025

This works:

Fcodes ([FCodes.KBD_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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Indeed - it does!!! Thank you!!! (I'll try the other settings also)!

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Script was very simple:

var doc = app.ActiveDoc;
doc.PrintBlankPages = 1;
doc.PrintScope = 1;
doc.GenerateAcrobatInfo = 0;
//doc.PrintPaperWidth = 5;
//doc.PrintPaperHeight = 8;
Fcodes([FCodes.KBD_PRINT]);

I ended up with one minor problem, but I can live with it.

Some of our documents are printed on 5-inch wide by 8-inch high pages.

If I use FIle>Save As PDF, FM sets the paper size correctly, but that gives an error if the Adobe PDF printer is not installed.

If I set it in code like the commented lines above, it seems to be ignored.

If I go to the Print Document menu, and select Printer>Setup>Properties>Layout>Advanced>Paper Size>PostScript Custom Page Size>Edit Custom Page Size and set it to 5 x 8, and then set Paper Size to "PostScript Custom Page Size", it works, but then I have to set it back to Letter for 8.5x11 documents.

But I'm not sure there is a way to automate this. https://community.adobe.com/t5/framemaker-discussions/create-print-pdf-using-extendscript/m-p/138964... - looks like it didn't work here either.
@frameexpert - Do you know what the values should be? - from the other thread, if  54059448 = 291mm, I don't think 5 = 5 inches.

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

If it did the math correctly, 5x8 should be 36565 x 58504. If so, it doesn't work ... 

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 ,
Mar 31, 2025 Mar 31, 2025

5 inches would be 5 * 65536 * 72 but setting these values didn't work for me.

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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Thank you for testing - my numbers were way off, but it looks like it can't be done this way anyway!!!

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 ,
Mar 31, 2025 Mar 31, 2025

I guess I would go ahead and install the Adobe PDF Printer so you can use Save As PDF programmatically.

Or, you can programmatically call the Publish command with a series of CallClient commands:

// Absolute path to .sts file.
setSts (sts);
// Absolute path to output folder.
setOutputFolder (name); 
// Output type. 
callPublisher ("PDF");

function setSts (sts) {  
      
    var cmd = "SetMCPSetting " + sts;  
    return CallClient ("FMPublisher", cmd);  
}
  
function setOutputFolder (folder) {  
      
    var cmd = "SetOutputLocation " + folder;  
    return CallClient ("FMPublisher", cmd);  
}    
  
function callPublisher (type) {  
      
    var cmd = "MCPPublish " + type;  
    return CallClient ("FMPublisher", cmd);  
}
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
Enthusiast ,
Mar 31, 2025 Mar 31, 2025

Adobe PDF Printer can only be installed with a full version of Acrobat, correct?

Will those publish commands above work without the Adobe PDF Printer? File>Save As PDF gave errors.

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 ,
Mar 31, 2025 Mar 31, 2025

Try File > Publish manually. If it works there, the publish commands should work.

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
Enthusiast ,
Apr 01, 2025 Apr 01, 2025

No luck - but learned something new. Publish requires either Adobe PDF Printer or Adobe Distiller 5.0.5 or later, but from what I can tell, neither one can be installed without a full version of Acrobat (most online references say Acrobat Pro, but I think Standard includes it also - I know it does for the Adobe PDF Printer).

 

I'm just going to show an alert to select the custom paper size for the 5x8 documents.

@frameexpert - Where did you find the KBD_PRINT fcode? I could use an updated list, unless it was just trial and error?

Thank you again!

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 ,
Apr 01, 2025 Apr 01, 2025

They are in the fcodes.h file that comes with the FDK. With ExtendScript you have to put the FCodes. prefix on 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
Enthusiast ,
Apr 01, 2025 Apr 01, 2025

@frameexpert- Got it, but it wasn't easy. For me, I went to https://adobe.fandom.com/wiki/Adobe_FrameMaker_Developer_Kit - follow the link to https://web.archive.org/web/20181023130035/https://www.adobe.com/devnet/framemaker.html - That downloads, but it gets 182 of 183 MB and fails with a network errror, but it leaves a .zip.part file. Rename that to .zip and you can open it and the file is inside the zip at \products\FDK\FDK15.zip\1\Application\include.

I'm attaching it here, unless that isn't permissible. (Posted to the GitHub Link above - attachments aren't working for me.)

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 ,
Apr 01, 2025 Apr 01, 2025

FM2022 should have installed an "AdobePDF" printer instance in Windows even if you haven't got the full Acrobat install. That being said, there are a number of threads about the Adobe PDF printer going AWOL from people's systems & instructions on getting it back.

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