Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 3
Microsoft® Office Publisher 2003
Summary: Use the Microsoft Office Publisher 2003 object model to automate, customize, and extend prepress operations. This article, the last in the series, covers creating composite CMYK PostScript, PDF (Portable Document Format) files programmatically, and performing page imposition. Some limitations of the Publisher 2003 object model are also discussed. This is part three of a three part series. (22 printed pages)
This is the third of three articles meant to supplement the Publisher 2003 Prepress Reference Guide, and discuss how to use the Microsoft® Office Publisher 2003 object model to accomplish prepress tasks. This article covers generating composite CMYK, PostScript, and Portable Document Format (PDF) files from Publisher publications, and discusses issues to consider when automating imposition using the Publisher object model.
For more information about these tasks (including how to accomplish them using the Publisher user interface) see the Publisher 2003 Prepress Reference, available for download from Publisher Prepress on Office Online.
You might want to generate composite CMYK PostScript from Publisher files if you are planning to use CMYK output as a step to:
- Creating PDF files
- Going direct to plate
- Making color proofs
For more information about how Publisher creates spot colors in composite CMYK Postscript files, and how Publisher handles spot colors in EPS graphics, see Chapter 11: Composite Workflow of the Publisher 2003 Prepress Reference.
Settings to Print Composite CMYK PostScript
Before you print composite CMYK, make sure to do the following:
- Set up the publication to use an appropriate printer driver and to print to the appropriate size paper. If you want to print bleeds or crop marks, the paper size must be larger than the page size. For more information about programmatically controlling page setup, see the second article in this series, Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 2.
- Define any spot-color inks for the publication. If you don't define the spot-color inks, you will only get process-color inks (ie, cyan, magenta, yellow, and black). For more information on programmatically defining spot color inks and the Publisher color models, see the first article in this series Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 1.
The composite workflow follows these general steps:
- Specify the print output to be composite CMYK.
To do this, you should specify the PrintMode property of the AdvancedPrintOptions object as pbPrintModeCompositeCMYK.
Note To use composite CMYK as the default print mode for future Publisher instances, rather than composite RGB, you can set the PrintCMYKByDefault property of the AdvancedPrintOptions object to True. Just be aware that setting this property does not apply to the current application of Publisher, or any open instances.
- Leave the resolution set to its default setting, so that the publication prints with the resolution set at the RIP.
To do this, set the Resolution property of the AdvancedPrintOptions object to "(default)", or the appropriate string value for your printer driver.
- Specify whether you want printer's marks, bleeds, or other output options selected.
This entails setting any of the following properties of the AdvancedPrintOptions object to True to select the print option you want:
- Print out the publication as a PostScript file.
To do this, use the Document.PrintOut method. For the PrintToFile parameter, specify a string that represents the name you want to give the PostScript file. This string must end in the PostScript file extension of .ps. You can also use the optional From and To parameters to specify a page range to print.
Note You cannot save a publication as a PostScript file, as you can by using the Publisher user interface. The PostScript format is not a valid value for the pbFileFormat parameter of the SaveAs method.
The following procedure prepares a publication and then prints the first three pages as a composite CMYK PostScript file. The sample assumes that you defined any desired spot color inks.
Sub PrintPubAsCompositeCMYK(pubDocument, strPrinterName) With pubDocument 'Set active printer to a PS printer 'that supports PS Level 2 or higher .ActivePrinter = strPrinterName 'Set desired printers marks to print With .AdvancedPrintOptions 'Set print mode to separations .PrintMode = pbPrintModeSeparations 'Set printers marks .Resolution = "(default)" .AllowBleeds = True .PrintBleedMarks = True .PrintCropMarks = True .PrintColorBars = True .PrintDensityBars = False .PrintJobInformation = False .PrintRegistrationMarks = False .HorizontalFlip = True .NegativeImage = True .VerticalFlip = True 'Set print mode to composite CMYK .PrintMode = pbPrintModeCompositeCMYK End With 'Call function that determines if page size 'exceeds selected paper size If PageFitsPaper(ActiveDocument) = False Then MsgBox Prompt:="This publication is too large " & _ "for the paper size specified. " & vbLf & _ "Increase the paper size and " & _ "print the publication again.", _ Title:="Increase Paper Size" 'exit Else .PrintOut From:=1, To:=3, PrintToFile:=.FullName & "_CompCMYK.ps" End If End With End Sub
Note that this code sets the print mode to separations before it specifies any printer's marks, and then sets the print mode to composite CMYK. The code does this because the PrintColorBars, PrintDensityBars, and PrintRegistrationMarks properties are only accessible when the PrintMode property is set to separations. However, these options are available in the Publisher user interface for the composite CYMK and composite grayscale print modes. Therefore, the procedure changes the print mode to separations, sets the desired printer's marks to print, and then sets the print mode to the actual desired value, composite CMYK.
The sample calls a helper function, PageFitsPaper, that determines if the page size (including any selected printer's marks) fits on the paper size specified. For an example of the code such a helper function would contain, see Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 2.
Settings to Generate a PDF File from Composite CMYK PostScript
Publisher 2003 does not have a feature for saving a publication directly as a PDF file, either programmatically or by using the user interface. Instead, you must print a composite PostScript file and then use a third-party application to distill the PostScript file into a PDF file.
For most PDF distilling applications, when you install the application you get components: a printer driver that you can choose directly from within your Microsoft Windows® application, and a standalone application that can convert a PostScript file to a PDF file. Implementing either method programmatically has its advantages and disadvantages:
Method 1: Print directly to a PDF printer driver
The main advantage to this method is that it's more efficient; you print directly to the PDF distiller, rather than creating a PostScript file as an intermediate step.
The disadvantages to this method include the fact that it requires manual input. You must manually provide a file name and location for the PDF file to create. In addition, if you set up the PDF distiller with the wrong settings, you have to print the file again with the correct settings. Also, if the PDF distiller encounters a problem, you do not see an error message; the distiller process fails silently.
Important Publisher 2003 cannot print directly to Acrobat Distiller versions 5 and 6, although it works with earlier versions. If you are using Acrobat 5 or 6, use the second method described below.
Method 2: Print a PostScript file, which the PDF application can then distill
The advantages to this method include the fact that if the distilling application fails, you get an error message that may help resolve the problem. This is usually a PostScript error message. In addition, if you set up the distilling application incorrectly, you are not forced to recreate the PostScript file. Just correct the distiller setting and distill the PostScript file again. In addition, this method requires no manual input. As long as you place the finished PostScript file in a folder that the distilling application is monitoring, the distilling application detects and automatically distills the PostScript file.
The main disadvantage is that it's not as efficient a process, in that you create a PostScript file as an intermediate step.
Important For more information about configuring Adobe Acrobat Distiller to work with Publisher, as well as known issues concerning PostScript and PDF files generated from Publisher publications, see Chapter 11: Composite Workflow of the Publisher 2003 Prepress Reference.
Whichever method you select, the general workflow is similar to generating composite CMYK output, with the following differences:
- Specify the print output.
To do this, set the PrintMode property of the AdvancedPrintOptions object for the desired print output (such as composite RGB, composite grayscale, composite CMYK, or separations).
- If printing separations, set the screen frequency and angles for separations, if you are not setting these at your RIP.
To do this, set the UseCustomHalftones property of the AdvancedPrintOptions to True, and then specify the Frequency and Angle properties of each PrintablePlate object you select to print. For more information, see Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 2.
- Print the publication, either directly to the device, or as a PostScript file.
To do this, use the Document.PrintOut method. You can use the optional From and To parameters to specify a page range to print, the Copies parameter to specify the number of copies, and the Collate property to set whether the copies are collated. To generate a PostScript file, for the PrintToFile parameter, specify a string that represents the name you want to give the PostScript file. This string must end in the PostScript file extension of .ps.
Note You cannot save a publication as a PostScript file, as you can through the Publisher user interface. The PostScript format is not a valid value for the pbFileFormat parameter of the SaveAs method.
Imposition refers to the positioning of pages on a signature such that, once the signature is printed, folded, and cut, the pages appear in the proper sequence. You can impose a Publisher publication in three ways:
- Print single pages from Publisher and manually strip the film together
- Impose the job within Publisher, if it is simple enough
- Print the publication as composite CMYK or PDF and use a third-party imposition application
Note Do not impose pages from Publisher publications by printing them as single-page composite CMYK PostScript or PDF files and placing them in another desktop publishing application, such as Quark XPress or FreeHand. This method does not yield satisfactory results.
Publisher offers basic page-imposition options. You can use the Publisher object model to create routines that automate manual imposition in Publisher. However, as you write your code, there are several aspects of how Publisher structures publications that you should consider.
Creating Custom Printer Marks
Printer's marks, such as crop marks or density bars, only appear when the publication is printed or previewed. They are not publication shapes that you can copy and paste into the new publication. Printer marks only appear on the edges of each publication page. So, for example, if you create a publication where each publication page is actually a 4-up imposition of four smaller pages, then printer's marks only appear along the edges of the larger page itself.
Also, crop marks do not appear in x-up imposition layouts if the distance between the publication pages is less then 0.125 inch.
Publisher does not have a built-in registration color, although there are several ways to simulate one, depending on your needs and the print output you want from the publication.
If you need to add custom registration marks to an imposition layout page, you can do so programmatically, as described below.
Note that, in order for a shape to be printed with a publication page, it must touch the page. Publisher considers any shape that does not touch the page to be in the scratch area, and does not print it. A good practice is to group the custom printers mark with an "invisible" shape (that is, a shape with no line, text, or fill), and have the invisible shape touching the page.
Method 1: Create an object with registration color for process color printing
The first approach involves creating a registration color whose C, M, Y, and K values are each 100%. To do this, we use the SetCMYK method of the ColorCMYK object to specify CMYK values. The ColorFormat object represents a color in the publication, based on a spot color ink, RGB value, or CMYK value. If the color is a CMYK value, the ColorCMYK object represents that value. The SetCMYK method takes four parameters, one for each process color value. Note that valid values are from 0 to 255, rather than from 1 to 100 as one might expect.
- Use this approach if you plan to print the publication as process-color separations, or as composite CMYK.
- Do not use this approach if you plan on printing the publication with any spot colors that need to print on a spot-color plate.
Once you define the registration color, you can apply it to a shape (or grouped shape, as in the case of the example), setting the line color of the shape to a color with C, M, Y, and K values of 100, and then pasting and positioning the shape on each page of the publication.
The following code creates a grouped shape, sets each shape in the group to the specified registration color, and then pastes and positions the grouped shape on each page of the selected publication. Note that the C, M, Y, and K values of the registration color are set to 255 (100%). The sample assumes the publication's color mode is either process color or spot color and process.
Sub AddRegShape() Dim shpRange As ShapeRange Dim shpLoop As Shape Dim pgLoop As Page 'Create registration shape With ActiveDocument With Pages(1).Shapes .AddShape Type:=msoShapeOval, Left:=25, Top:=25, _ Width:=30, Height:=30 .AddShape Type:=msoShapeOval, Left:=32, Top:=32, _ Width:=16, Height:=16 .AddLine BeginX:=15, BeginY:=40, EndX:=65, EndY:=40 .AddLine BeginX:=40, BeginY:=15, EndX:=40, EndY:=65 'Select a shape range Set shpRange = .Range(Array(.Count, .Count - 1, _ .Count - 2, .Count - 3)) 'Set line color of each shape in the range 'to the CMYK registration color For Each shpLoop In shpRange shpLoop.Line.ForeColor.CMYK.SetCMYK _ Cyan:=255, Magenta:=255, Yellow:=255, Black:=255 Next 'Group the shapes shpRange.Group shpRange.Cut End With 'Add grouped registration shape to each page 'and position it For Each pgLoop In .Pages With pgLoop.Shapes .Paste .Item(.Count).Left = 15 .Item(.Count).Top = 15 End With Next End With End Sub
Method 2: Create a Group of Registration Objects for Spot Color Printing
The next approach involves creating the same shape for each spot ink, setting the object to Overprint, and then positioning each shape in the same spot on each page of the publication. When you print the publication as separations, one copy of each object appears on each spot ink plate.
- Use this approach if the publication uses spot colors and you plan to print it as separations.
- Do not use this technique if you plan to print the publication as a composite.
Additionally, you cannot completely automate this approach. Because the Publisher object model does not expose registration settings, you cannot set the shapes to overprint programmatically. Unless you set each shape to overprint, only the shape on top prints on the plate for its spot color, rather than each shape printing on the plate for its spot color.
However, you can still automate much of the task, with minimal user input required. In the following example, the first procedure creates the shapes, sets one shape to each spot ink, and prompts the user to set the Overprint setting on each object manually. The second procedure then copies the shapes and positions them on each publication page.
Note that this sample assumes the publication's color mode is spot and process color. Because of this, Publisher creates one object for each Plate object after the first four. The first four Plate objects are always the C, M, Y, and K plates in this color mode. Also notice that the ColorFormat.Ink property refers only to spot inks; therefore, in spot and process color publications, there are always four fewer inks than plates. In a publication whose color mode is spot color, the number of Plate objects and inks is equal, and so this code does not produce the desired results.
Also, in this sample we set the name of each grouped shape to be the same as the name of the Plate object for which it was created. This allows us to identify the shapes in the second procedure, so we can copy and position them.
Sub CreateSpotRegShapesForSpotAndProcess() Dim shpRange As ShapeRange Dim shpRangeInk As ShapeRange Dim shpLoop As Shape Dim shpGroup As Shape Dim pgLoop As Page Dim intCount As Integer Dim intCountShapes As Integer Dim intShapePosition As Integer 'creates spot color registration shapes 'for process plus spot color publications intShapePosition = 10 'Create registration shape With ActiveDocument With Pages(1).Shapes .AddShape Type:=msoShapeOval, Left:=25, Top:=25, _ Width:=30, Height:=30 .AddShape Type:=msoShapeOval, Left:=32, Top:=32, _ Width:=16, Height:=16 .AddLine BeginX:=15, BeginY:=40, EndX:=65, EndY:=40 .AddLine BeginX:=40, BeginY:=15, EndX:=40, EndY:=65 'Select a shape range Set shpRange = .Range(Array(.Count, .Count - 1, _ .Count - 2, .Count - 3)) shpRange.Cut 'Set each shape in the range to spot color ink For intCount = 5 To _ ActiveDocument.Plates.Count Set shpRangeInk = .Paste For Each shpLoop In shpRangeInk shpLoop.Line.ForeColor.Ink = (intCount - 4) Next 'Group the shape range shapes Set shpGroup = shpRangeInk.Group 'Position grouped shape on page one With shpGroup .Left = intShapePosition .Top = 15 .Name = ActiveDocument.Plates.Item(intCount).Name End With intShapePosition = intShapePosition + 55 Next End With MsgBox Prompt:="Please set each spot color registration shape " & _ "to Overprint, " & vbLf & "and then run the macro " & _ "that copies the shapes to every page.", _ Title:="Spot Color Registration Shapes Created" End With End Sub
This second procedure copies each shape and pastes it onto every page in the publication. For each spot color Plate object, the code identifies the shape on page one with the same name, and then cuts, copies, and positions that shape on each page of the publication.
Sub DuplicateAndPositionSpotRegShape() Dim intCount As Integer Dim shpLoop As Shape Dim pgLoop As Page With ActiveDocument For intCount = 5 To .Plates.Count Set shpLoop = .Pages.Item(1).Shapes.Item _ (.Plates.Item(intCount).Name) shpLoop.Cut For Each pgLoop In .Pages With pgLoop.Shapes .Paste .Item(.Count).Left = 15 .Item(.Count).Top = 15 End With Next Next End With End Sub
Method 3: Create a registration object as an EPS file
This final approach involves creating an Encapsulated PostScript (EPS) file in another application, and then inserting the file onto every page in the publication.
- You can use this technique if the publication's color mode is process colors, spot colors, or process and spot colors, and you plan to print it as separations or composite CMYK.
Note This approach was tested informally with Adobe Illustrator 10 and Macromedia FreeHand MX (11). It may or may not work with other versions or applications.
For example, the following procedure inserts the specified file as a picture on every page in the publication.
Sub InsertEPSRegShape(strFilePath As String) Dim pgLoop As Page For Each pgLoop In ActiveDocument.Pages pgLoop.Shapes.AddPicture _ Filename:=strFilePath, LinkToFile:=True, _ SaveWithDocument:=False, Left:=15, Top:=15 Next End Sub
Page Imposition Options Available in Publisher 2003
Publisher offers only limited page-imposition options, which include reader's spreads, step and repeat layouts for business cards, and labels. You specify them by setting the PublicationLayout property of the PageSetup object. For more information, see Automating Commercial Printing Prepress Tasks in Publisher 2003, Part 2.
Finding All the Visible Shapes on a Page
Not all the shapes that appear on a given publication page reside in that page's Shape collection. To ensure you move all the shapes that are visible on the page, your code needs to consider that shapes may also reside in the master page assigned to the selected page, or may extend onto the selected page from other publication pages.
Working with Shapes on Master Pages
Master pages contain the design and layout elements that the user wants to repeat on multiple pages in a publication. Users put these common elements on master pages to give their publication a more consistent appearance. A master page can contain anything that you can put on a publication page, as well as some elements (such as headers, footers, and layout guides) that you can only set up on a master page. A publication may have one or more master pages; however, you can assign each page only one master page.
Figure 1 shows how a typical page appears in a publication. You actually place elements that appear on more than one page, such as the header, footer, and water mark, on the master page. You place content that appears only on that specific page, such as text or pictures, on the publication page.
Figure 1. The page (top) is actually comprised of objects on the publication page (bottom left) and master page (bottom right)
If you plan to use Publisher to perform manual imposition, you must copy objects on master pages from master pages and paste them onto the publication pages. If you impose multiple publication pages onto a single, larger publication page in another file, simply applying a master page to the larger page does not yield satisfactory results.
Publisher represents master pages using Page objects in the Document.MasterPages collection. Use the Master property of a publication page to return or set the master page to apply to that publication page. However, if the Page.IgnoreMaster property is set as True for a publication page, then none of the elements on the master page display on the publication page. Also, if the user configures the publication as two-page spreads, the master page to apply may actually contain shapes for both left and right pages. Use the Document.ViewTwoPageSpread to determine if the user configured the publication as a two-page spread, and the Page.IsTwoPageMaster property to determine if a master page is for two pages.
Working with Shapes that Extend Across Multiple Pages
Shapes that you insert on one page, and belong to that page's Shapes collection, may extend beyond the borders of that page. Because of this, if you write code that pastes pages into different configurations relative to each other, you must consider shapes that extend beyond the page on which they were inserted. There are two scenarios where this may cause issues during automated imposition:
- If the user configured the publication as a two-page spread, and wants elements that they inserted on one page to extend onto the other page.
- Users inserted shapes that extend beyond the borders of a page, and does not want these shapes to extend onto other pages.
These two scenarios are illustrated below. Figure 2 depicts publication pages as the user submitted them to the printer. The user wants the star to appear on pages two and three; however, they do not want the blue lines that extend from pages one to appear on any other page. Figure 3 depicts what happens if the code simply copies and pastes each page's Shapes collection onto the imposition publication. The star shape belonged to page two's Shapes collection; it now appears on page seven as well, and not on page three at all. The blue line that extends beyond page one in the original layout now extends into page eight. In addition, if any of the pages contain text boxes, these shapes extending into pages may well cause the text in those text boxes to reflow.
Figure 2. Publication pages as two-page reader spread (before automated imposition)
Figure 3. Publication pages as eight page imposition (after automated imposition)
The following example determines if any of a shape's sides extend beyond the edges of the page on which it appears. The example assumes that you declare the variable shpLoop and you set it equal to a Shape object in the active publication.
With shpLoop If (.Left + .Width) > ActiveDocument.PageSetup.PageWidth Then Debug.Print .Name & " on page " & pgLoop.PageNumber & _ " extends beyond the right page border." End If If .Left < 0 Then Debug.Print .Name & " on page " & pgLoop.PageNumber & _ " extends beyond the left page border." End If If (.Top + .Height) > ActiveDocument.PageSetup.PageHeight Then Debug.Print .Name & " on page " & pgLoop.PageNumber & _ " extends below the bottom page border." End If If .Top < 0 Then Debug.Print .Name & " on page " & pgLoop.PageNumber & _ " extends above the upper page border." End If End With
Identifying Shapes with Variable Content
Some shapes contain dynamic content or formatting that updates based on the shape's context. Content or appearance of these types of shape may change if you copy or move the shape to a different page or publication.
Identifying Shapes That Contain Dynamic Text
Publisher enables users to insert placeholders for dynamic text, called fields, into text boxes in the publication. Each field represents a piece of information that may change based on conditions in the publication. Publisher dynamically updates the actual text that the field displays as necessary. For example, suppose you insert a field representing the current page number into a text box on page 2. If you move that page so that it is the fourth page in the publication, the field automatically updates to display page 4.
Fields that update the text they display based on the publication page they appear on are a concern when automating manual imposition in Publisher. For example, if you take the first four pages from one publication and impose them a as 4-up spread (that is, on a single, larger publication page) in another publication, any fields representing page numbers on those page displays the same page number. Fields such as page numbers are especially common in the HeaderFooter objects of MasterPage objects.
To identify fields in a publication, use the Fields collection of the TextRange object. Each TextRange object represents the actual text in a TextFrame object. Each TextRange object contains a Fields collection, whether or not the text it represents contains fields; for text that does not contain any fields, the Count property of the Fields collection is 0. Each Field object has a Type property, which you can use to identify just the types of fields you want. The Code property returns the code of a field, while the Result property returns the text Publisher is currently displaying for that field. Use the Unlink method to convert the field to text displaying its most recent result, and stop the field from updating further.
The following example identifies any fields present on the pages of the specified publication, and writes information about each field it finds to the specified text file. Each shape in the Shapes collection contains a TextRange object; this example uses the HasText property of that object to determine if the shape actually contains text. If so, that text is represented by a TextRange object, which in turn contains any fields inserted into the text in its Fields collection.
Note that the sample does not check for fields in the grouped shapes, or HeaderFooter objects on any master pages.
Sub FindFields(pubDocument As Document, strFilePath As String) Dim objFileSystem As FileSystemObject Dim objTextStream As TextStream Dim pgLoop As Page Dim shpLoop As Shape Dim fldLoop As Field Dim intCount As Integer Set objFileSystem = New Scripting.FileSystemObject Set objTextStream = objFileSystem.OpenTextFile _ (Filename:=strFilePath, IOMode:=ForAppending) For Each pgLoop In pubDocument.Pages For Each shpLoop In pgLoop.Shapes If shpLoop.HasTextFrame = msoTrue Then With shpLoop.TextFrame If .HasText = msoTrue Then If .TextRange.Fields.Count > 0 Then For intCount = 1 To .TextRange.Fields.Count With .TextRange.Fields(intCount) objTextStream.WriteLine _ "Shape: " & shpLoop.Name & _ " Page: " & pgLoop.PageNumber objTextStream.WriteLine "Code: " & _ .Code objTextStream.WriteLine "Result: " & _ .Result objTextStream.WriteLine "Type: " & _ .Type End With Next End If End If End With End If Next Next End Sub
Identifying Shapes with Color Scheme Formatting Applied
Sometimes, objects change color if you paste them into another publication. This happens because the two publications have different color schemes. Color schemes are collections of pre-defined colors. They enable the user to quickly change the look of a publication. They are quite popular and useful during the designing of a publication, but can cause unexpected results during the printing of a publication. For example, suppose you assign a publication the "Fjord" color scheme, and you assign an object in that publication the Accent 3 scheme color, which in this case is a dark blue. If you copy and paste the object into a publication with the "Bluebird" color scheme, the object turns a shade of red, because that is the Accent 3 scheme color for that color scheme.
To resolve this issue, make a copy of the original publication, remove the color scheme from the copy, and then copy the objects into the target publication.
This is a simple procedure if the publication's color mode is RGB (desktop). Each ColorFormat object in the publication's Document.ColorsInUse collection represents a color present in the publication. Each scheme color is represented in that collection by a ColorFormat object whose Type property is pbColorTypeScheme. Directly setting the RGB value of a ColorFormat object changes it from a scheme color to a custom color; that is, changes its Type property from pbColorTypeScheme to pbColorTypeRGB. So, by setting the RGB value of a scheme color to equal its current RGB, we retain the actual RGB color value, while ensuring that any objects using that color are no longer affected by changes in the color scheme of the publication. This is illustrated in the sample function below:
Function RemoveColorSchemesFromPub(ByRef docPublication As Document) Dim cfLoop As ColorFormat 'Determine that publication color mode is RGB If docPublication.ColorMode = pbColorModeDesktop Then For Each cfLoop In docPublication.ColorsInUse 'Identify which colors are scheme colors If cfLoop.Type = pbColorTypeScheme Then 'Set each RGB value equal to itself 'this changes the color type from scheme to RGB 'while preserving the actual color value cfLoop.BaseRGB = cfLoop.BaseRGB cfLoop.RGB = cfLoop.RGB End If Next End If End Function
This approach only yields predictable results if the publication color mode is RGB, not CMYK. We recommend that you do not set the RGB values of CMYK colors; while this changes the colors from scheme colors to custom colors, the conversion from CMYK to RGB may lead to colors shifting slightly. Unfortunately, a limitation in the Publisher object model prevents you from accessing the CMYK values of a scheme color, so you cannot use the SetCMYK method to set the ColorFormat object's CMYK values equal to themselves. To change scheme colors to custom colors in a CMYK publication, use the Publisher user interface.
To change scheme colors to custom colors in a CMYK publication
- On the Tools menu, point to Commercial Printing Tools, and then click Color Printing.
- On the Colors tab, click the arrow next to the scheme color, and select Change.
- Click the Custom tab, and then click OK.
For RGB publication that you plan to convert and print as CMYK publication, we recommend you convert the scheme colors to custom colors while the publication color mode is still RGB.
Figure 4 illustrates the structure of the ColorFormat object and the members it contains. Any time you use a color in a publication, whether it be for text, or a shape's line or fill color, etc., it is represented by a ColorFormat object.
Figure 4. The ColorFormat Object and Members
Identifying Shapes with Font Scheme Formatting Applied
When you copy a text box from one publication to another publication, the font size or font face of the text may change in the new publication. This happens if you create the second publication based on a wizard; Publisher applies the current font scheme to the pasted text, rather than retain the original formatting. When Publisher creates a publication based on a wizard, it applies a default font scheme. Font schemes apply to all text in a publication, whether you type or paste it from another source.
To prevent this from happening, when you create the new publication, specify that it not be based on a wizard. Programmatically, when you call the Application.NewDocument method, specify the Wizard parameter as pbWizardNone. This is the default value of the Wizard parameter, but it is still a good practice to set it specifically, as in the example below.
Dim pubNewDoc As Document Set pubNewDoc = NewDocument(Wizard:=pbWizardNone)
Note that unlike color schemes, The Publisher object model does not expose font schemes, and as such you cannot set or change them programmatically.
While the great majority of Publisher functionality available through the user interface has an object model counterpart, there are a few areas of interest to commercial printers where the object model does not currently expose functionality.
The Publisher object model does not expose functionality for managing fonts. Each TextRange object that represents text contains a Font object, whose members you can use to get and set the font's various characteristics. However, publications do not contain a collection of the fonts used in that publication. To determine programmatically which fonts are in use in a specified publication, you must iterate through each TextRange object in the publication.
In addition, the Publisher object model does not provide functionality for performing font management tasks, such as:
- Embedding a font, or determining is a font is embedded in a publication
- Determining the license restrictions for a font in the publication
- Determining if there are missing fonts for a publication, or specifying substitution fonts for any missing fonts
- Determining whether a font is synthesized (which causes it to bitmap)
- Determining the type of a font; for example, TrueType, Postscript, or other
Registration (Trapping and Overprinting)
Trapping is not currently supported in the Publisher object model. You cannot specify default trapping settings at the publication or spot color level, or custom trap setting at the object level. You cannot query the publication for trap placement or explanation information. Also, you cannot set a shape to Overprint.
Pack and Go
There is no Pack and Go functionality exposed in the Publisher object model. You cannot programmatically call the Pack and Go Wizard to consolidate a publication and its linked files into a single file for easy transportation. However, commercial printers are likely more concerned with unpacking packed files they receive from customers. You can partially automate unpacking a packed file into its constituent files using Visual Basic.
When Publisher saves a packed publication, it always saves a copy of Unpack.exe along with it. Unpack.exe is the utility that unpacks the file into its constituent parts. Unpack.exe can only unpack a publication located in the same folder.
Important Because it is an executable file, Unpack.exe could be used maliciously to introduce a virus. For security reasons, you should always use the Unpack.exe which installed with Publisher on your computer. Just remember, it must be copied into the same folder as the packed publication to function properly.
The following example ensures that the version of Unpack.exe installed on your computer with Publisher is used to unpack customer files. The code determines if Unpack.exe is present in a specified folder; if it is, the code copies the Unpack.exe from a trusted location on your computer and pastes it over the executable in the specified folder. It then launches the Unpack.exe using the Visual Basic Shell function. Once the application launches, the user must manually supply a folder location and click OK, as the application does not accept command line arguments.
Note that to navigate folders and manipulate files outside the Publisher object model, you must employ the Microsoft Scripting Runtime object library. To use this library, add a reference to the library into the Visual Basic for Application project:
- In the Visual Basic Editor, select the project in the Project Explorer window.
- On the Tools menu, click References.
- Under Available References, select the Microsoft Scripting Runtime box, and then click OK.
Sub Unpack(FolderLocation As String, TrustedAppLocation As String) Dim objFileSystem As FileSystemObject Dim objFolder As Folder Dim objFile As File Set objFileSystem = New Scripting.FileSystemObject Set objFolder = objFileSystem.GetFolder(FolderLocation) For Each objFile In objFolder.Files If objFile.ShortName = "unpack.exe" Then 'Permission denied on next line objFileSystem.CopyFile _ Source:=TrustedAppLocation, _ Destination:=objFolder.Path & "\unpack.exe", _ OverWriteFiles:=True Shell PathName:=objFile.Path, WindowStyle:=vbNormalFocus End If Next End Sub
The Publisher 2003 object model features greatly expanded support for automating, customizing, and extending commercial prepress operations. Over the course of the last three articles, we examined how to use this new functionality to streamline and standardized the way a printer works with Publisher files, from file unpacking through print output.
For more in this series, see the following articles: