Skip to content

Commit

Permalink
Merge pull request #119 from TrustTheVote-Project/development
Browse files Browse the repository at this point in the history
Merge Development to Main to close Issues
  • Loading branch information
stratofax authored Sep 26, 2022
2 parents 805936d + 45f06ba commit 9b34c45
Show file tree
Hide file tree
Showing 39 changed files with 5,084 additions and 1,045 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

A version history of BallotLab.

## 0.1.3 - September 20, 2022

Completed [Milestone 2. Generate ballot PDFs with embedded form objects Milestone](https://github.com/TrustTheVote-Project/BallotLab/milestone/2)

* Prototype check boxes to track coordinates of vote marking ovals
* Generate ballots with hidden, embedded form objects to track coordinates and ids of vote mark ovals
* Generate ballots from all four (4) precincts in the September 2022 EDF
* Incorporate new NISTLib data access layer (includes corresponding test harness)
* Additional layout enhancements and refinements

## 0.1.2 - September 7, 2022

Complete Milestone 1: flat file PDF. Notable features include:
Completed milestone 1: [Generate flat PDFs from Jetsons EDF](https://github.com/TrustTheVote-Project/BallotLab/milestone/1)

* Multi-candidate tickets (including contest section IDs)
* Write-ins (also with contest selection IDs)
Expand Down
Binary file added pdfs/ballot_demo_2022_09_13T095513.pdf
Binary file not shown.
Binary file added pdfs/precinct_2_spacetown.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "BallotMaker"
version = "0.1.1"
version = "0.1.3"
description = "Generate PDF ballots from EDF file; part of ElectOS Versa."
authors = ["Neil Johnson <[email protected]>"]
license = "OSET Public License"
Expand Down
9 changes: 9 additions & 0 deletions samplecode/form_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import PyPDF2 as pypdf

pdfobject = open(
"/Users/neil/repos/BallotLabFork/samplecode/ballot_demo_2022_09_13T095513.pdf",
"rb",
)
pdf = pypdf.PdfFileReader(pdfobject)
form_data = pdf.get_fields()
print(form_data)
79 changes: 79 additions & 0 deletions samplecode/form_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# from https://groups.google.com/g/reportlab-users/c/KRx3oLi34Dc/m/3GGnhy3qCQAJ
# import PyPDF2
from reportlab.pdfbase import pdfform
from reportlab.platypus import Flowable, SimpleDocTemplate, Table

# from pprint import pprint


class formCheckButton(Flowable):
def __init__(self, title, value="Yes"):
self.title = title
self.value = value
self.width = 16
self.height = 16

def wrap(self, *args):
self.width = args[0]
return (self.width, self.height)

def draw(self):
self.canv.saveState()
pdfform.buttonFieldRelative(
self.canv,
self.title,
self.value,
0,
0,
# including w & h shift the buttons up
# width=self.width,
# height=self.height,
)
self.canv.restoreState()


class formInputField(Flowable):
def __init__(self, id, value="Sample"):
self.id = id
self.value = value
self.width = 0
self.height = 10

def wrap(self, *args):
self.width = args[0]
return (self.width, self.height)

def draw(self):
self.canv.saveState()
pdfform.textFieldRelative(self.canv, self.id, 0, 0, 50, 10, self.value)
self.canv.restoreState()


class createExamplePDFFormFile:
def __init__(self, filename):
data = []
value = "Yes"
for i in range(10):
title = f"title {i}"
checkbox = formCheckButton(title, value)
data.append([title, checkbox])
dataTable = Table(data)
print([dataTable])
doc = SimpleDocTemplate(filename)
doc.build([dataTable])


# class readExamplePDFFormFile:
# def __init__(self, filename):
# f = PyPDF2.PdfFileReader(filename)
# data = f.getFields()
# for title, value in data.items():
# pprint(value)


ORIGINAL_FILE = "OriginalFile.pdf"
EDITED_FILE = "EditedFile.pdf"

createExamplePDFFormFile(ORIGINAL_FILE)
# readExamplePDFFormFile(ORIGINAL_FILE)
# readExamplePDFFormFile(EDITED_FILE)
Loading

0 comments on commit 9b34c45

Please sign in to comment.