Module special_docx

Classes

AddDocx(doc, info)

Class for working with specific blocks in a document.

class sbi_special_docx_master.special_docx.AddDocx(doc, info)[source]

Class for working with specific blocks in a document. It adds textual and image information to a Document object.

Ensures that the original document is returned if an error occurs during modifications.

Variables:
  • _orig_doc – DocxDocument - The original document.

  • info – dict - A dictionary containing information to be added.

  • _new_doc – Optional[DocxDocument] - The new document after modifications (if successful).

Parameters:
  • doc (Document) –

  • info (Dict[str, List[Dict[str, Any]]]) –

static _add_image_from_base64(base64_string, height, doc)[source]

Adds an image from a Base64 string to the document.

Parameters:
  • base64_string (str) – The image string in Base64 format.

  • height (float) – The height of the image in inches.

  • doc (Document) –

_add_info(info)[source]

Adds textual and image information to the document.

Parameters:

info (List) – A list of dictionaries containing titles, content, and images.

property document: Document

Returns the document instance with the required modifications, or the original document if the modified version could not be generated.

property has_succeeded: bool

Returns True if the modified document was successfully created, or False if the document could not be generated.

save(filename)[source]

Saves the document to a file on disk.

Parameters:

filename (str) – The path to the file where the document will be saved.

save_io()[source]

Saves the document to an in-memory stream (BytesIO).

Returns:

A BytesIO stream with the saved document or None if an error occurs.

Return type:

BytesIO | None