Skip to content

Commit 00318aa

Browse files
committed
Introduce PDF generation for parallel text comparison of Bible texts
This commit introduces an application that creates a PDF file with a parallel comparison of two Bible texts sourced from SQLite databases. The PDF generator script fetches data from the databases and synchronizes the texts at the beginning of each chapter, providing a side-by-side comparison format. Changes: - Added a workflow file for releasing PDFs with parallel text comparisons - Included a `.gitignore` file to exclude generated PDFs and other files - Added a Dockerfile for containerizing the PDF generation process - Included a MIT License for the project - Added a Makefile for building and generating PDFs - Updated the `README.md` with details about the project and usage instructions - Added a SQL file (`chapters.sql`) for querying and organizing Bible text chapters - Removed unnecessary `.zip` and `.SQLite3` files from the `db/` directory - Included different font files and styling assets for PDF rendering - Added a `print.css` file for setting PDF print styles - Included a `render.sed` file for text rendering transformations - Updated the `shell.nix` file by removing a specific script definition - Added a `style.css` file for defining the PDF styling and layout
1 parent 0f1a826 commit 00318aa

26 files changed

+264
-16
lines changed

.github/workflows/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Make a release with attached PDF
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
- name: Build
13+
run: make screen
14+
- name: Create release
15+
uses: softprops/action-gh-release@v2
16+
if: startsWith(github.ref, 'refs/tags/')
17+
with:
18+
draft: true
19+
files: '*.pdf'

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.html
2+
*.pdf
3+
*.zip
4+
*.SQLite3
5+
*.db

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM alpine:3.19.1
2+
ADD https://www.princexml.com/download/prince-15.3-r0-alpine3.19-x86_64.apk /tmp/prince.apk
3+
RUN apk add --allow-untrusted /tmp/prince.apk && rm /tmp/prince.apk
4+
ENTRYPOINT ["prince"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Paweł Placzyński
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
size ?= A6
2+
left ?= BT'03
3+
right ?= NA28
4+
5+
all: screen print
6+
7+
.PHONY: screen
8+
screen: $(left)-$(right)_screen.pdf
9+
10+
.PHONY: print
11+
print: $(left)-$(right)_print.pdf
12+
13+
$(left)-$(right).html: info-$(left).html info-$(right).html chapters.sql render.sed
14+
mv "$(left).SQLite3" left.db; mv "$(right).SQLite3" right.db; \
15+
{ echo "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><link rel=\"stylesheet\" href=\"style.css\"></head><body><h1>pocket-nt</h1><info>"; \
16+
cat "info-$(left).html" "info-$(right).html"; \
17+
echo "</info>"; \
18+
sqlite3 < chapters.sql | sed -rf render.sed; \
19+
echo "</body></html>"; \
20+
} > "$@"
21+
22+
%.zip:
23+
curl -s -o "$@" "https://raw.githubusercontent.com/placek/bible-databases/master/$(basename $@).zip"
24+
25+
%.SQLite3: %.zip
26+
unzip -j "$<"
27+
28+
%_screen.pdf: %.html
29+
docker run --rm -v "`pwd`":/data silquenarmo/princexml:15.3 --verbose --no-network --page-size=$(size) --media=screen --output="/data/$@" "/data/$<"
30+
31+
%_print_raw.pdf: %.html
32+
docker run --rm -v "`pwd`":/data silquenarmo/princexml:15.3 --verbose --no-network --page-size=$(size) --media=print --style=/data/print.css --output="/data/$@" "/data/$<"
33+
34+
%_print.pdf: %_print_raw.pdf
35+
gs -dPDFX -dBATCH -dNOPAUSE -dNOOUTERSAVE -dNoOutputFonts -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dHaveTransparency=false -sOutputFile="$@" "$<"
36+
37+
info-%.html: %.SQLite3
38+
{ echo "<column><description>"; \
39+
sqlite3 "$<" "select value from info where name = 'description'" | sed "s/,/<br>/g"; \
40+
echo "</description></column>"; \
41+
} > "$@"
42+
43+
.PHONY: clean
44+
clean:
45+
rm -f *.html *.pdf *.zip *.SQLite3 *.db

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1-
Source of the bible text[^1]
1+
# pocket-nt
22

3-
[^1]: https://www.ph4.org/b4_index.php
3+
A parallel Bible text comparison PDF generator.
4+
5+
## Overview
6+
This project is designed to generate a printable PDF file that provides a parallel comparison of two versions of Bible texts. It fetches data from two SQLite databases and generates a PDF that synchronizes the texts at the beginning of each chapter.
7+
8+
## Features
9+
- **Parallel text comparison:** Directly compares two different Bible texts side by side, starting synchronization at the beginning of each chapter.
10+
- **Multiple texts available:** Includes several Bible texts for comparison, which can be found in the `db/` directory of the project.
11+
- **Pocket PDF format:** Generates a pocket-sized PDF suitable for printing or viewing in standard PDF viewers.
12+
- **Data source:** The Bible texts used in this project are sourced from the library of Bible databases[^1].
13+
14+
## Getting Started
15+
To use this PDF generator, follow these steps:
16+
17+
1. **Clone the repository:**
18+
```
19+
git clone https://github.com/placek/pocket-nt.git
20+
cd pocket-nt
21+
```
22+
23+
2. **Run the PDF generator script:**
24+
Execute the script to generate the PDF:
25+
```
26+
make
27+
```
28+
Alternatively, you can use any known versions of the Bible:
29+
```
30+
make left=PAU right=NVUL
31+
```
32+
By default, the make command prepares two versions of the PDF: one for use on electronic devices (such as PCs and mobile devices) `*_screen.pdf` and one ready for printing (with printing marks and bevels) `*_print.pdf`. To select only one option for generation, use dedicated targets:
33+
```
34+
make screen left=CVUL right=NA27
35+
make print left=CVUL right=NA27
36+
```
37+
**NOTE** If there is any problem with the generation of any variant, please [report that](https://github.com/placek/pocket-nt/issues/new).
38+
39+
3. **View or print the PDF:**
40+
Once generated, the PDF will be available in the specified output directory. You can open it with any PDF viewer or send it to a printer.
41+
42+
## Dependencies
43+
- SQLite3 3.43.2
44+
- [PrinceXML 15.3](https://www.princexml.com) (via Docker image[^2])
45+
- GNU Make 4.4.1
46+
- GNU sed 4.9
47+
- cUrl 8.4.0
48+
- UnZip 6.00
49+
50+
## Contributing
51+
Contributions to this project are welcome. Please ensure to follow the existing coding style.
52+
53+
## License
54+
The project can be distributed under the [MIT License](./LICENSE).
55+
56+
### DISCLAIMER
57+
There are some limitations on the two aspects of the resources used by this tool:
58+
1. The author of pocket-nt is not the owner of the SQLite databases. Each database has its own license and has to be carefully considered when such will be in any circumstance used/sold/modified/published/etc.
59+
2. The PrinceXML has its own [limited license](https://www.princexml.com/purchase/).
60+
61+
62+
[^1]: https://github.com/placek/bible-databases
63+
[^2]: https://hub.docker.com/r/silquenarmo/princexml

TODO

Lines changed: 0 additions & 1 deletion
This file was deleted.

TODO.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

chapters.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ATTACH DATABASE 'left.db' AS db1;
2+
ATTACH DATABASE 'right.db' AS db2;
3+
4+
WITH
5+
AllVersesD1 AS (
6+
SELECT
7+
b.book_number,
8+
b.long_name AS book,
9+
v.chapter,
10+
v.verse,
11+
v.text
12+
FROM
13+
db1.verses AS v
14+
JOIN
15+
db1.books AS b
16+
ON
17+
v.book_number = b.book_number
18+
WHERE
19+
b.book_number >= 470
20+
ORDER BY b.book_number, v.chapter, v.verse
21+
),
22+
AllVersesD2 AS (
23+
SELECT
24+
b.book_number,
25+
b.long_name AS book,
26+
v.chapter,
27+
v.verse,
28+
v.text
29+
FROM
30+
db2.verses AS v
31+
JOIN
32+
db2.books AS b
33+
ON
34+
v.book_number = b.book_number
35+
WHERE
36+
b.book_number >= 470
37+
ORDER BY b.book_number, v.chapter, v.verse
38+
),
39+
AllChaptersD1 AS (
40+
SELECT
41+
book_number,
42+
book,
43+
chapter,
44+
GROUP_CONCAT('{{verse data-verse="' || verse || '"}}' || text || '{{/verse}}', '') AS verses
45+
FROM
46+
AllVersesD1
47+
GROUP BY book_number, chapter
48+
),
49+
AllChaptersD2 AS (
50+
SELECT
51+
book_number,
52+
book,
53+
chapter,
54+
GROUP_CONCAT('{{verse data-verse="' || verse || '"}}' || text || '{{/verse}}', '') AS verses
55+
FROM
56+
AllVersesD2
57+
GROUP BY book_number, chapter
58+
)
59+
SELECT
60+
v1.book_number,
61+
v1.book,
62+
v1.chapter,
63+
v1.verses AS left,
64+
v2.verses AS right
65+
FROM AllChaptersD1 AS v1
66+
JOIN AllChaptersD2 AS v2
67+
ON v1.book_number = v2.book_number AND v1.chapter = v2.chapter;

db/NA27ca.zip

-1.52 MB
Binary file not shown.

0 commit comments

Comments
 (0)