Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
Barry MacDonnell's Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel® WordPerfect® for Windows® |
Page updated Apr 28, 2024 |
|
SaveAsPDF - A macro to automate saving the current document as a PDF file to any drive or folder |
||
Related pages - • Publishing to PDF with WordPerfect 9 (c.1999) and later versions (tips on the feature and some simple macros) |
Purpose and operation When
you have more than a few PDF files to create from WordPerfect
documents, or PDF(s) to create from the same file(s) on a frequent
basis, SaveAsPDF.wcm can help automate the task.
Note that the macro uses WordPerfect's own File, Publish to PDF feature to create and save the current on-screen document as a PDF file — but unlike the standard Publish to PDF feature it can save the PDF to a specified drive and folder. The specific PDF location can be easily changed when the macro plays from a pop up menu (or more permanently with a simple modification to the macro as described below): This can be useful if you want to quickly convert several open documents to PDFs and store them in a different location, rather than the same location as the on-screen document which is the WordPerfect program default (and the macro default when you use it without modification). Just play it while the cursor is in any open WordPerfect document. You can then verify and optionally change the target drive and folder (in the first field, which also has a Browse button), and if desired, change the name of the PDF file that will be generated when you click OK. Main advantages • Your preferred default folder for the generated PDF file can be specified (i.e., made relatively permanent) inside the macro's redlined User Modification Area at the top of the macro code.
Note:
In the download version of the macro, the folder that is specified as the preferred default is the same folder as your current on-screen WPD document — which is the way WordPerfect's Publish to PDF feature works. This location also acts as a "placeholder" for the menu's first field, and will of course work, but — to accomplish the main purpose of the SaveAsPDF.wcm macro, you probably will want to change that folder to your preference. Just [1] open the macro like any document to edit it and [2] follow the brief instructions in the User Modification Area to change the value of a single variable (vPDFLocation =) to your desired drive and path. Example settings: vPDFLocation = "D:\Temp\" ... or ... vPDFLocation = "C:\Users\{UserName}\OneDrive\Documents\" ... i.e., any valid drive and path (double quotes required in the code). When finished modifying the macro, be sure to click the Save & Compile button on the macro's toolbar (or just use File, Save on the main WordPerfect menu). Tips: ☼ Even if you have specified a preferred default folder for the PDF in the macro code, you can still change that location whenever the menu appears by using the first field. ☼ You can suppress (i.e., hide) the confirmation message that appears when you click OK on the menu by changing a single variable (vMsg =) in the User Modification Area. ☼ Advanced users: An alternative to the SaveAsPDF macro can be constructed following the instructions in the Corel Tutorials here and here, published several years ago The first link also shows how to create a custom PDF style in the Publish to PDF's Settings module that can be used in the macro when it generates the PDF document. (It does this via the macro command PDFStylesSetActive("<yourstylename>") just above the PDFDlg() command.)But note that such changes to the Publish to PDF's Settings -- even made manually be the user at any time -- are "sticky" between WordPerfect sessions. For more see the Caveats section below. • The PDF filename in the download version is the same name as the existing WPD's name, but you can change it in the menu's second field when you play the macro. The macro will automatically add a .pdf filename extension to the PDF name at run time. However, you can always change the PDF's filename from the macro's menu. Tip: If you often need to use several
specific folders to store your PDFs, you could make several copies of
this macro (named slightly differently and with different default
folders specified at the top of the macro code) and add them to your
menu,
main toolbar (or a custom toolbar) or even to a dedicated macro menu.
For more see here for links to these topics.
Caveats WordPerfect's
Publish to PDF feature displays a dialog ("Publish to PDF") with
several options on it. Further, there is a Settings button on the dialog, which brings up another dialog ("Publish to PDF Settings").
On that second dialog's General tab you can (e.g.) choose between Full Document, Current Page, a Selection of text, or a particular group of pages. Other tabs on that "Publish to PDF Settings" dialog have more options (most users typically accept the factory default settings). It is important to note that the choices you make on the main "Publish to PDF" and the "Publish to PDF Settings" dialogs in WordPerfect are "sticky" between WordPerfect sessions. Hence, the SaveAsPDF macro will use the program's last-saved settings for the Publish to PDF feature when it creates and saves the current document as a PDF file. (There's a small reminder to verify the Publish to PDF settings on the macro's pop up menu.) For most users this should not be an issue. But (e.g.) this sometimes becomes a problem if changes were made to the Publish to PDF dialog or its Settings. (Any changes can "stick" until they are changed again.) Here are some examples: Example1: If
you always want the PDF to immediately open in your PDF reader as soon
as it is created, the checkbox "Open PDF After Saving" at the bottom of
the Publish to PDF dialog should be enabled (ticked). If it not enabled
the PDF will be created ... but it won't be automatically opened.
Example2: If
you have chosen something other than Full Document with the Settings
button (e.g., Current Page) your new choice becomes the default for
future sessions, and can cause concern if you might be expecting the
standard default of Full Document. Just bring up the Publish to PDF
feature from the program's File menu and click the Settings button to
verify the current settings and options.
Example3: If you do NOT want the PDF to immediately open in your PDF reader as soon as it is created, simply un-tick (clear) the checkbox, "Open PDF After Saving" at the bottom of
the Publish to PDF dialog.
Just remember this is a sticky setting in recent WordPerfect versions, so if the option should be turned on my default, simply tick the box again. Alternatively ... Below in Footnote 1 you will find plain macro code you can use (in WordPerfect X7 or higher version) that can - 1) automatically publish the current document as a PDF quickly and directly, without displaying dialogs or messages (except as absolutely needed), by using some macro code and two existing PDF Styles; (2) not open the PDF after it is created from the current document; (3) over-write the same-named PDF if it exists at the target location, without displaying a confirmation message; and (4) restore your previously preferred ("default") PDF style in the Publish to PDF dialog. These advantages have a small downside: You must first manually create two PDF Styles in the Publish to PDF dialog, as explained in Footnote 1, which are then used by the macro. See more on this issue and other PDF tips here. |
|
Footnote 1 [...Continued from above...] Create a macro (described in Example3 above) NAME: Create custom PDFs.wcm (for WordPerfect X7 and higher) [Originally posted on WordPerfect Universe (Apr 26, 2024) here] PURPOSES, OPERATION AND REQUIREMENTS: (1) Publishes the current document as a PDF quickly and directly, without displaying dialogs or messages (except as absolutely needed), by using macro code and two PDF Styles. (2) This macro does not open the PDF after it is created from the current document. (3) If the same-named PDF exists at the target location it is overwritten without displaying a confirmation message. (4) As this macro finishes, your previously preferred ("default") PDF style is restored in the Publish to PDF dialog. Hence - (5) You must FIRST manually create two PDF styles in your Publish to PDF dialog's Settings module -- see the linked articles below for help. • The first style will be modified using this macro's step 4 to produce new settings described above (e.g., disable Open PDF After Saving), and the second style will be used in step 8 to restore your Publish to PDF to your currently preferred settings (e.g., enable Open PDF After Saving) after the PDF is generated. • Both style names should be stored in the two variables in step 1. • For help with creating/modifying PDF Styles see WordPerfect's Help (F1, search "PDF styles") and also the Corel tutorials at - https://www.wordperfect.com/en/pages/items/1500680.html [good intro to PDF Styles] https://www.wordperfect.com/en/pages/items/8900004.html [PDF styles via a macro] https://www.wordperfect.com/en/pages/items/8900005.html [usage: see step 4] = = = = = = = = = = To copy the code below into your WordPerfect program to create a working macro see here. The macro then can be assigned to a toolbar button, keyboard shortcut, or menu; see here. = = = = = = = = = = // MACRO begins here = = = = = // Step 1. OPTIONAL: Modify the Style names: // Stores the name of your EXISTING PDF Style (your "default," used at end of this // macro); AND the name of the NEW PDF Style to use to Publish to PDF (see // the PURPOSES documentation above). // [You can modify the names (in quotes) in either/both of the next two commands. // They will be used in several places in the macro code.] NewStyleName := "MyNewStyle" ExistingStyleName := "MyCustomStyle" // Step 2. Store the current (WordPerfect) document's path and name, but // with a .PDF extension. First, extract both the document's path, filename and // extension to use for the PDF file. IF(?Name="") // Test if the file has not been saved; if not, pop a message and quit Messagebox (;"Ooops!";"This document is not yet named, it must be saved first") Return ENDIF vFullName:=?Path+?Name // <- Or use specific target path; e.g. "D:\Temp\"+?Name // // Use the next (generic) code segment to separately store the file's // name and extension. vPos:=StrScan (vFullName; -1; EqualTo!; ".") // Get location of last period/full stop IF(vPos=0) // If there is no extension to the filename, store the current name... //vFName:=vFullName // (<- or do something else) Messagebox(;"Error - No filename extension";vFullName +NToC(0F90Ah)+ "... has no filename extension (e.g., .wpd). Rename the file.") Return ELSE // ... otherwise, "break apart" the file's name and extension ... vFName:=SubStr(vFullName;1;vPos-1) // vExt:=SubStr(vFullName;vPos+1;StrLen(vFullName)-vPos) // (not used here) ENDIF // (end generic segment) // Add a .pdf extension to the filename part, and store it in vPDFName // to name the PDF. vPDFName:=SubStr(vFName;1;vPos-1) + ".pdf" // Step 3. Activate the new PDF Style. PDFStylesSetActive(NewStyleName) // Step 4. Modify setting(s) for the new PDF Style here. // In these examples (taken from a Corel tutorial) only the LAST one is active // (it turns OFF the "Open PDF After Saving" option). The others could be used // as desired. See the WordPerfect macro commands for several other // PDFStyles... commands and their (parameters). // // **EACH of the next 4 command should be on ONE line (no hard returns): // PDFStylesSetSettingValue(NewStyleName; Setting:PDFVersion!; SettingValue:PDFVersion12!) // PDFStylesSetSettingValue (NewStyleName; Setting:OptimizeForWeb!; SettingValue:False!) // PDFStylesSetSettingValue (NewStyleName; Setting:GenerateLogFile!; SettingValue:False!) PDFStylesSetSettingValue (NewStyleName; Setting:OpenPDFAfterSaving!; SettingValue:False!) // Step 5. Save the change(s) made to the new style. PDFStylesSave(NewStyleName) // Step 6. Publish (i.e., save) the current document to PDF without being prompted, // i.e., if it already exists, simply overwrite it. PdfDlg (vPDFName; Options: ReplaceAlways!) Wait(1) // (wait 0.1 second) // Step 7. Restore (reset) the settings(s) used above in the new PDF Style, then // re-save it. // **EACH of the next 2 command should be on ONE line (no hard returns): PDFStylesSetSettingValue (NewStyleName; Setting:OpenPDFAfterSaving!; SettingValue:True!) PDFStylesSave(NewStyleName) // Save the change made to the style // Step 8. OPTIONAL (but probably desirable for most users): // Reactivate your preferred default PDF Style with a preferred setting; then re-save it. PDFStylesSetActive(ExistingStyleName) // The next command seems to be required since the "Open PDF After Saving" // option is not located inside the Settings dialog. // **EACH of the next 2 command should be on ONE line (no hard returns): PDFStylesSetSettingValue (ExistingStyleName; Setting:OpenPDFAfterSaving!; SettingValue:True!) PDFStylesSave(ExistingStyleName) Wait(1) // (wait 0.1 second) // Step 9. Exit from the macro. Return // MACRO ends here = = = = = |