mupdf added, everything is bytesIO
This commit is contained in:
parent
ad7d6c9b48
commit
1f92945ee4
20
app.py
20
app.py
@ -1,7 +1,9 @@
|
|||||||
from flask import Flask, request, render_template, current_app, send_file
|
from flask import Flask, request, render_template, current_app, send_file
|
||||||
import json
|
import json
|
||||||
from io import BytesIO
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import fitz # PyMuPDF
|
||||||
|
import io
|
||||||
|
|
||||||
from weasyprint import HTML, CSS
|
from weasyprint import HTML, CSS
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -67,10 +69,22 @@ def index():
|
|||||||
#verse_html = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'><style>{}</style></head><body>".format(read_css_file()) + verse_html + '</body></html>'
|
#verse_html = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'><style>{}</style></head><body>".format(read_css_file()) + verse_html + '</body></html>'
|
||||||
verse_html = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'></head><body>"+ verse_html + '</body></html>'
|
verse_html = "<!DOCTYPE html><html lang=en><head><meta charset='utf-8'></head><body>"+ verse_html + '</body></html>'
|
||||||
print(verse_html)
|
print(verse_html)
|
||||||
HTML(string=verse_html).write_pdf(
|
pdf_data=HTML(string=verse_html).write_pdf(
|
||||||
"custom_size.pdf",
|
|
||||||
stylesheets=[CSS(string=read_css_file())]
|
stylesheets=[CSS(string=read_css_file())]
|
||||||
)
|
)
|
||||||
|
doc = fitz.open(stream=pdf_data, filetype="pdf")
|
||||||
|
for page_index in range(len(doc)):
|
||||||
|
page = doc.load_page(page_index)
|
||||||
|
pix = page.get_pixmap(dpi=240)
|
||||||
|
|
||||||
|
# Convert the rendered image into PNG bytes
|
||||||
|
png_bytes = pix.tobytes("png")
|
||||||
|
|
||||||
|
# You can now send png_bytes to a response or store it in a DB
|
||||||
|
print(f"Page {page_index} is {len(png_bytes)} bytes.")
|
||||||
|
|
||||||
|
doc.close()
|
||||||
|
|
||||||
print(f"Reference: {reference}, Version: {version}, Text: {verse_text}, Error: {error}")
|
print(f"Reference: {reference}, Version: {version}, Text: {verse_text}, Error: {error}")
|
||||||
|
|
||||||
return render_template('index.html', reference=reference, version=version, verse_html=verse_html, error=error)
|
return render_template('index.html', reference=reference, version=version, verse_html=verse_html, error=error)
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
}
|
}
|
||||||
@page {
|
@page {
|
||||||
/* Set specific page dimensions: width height */
|
/* Set specific page dimensions: width height */
|
||||||
size: 9in 4.5in;
|
size: 8in 4.5in;
|
||||||
margin: 0.5in;
|
margin: 0.5in;
|
||||||
}
|
}
|
||||||
.text-html p,
|
.text-html p,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user