-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from TrustTheVote-Project/development
Merge Development to Main to close Issues
- Loading branch information
Showing
39 changed files
with
5,084 additions
and
1,045 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.