30 lines
914 B
Python
30 lines
914 B
Python
import fitz # PyMuPDF
|
|
import io
|
|
from weasyprint import HTML, CSS
|
|
from bs4 import BeautifulSoup
|
|
import sys
|
|
|
|
css='''
|
|
body {
|
|
font-size: 40px;
|
|
line-height: 40px;
|
|
color: #FFF;
|
|
font-family: "Times New Roman", Times, serif;
|
|
whitespace: pre-wrap;
|
|
|
|
}
|
|
|
|
@page {
|
|
/* Set specific page dimensions: width height */
|
|
size: 1920px 1080px;
|
|
margin: 70px;
|
|
background-color: #2c5aa0; color: white;
|
|
whitespace: pre-wrap;
|
|
}
|
|
'''
|
|
#html_skeleton = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'></head><body><p>{}</p></body></html>".format(sys.stdin.read().replace('\n','<br>').replace('\t',' '))
|
|
html_skeleton = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'></head><body><p>{}</p></body></html>".format(sys.stdin.read())
|
|
|
|
HTML(string=html_skeleton).write_pdf('output.pdf', stylesheets=[CSS(string=css)])
|
|
pdf_bytes=HTML(string=html_skeleton).write_pdf(stylesheets=[CSS(string=css)])
|