code: def preview_string(self, page, format='png', dpi=72, background_colour=0xFFFFFF):
          
          # Check the page number.
          if page < 1 or page > self.page_count:
              raise ValueError("Invalid page number; should be between 1 and {0:d}.".format(self.page_count))
  
          # Shade any remaining missing labels if desired.
          self._shade_remaining_missing()
  
          # Rendering to an image (as opposed to a PDF) requires any background
          # to have an integer width and height if it is a ReportLab Image
          # object. Drawing objects are exempt from this.
          oldw, oldh = None, None
          if isinstance(self._bgimage, Image):
              oldw, oldh = self._bgimage.width, self._bgimage.height
              self._bgimage.width = int(oldw) + 1
              self._bgimage.height = int(oldh) + 1
  
          # Let ReportLab do the heavy lifting.
          s = renderPM.drawToString(self._pages[page-1], format, dpi, background_colour)
  
          # Restore the size of the background image if we changed it.
          if oldw:
              self._bgimage.width = oldw
              self._bgimage.height = oldh
  
          # Done.
          return s
docs: Render a preview image of a page as a string.
  
          Parameters
          ----------
          page: positive integer
              Which page to render. Must be in the range [1, page_count]
          format: string
              The image format to use for the preview. ReportLab uses the Python
              Imaging Library (PIL) internally, so any PIL format should be
              supported.
          dpi: positive real
              The dots-per-inch to use when rendering.
          background_colour: Hex colour specification
              What color background to use.
  
          Notes
          -----
          If you are creating this sheet for a preview only, you can pass the
          pages_to_draw parameter to the constructor to avoid the drawing function
          being called for all the labels on pages you'll never look at. If you
          preview a page you did not tell the sheet to draw, you will get a blank
          image.
  
          Raises
          ------
          ValueError:
              If the page number is not valid.