@@ -402,16 +402,43 @@ class PrintOptions:
402402 - Set
403403 - `None`
404404 """
405+ # Predefined page sizes (in centimeters)
406+ A4 = {"height" : 29.7 , "width" : 21.0 } # size in cm
407+ LEGAL = {"height" : 35.56 , "width" : 21.59 } # size in cm
408+ LETTER = {"height" : 27.94 , "width" : 21.59 } # size in cm
409+ TABLOID = {"height" : 43.18 , "width" : 27.94 } # size in cm
405410
406411 def __init__ (self ) -> None :
407412 self ._print_options : _PrintOpts = {}
408- self ._page : _PageOpts = {}
413+ self ._page : _PageOpts = {"height" : PrintOptions . A4 [ "height" ], "width" : PrintOptions . A4 [ "width" ]} # Default page size set to A4
409414 self ._margin : _MarginOpts = {}
410415
411416 def to_dict (self ) -> _PrintOpts :
412417 """:Returns: A hash of print options configured."""
413418 return self ._print_options
414419
420+ def set_page_size (self , page_size : dict ) -> None :
421+ """
422+ Sets the page size to predefined or custom dimensions.
423+
424+ Parameters
425+ ----------
426+ page_size: dict
427+ A dictionary containing `height` and `width` as keys with respective values.
428+
429+ Example
430+ -------
431+ self.set_page_size(PageSize.A4) # A4 predefined size
432+ self.set_page_size({"height": 15.0, "width": 20.0}) # Custom size in cm
433+
434+ """
435+ self ._validate_num_property ("height" , page_size ["height" ])
436+ self ._validate_num_property ("width" , page_size ["width" ])
437+ self ._page ["height" ] = page_size ["height" ]
438+ self ._page ["width" ] = page_size ["width" ]
439+ self ._print_options ["page" ] = self ._page
440+
441+
415442 def _validate_num_property (self , property_name : str , value : float ) -> None :
416443 """Helper function to validate some of the properties."""
417444 if not isinstance (value , (int , float )):
0 commit comments