What is Fit Page to Content?
Fit Page to Content is a macro that changes the size of the current page to fit specified content, and moves all content horizontally and/or vertically to put the specified content at the correct position relative to the page. Options are available to specify the content to be used when doing this, margins to use when doing this, and other details associated with how this is carried out.
See Fit Page to Content in use:
Screenshot:
Using the macro with the Userform.
Clicking on the Fit Page to Content button carries out the Fit Page to Content operation.
Option buttons in the Target for Fit section determine the content that is to be used when carrying out the FPTC operation.
The size of the margin between the specified content and the page edges is set by option buttons and comboboxes in the Target to Fit section. The margin can be an absolute distance, or can be calculated as a percentage relative to the longer dimension.
The Other Options section includes a drop-down list to specify the number of decimal places to be used when rounding the page dimensions.
When Use True Size of Objects is checked, the macro uses the "true size" of objects (including outline width, corner styles, line caps, etc.) rather than "wireframe" size when determining the size and location of the content.
When Ignore Master Layers is checked, the macro does not consider master layer content when calculating the new page size, and leaves content on master layers unchanged.
If Close Form on FPTC is checked, then the form is closed automatically after the Fit Page to Content operation is performed.
If Set values for "No Form" sub is checked, then the settings in the userform are stored in the Registry for use by the Fit_Page_to_Content_No_Form sub (more on this later).
Using the Comboboxes.
The boxes for numeric entry are comboboxes. The drop-down list for a combobox can contain values stored for convenient access. If a combobox is not locked, then when a value in thatcombobox is used by the macro, that value is added to the top of the list. If an existing value is used from the list, then that value is moved to the top of the list. Values can also be manually added to the list.
Ctrl+clicking on a combobox sets that combobox to its default value.
Right-clicking on a combobox brings up a menu of options for managing it.
These options may include:
Units of Distance.
For a combobox that represent a distance, values are applied by the macro in whatever units (inches, millimeters, etc.) are shown beside the combobox. Those units can be specified by the user through the right-click context menu.
If “Follow Horizontal Ruler Units” is chosen, then the units for the combobox are the same units that are in use in the document for the horizontal ruler. If those units are changed in the document, then the macro automatically changes the units in the combobox to match.
Although this documentation makes references to “the list” for the combobox, there is not necessarily only one list. The combobox maintains a separate list for any unit that is used in it. When units for the combobox are changed, then the list associated with those units is loaded. The number of decimal places, and also whether a list is locked or not, are things that are handled independently for each list.
A Video Describing and Demonstrating the Special Features of My ComboBoxes:
Using the macro without the Userform.
The Fit_Page_to_Content_No_Form sub can be used to fit page to content without opening the userform. This sub can be used as a Command in regular CorelDRAW workspace customization, so it can be used on toolbars or menus, and can have a keyboard shortcut assigned to it. When performing the FPTC, this sub uses settings stored in the Registry. Those settings can be established by using the userform with the Set values for "No Form" sub box checked.
Subs in the Macro Manager.
How does this thing work?
The page in CorelDRAW is always centered in CorelDRAW's 1800 x 1800 inch "world", so the macro not only sets a new page size, but also moves all content horizontally and/or vertically as necessary to put the specified content at the correct position relative to the page. Changing the page size is simple. The "move everything" part of the job can range from very simple to rather involved, depending on the details of how the document is structured.
"Everything" needs to include objects on locked layers, objects on hidden layers, objects that have been individually locked, objects that have been individually hidden, and objects that have combinations of those characteristics. In order to move everything, the macro may need to temporarily change some of these characteristics, and then restore those characteristics after the objects have been moved. If "true size" of objects is being used when determining the page size, then the macro needs to temporarily make non-printable layers printable.
Disclaimer.
As described in the preceding section, there can be a lot going on here! From my experience, I am not aware of situations where this macro fails to correctly "move everything", or fails to properly restore locked/hidden/printable status for layers and/or individual objects - but no guarantee is offered here. If you find cases in which this macro does not seem to handle something as it should, then please let me know so that I have the opportunity to investigate.
Compatibility.
Fit Page to Content was put together in a CorelDRAW X7 environment, and should work in versions X7-2020.
OK, where's the macro?
JQ_Fit_Page_To_Content_Current.zip (most recently updated 2021-07-17).
That includes the .GMS file and a simple icon that can be used on a CorelDRAW Toolbar.
Please note that, starting with the version released on 2020-04-19, this macro uses a different scheme for storing combobox value lists and some preferences in the Registry. If you have been using an older version of this macro, those "old" value lists and preferences will not be there when you use the newer version. If you want to "clean out" those old entries that are not used by the newer version of the macro, the best way to do so is to run the Remove_FPTC_Registry_Entries sub, which will set the macro back to its default values.
How cool, this is great, I will be happy to advertise on our networks!
Hello Léo,
Thank you for your kind words!
I have a newer version of this macro - with one additional option - that I will upload within one or two days.
Fantastic, soon I will present to our audience, as it is of great help! Thank you my friend and congratulations for the work!
Sub SetPageSameAsSelection()
Dim sr As ShapeRange, s As ShapeDim x#, y#, w#, h#
ActivePage.Shapes.All.CreateSelection 'Selects all Shapes on the document' Set s = ActiveSelection.Group 'Groups all Shapes together' s.AlignAndDistribute 3, 3, 2, 0, False, 2 'Aligns all groups to centre of document / page' Set s = ActiveSelection.GroupSet sr = ActiveSelectionRangeIf sr.Count = 0 Then Exit Sub 'If there is nothing to select the macro will stop'
sr.GetBoundingBox x, y, w, h 'Gets the selections position and size'
ActivePage.SetSize w + 0.03936 * 2, h + 0.03936 * 2 'Set the Page Size & offset from the artwork (0.03936 is 1mm in inches)'
End Sub
I did however notice that all .gms files are protected **,) lol!How sentimental are you with regards to sharing the unprotected file so that I can update and modify the code for our internal workflows and possibly merge them with existing .gms modules that I already have in place?So; this is super simple; but this is what i put together for the "Fit Page to Content" solution, I did not build in a user form though; just assign them to keyboard shortcuts for the designers.