Skip to content

Commit

Permalink
Merge pull request #1755 from emko-274/add_margin
Browse files Browse the repository at this point in the history
Fixed COMPILED.pdf and updated PDF layout
  • Loading branch information
emko-274 authored Aug 24, 2024
2 parents 38bc0e4 + 5f20ba6 commit 4c981dd
Show file tree
Hide file tree
Showing 8 changed files with 1,290 additions and 1,283 deletions.
5 changes: 1 addition & 4 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,7 @@ def update_annotations(self):
def add_text(self, text: str):
_pdf = PdfReader(fdata=MarkdownToPDF.to_pdf("Addendum", text))
self.writer.addpages(_pdf.pages)

def get_pages(self):
return self._pdf.pages


def write(self, path: str):
self.writer.addpages(self._pdf.pages)

Expand Down
3 changes: 2 additions & 1 deletion src/backend/expungeservice/pdf/markdown_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def to_markdown(record: Dict, header: Optional[str] = None, aliases: List[Dict]
if x[0] == "Eligible Now If Balance Paid"
]

county_fines = [x for x in record["summary"]["county_fines"]]
county_fines = [county for county in record["summary"]["county_fines"] if county['total_fines_due'] != 0]

eligible_charges_by_date = record["summary"]["charges_grouped_by_eligibility_and_case"]
future_eligible_charges = [
(key, eligible_charges_for_date)
Expand Down
14 changes: 10 additions & 4 deletions src/backend/expungeservice/pdf/markdown_to_pdf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import markdown2
import pdfkit
import requests
import pathlib
from os import path


class MarkdownToPDF:
@staticmethod
def to_pdf(title: str, markdown_source: str) -> bytes:
html_style = MarkdownToPDF.css()
html_body = markdown2.markdown(markdown_source)

html = f"""
<html>
<head>
Expand All @@ -25,12 +28,15 @@ def to_pdf(title: str, markdown_source: str) -> bytes:
return pdfkit.from_string(html, False, options={"quiet": ""})

@staticmethod
# Reads 'style.txt' to string.
## 'style.txt' copied from https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css
def css():
response = requests.get(
"https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css"
)
fp = path.join(pathlib.Path(__file__).parent, "style.txt")

with open(fp, 'r') as f:
text = f.read()

return response.text
return text


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 4c981dd

Please sign in to comment.