django convert html that uses bootstrap 5 to docx or pdf with the result being formatting kinda like the input

25 views Asked by At

The need is to take a rendered template and convert it to docx and pdf. After experimenting some with several tools, pandoc seems like a good choice. The problem is the html input behaves as if there's no css being used on the input and the resulting docx or pdf look like barebones html formatting (e.g. h1 gets styled a little).

My question is: how do you set the css styling on the input so the translation comes out sort of looking like the input?

The html header has all the usual css definitions. Here they reference CDNs, but I also have a local version of the file.

<!DOCTYPE html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="LVM MGMT SYSTEM">
  <meta name="author" content="Weintraub & Grob">

  <link rel="icon" href="/static/images/logos/LVMLogo.ico">

  
    <!-- Latest compiled and minified Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css"
          integrity="s... media="all"/>
    <!-- Your stuff: Third-party CSS libraries go here -->

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
          type="text/css"/>

The rendered template makes extensive use of bootstrap d-flex layouts and other version 5 definitions. What results reflects the div structures, but none of the layouts. For example,

<div class="d-flex flex-row">
  <div> Whatever</div>
  <div>Peachy</div>
</div>

comes out as:

Whatever

Peachy

instead of

WhateverPeachy

Here's my code:

pypandoc.convert_text(source=person_text, 
                      format='html',
                      to=target, 
                      outputfile=file_name,
                      extra_args=["-M2GB", "+RTS", "-K64m", "-RTS"])

is there some parameter on the source I should be setting? Or should I break this into two steps - a read and a write?

Thanks for the help.

0

There are 0 answers