class_docstr: A class for converting documents from the hOCR format.
  
  For details of the hOCR format, see:
  http://kba.cloud/hocr-spec/.
class_docstr_tok: ["A","class","for","converting","documents","from","the","hOCR","format",".","For","details","of","the","hOCR","format",",","see",":","http",":","\/\/kba.cloud\/hocr-spec\/","."]
docstr: Creates a PDF file with an image superimposed on top of the text.
  
  Text is positioned according to the bounding box of the lines in
  the hOCR file.
  The image need not be identical to the image used to create the hOCR
  file.
  It can have a lower resolution, different color mode, etc.
  
  Arguments:
      out_filename: Path of PDF to write.
      image_filename: Image to use for this file. If omitted, the OCR text
          is shown.
      invisible_text: If True, text is rendered invisible so that is
          selectable but never drawn. If False, text is visible and may
          be seen if the image is skipped or deleted in Acrobat.
docstr_tok: ["Creates","a","PDF","file","with","an","image","superimposed","on","top","of","the","text",".","Text","is","positioned","according","to","the","bounding","box","of","the","lines","in","the","hOCR","file",".","The","image","need","not","be","identical","to","the","image","used","to","create","the","hOCR","file",".","It","can","have","a","lower","resolution",",","different","color","mode",",","etc",".","Arguments",":","out_filename",":","Path","of","PDF","to","write",".","image_filename",":","Image","to","use","for","this","file",".","If","omitted",",","the","OCR","text","is","shown",".","invisible_text",":","If","True",",","text","is","rendered","invisible","so","that","is","selectable","but","never","drawn",".","If","False",",","text","is","visible","and","may","be","seen","if","the","image","is","skipped","or","deleted","in","Acrobat","."]
code: def to_pdf(
      self,
      *,
      out_filename: Path,
      image_filename: Path | None = None,
      invisible_text: bool = True,
  ) -> None:
      """Creates a PDF file with an image superimposed on top of the text.
  
      Text is positioned according to the bounding box of the lines in
      the hOCR file.
      The image need not be identical to the image used to create the hOCR
      file.
      It can have a lower resolution, different color mode, etc.
  
      Arguments:
          out_filename: Path of PDF to write.
          image_filename: Image to use for this file. If omitted, the OCR text
              is shown.
          invisible_text: If True, text is rendered invisible so that is
              selectable but never drawn. If False, text is visible and may
              be seen if the image is skipped or deleted in Acrobat.
      """
      # create the PDF file
      # page size in points (1/72 in.)
      canvas = Canvas(page_size=(self.width, self.height))
      canvas.add_font(self._fontname, self._font)
      page_matrix = (
          Matrix()
          .translated(0, self.height)
          .scaled(1, -1)
          .scaled(INCH / self.dpi, INCH / self.dpi)
      )
      log.debug(page_matrix)
      with canvas.do.save_state(cm=page_matrix):
          self._debug_draw_paragraph_boxes(canvas)
          found_lines = False
          for par in self.hocr.iterfind(
              self._child_xpath("p", "ocr_par")
          ):
              for line in (
                  element
                  for element in par.iterfind(self._child_xpath("span"))
                  if "class" in element.attrib
                  and element.attrib["class"]
                  in {"ocr_header", "ocr_line", "ocr_textfloat"}
              ):
                  found_lines = True
                  direction = self._get_text_direction(par)
                  inject_word_breaks = self._get_inject_word_breaks(par)
                  self._do_line(
                      canvas,
                      line,
                      "ocrx_word",
                      invisible_text,
                      direction,
                      inject_word_breaks,
                  )
  
          if not found_lines:
              # Tesseract did not report any lines (just words)
              root = self.hocr.find(
                  self._child_xpath("div", "ocr_page")
              )
              direction = self._get_text_direction(root)
              self._do_line(
                  canvas,
                  root,
                  "ocrx_word",
                  invisible_text,
                  direction,
                  True,
              )
      # put the image on the page, scaled to fill the page
      if image_filename is not None:
          canvas.do.draw_image(
              image_filename, 0, 0, width=self.width, height=self.height
          )
  
      # finish up the page and save it
      canvas.to_pdf().save(out_filename)
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import unicodedata
  from dataclasses import dataclass
  from itertools import pairwise
  from math import atan, cos, pi
  from pathlib import Path
  from xml.etree import ElementTree
  from pikepdf import Matrix, Name, Rectangle
  from pikepdf.canvas import BLACK, BLUE, CYAN, DARKGREEN, GREEN, MAGENTA, RED, Canvas, Text, TextDirection
  from ocrmypdf.hocrtransform._font import EncodableFont
  from ocrmypdf.hocrtransform._font import GlyphlessFont
label_desc: Use image node_id 7 for calling the HocrTransform obj's underlying member method code with example usage: obj.to_pdf() without return types