Skip to content

Commit

Permalink
Introduce PDF generation for parallel text comparison of Bible texts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
placek committed Apr 19, 2024
1 parent 0f1a826 commit 00318aa
Show file tree
Hide file tree
Showing 26 changed files with 264 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Make a release with attached PDF
on:
push:
tags:
- "v*.*.*"
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build
run: make screen
- name: Create release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: '*.pdf'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.html
*.pdf
*.zip
*.SQLite3
*.db
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine:3.19.1
ADD https://www.princexml.com/download/prince-15.3-r0-alpine3.19-x86_64.apk /tmp/prince.apk
RUN apk add --allow-untrusted /tmp/prince.apk && rm /tmp/prince.apk
ENTRYPOINT ["prince"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Paweł Placzyński

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
size ?= A6
left ?= BT'03
right ?= NA28

all: screen print

.PHONY: screen
screen: $(left)-$(right)_screen.pdf

.PHONY: print
print: $(left)-$(right)_print.pdf

$(left)-$(right).html: info-$(left).html info-$(right).html chapters.sql render.sed
mv "$(left).SQLite3" left.db; mv "$(right).SQLite3" right.db; \
{ echo "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><link rel=\"stylesheet\" href=\"style.css\"></head><body><h1>pocket-nt</h1><info>"; \
cat "info-$(left).html" "info-$(right).html"; \
echo "</info>"; \
sqlite3 < chapters.sql | sed -rf render.sed; \
echo "</body></html>"; \
} > "$@"

%.zip:
curl -s -o "$@" "https://raw.githubusercontent.com/placek/bible-databases/master/$(basename $@).zip"

%.SQLite3: %.zip
unzip -j "$<"

%_screen.pdf: %.html
docker run --rm -v "`pwd`":/data silquenarmo/princexml:15.3 --verbose --no-network --page-size=$(size) --media=screen --output="/data/$@" "/data/$<"

%_print_raw.pdf: %.html
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/$<"

%_print.pdf: %_print_raw.pdf
gs -dPDFX -dBATCH -dNOPAUSE -dNOOUTERSAVE -dNoOutputFonts -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dHaveTransparency=false -sOutputFile="$@" "$<"

info-%.html: %.SQLite3
{ echo "<column><description>"; \
sqlite3 "$<" "select value from info where name = 'description'" | sed "s/,/<br>/g"; \
echo "</description></column>"; \
} > "$@"

.PHONY: clean
clean:
rm -f *.html *.pdf *.zip *.SQLite3 *.db
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
Source of the bible text[^1]
# pocket-nt

[^1]: https://www.ph4.org/b4_index.php
A parallel Bible text comparison PDF generator.

## Overview
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.

## Features
- **Parallel text comparison:** Directly compares two different Bible texts side by side, starting synchronization at the beginning of each chapter.
- **Multiple texts available:** Includes several Bible texts for comparison, which can be found in the `db/` directory of the project.
- **Pocket PDF format:** Generates a pocket-sized PDF suitable for printing or viewing in standard PDF viewers.
- **Data source:** The Bible texts used in this project are sourced from the library of Bible databases[^1].

## Getting Started
To use this PDF generator, follow these steps:

1. **Clone the repository:**
```
git clone https://github.com/placek/pocket-nt.git
cd pocket-nt
```

2. **Run the PDF generator script:**
Execute the script to generate the PDF:
```
make
```
Alternatively, you can use any known versions of the Bible:
```
make left=PAU right=NVUL
```
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:
```
make screen left=CVUL right=NA27
make print left=CVUL right=NA27
```
**NOTE** If there is any problem with the generation of any variant, please [report that](https://github.com/placek/pocket-nt/issues/new).

3. **View or print the PDF:**
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.

## Dependencies
- SQLite3 3.43.2
- [PrinceXML 15.3](https://www.princexml.com) (via Docker image[^2])
- GNU Make 4.4.1
- GNU sed 4.9
- cUrl 8.4.0
- UnZip 6.00

## Contributing
Contributions to this project are welcome. Please ensure to follow the existing coding style.

## License
The project can be distributed under the [MIT License](./LICENSE).

### DISCLAIMER
There are some limitations on the two aspects of the resources used by this tool:
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.
2. The PrinceXML has its own [limited license](https://www.princexml.com/purchase/).


[^1]: https://github.com/placek/bible-databases
[^2]: https://hub.docker.com/r/silquenarmo/princexml
1 change: 0 additions & 1 deletion TODO

This file was deleted.

7 changes: 0 additions & 7 deletions TODO.md

This file was deleted.

67 changes: 67 additions & 0 deletions chapters.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
ATTACH DATABASE 'left.db' AS db1;
ATTACH DATABASE 'right.db' AS db2;

WITH
AllVersesD1 AS (
SELECT
b.book_number,
b.long_name AS book,
v.chapter,
v.verse,
v.text
FROM
db1.verses AS v
JOIN
db1.books AS b
ON
v.book_number = b.book_number
WHERE
b.book_number >= 470
ORDER BY b.book_number, v.chapter, v.verse
),
AllVersesD2 AS (
SELECT
b.book_number,
b.long_name AS book,
v.chapter,
v.verse,
v.text
FROM
db2.verses AS v
JOIN
db2.books AS b
ON
v.book_number = b.book_number
WHERE
b.book_number >= 470
ORDER BY b.book_number, v.chapter, v.verse
),
AllChaptersD1 AS (
SELECT
book_number,
book,
chapter,
GROUP_CONCAT('{{verse data-verse="' || verse || '"}}' || text || '{{/verse}}', '') AS verses
FROM
AllVersesD1
GROUP BY book_number, chapter
),
AllChaptersD2 AS (
SELECT
book_number,
book,
chapter,
GROUP_CONCAT('{{verse data-verse="' || verse || '"}}' || text || '{{/verse}}', '') AS verses
FROM
AllVersesD2
GROUP BY book_number, chapter
)
SELECT
v1.book_number,
v1.book,
v1.chapter,
v1.verses AS left,
v2.verses AS right
FROM AllChaptersD1 AS v1
JOIN AllChaptersD2 AS v2
ON v1.book_number = v2.book_number AND v1.chapter = v2.chapter;
Binary file removed db/NA27ca.zip
Binary file not shown.
Binary file removed db/NA27ca/NA27ca.SQLite3
Binary file not shown.
Binary file removed db/NA27ca/NA27ca.commentaries.SQLite3
Binary file not shown.
Binary file removed db/NA28.zip
Binary file not shown.
Binary file removed db/NA28/NA28.SQLite3
Binary file not shown.
Binary file removed db/NA28/NA28.commentaries.SQLite3
Binary file not shown.
Binary file removed db/PBPW.zip
Binary file not shown.
Binary file removed db/PBPW/PBPW.SQLite3
Binary file not shown.
Binary file added fonts/freesans.ttf
Binary file not shown.
Binary file added fonts/freeserif.ttf
Binary file not shown.
Binary file added fonts/greek.ttf
Binary file not shown.
Binary file added fonts/mono.ttf
Binary file not shown.
Binary file added fonts/newathu.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@page { marks: crop cross; bleed: 5mm; -prince-trim: 5mm; }
15 changes: 15 additions & 0 deletions render.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
s/<n>[^<]*<\/n>//g # remove all notes
s/<S>[^<]*<\/S>//g # remove all strong codes
s/<m>[^<]*<\/m>//g # remove all grammar codes
s/<[^>]*>//g # remove all tag begginings
s/<\/[^>]*>//g # remove all tag endings
s/\*//g # remove all asterisks
s/\[[0-9]*\]//g # remove all numbers in square brackets
s/\s+/ /g # remove extra whitespaces

s/^[0-9]*\|([^|]*)\|1\|([^|]*)\|([^|]*)$/<book data-book="\1"><chapter data-chapter="1"><column class="left">\2<\/column><column class="right">\3<\/column><\/chapter>/
s/^[0-9]*\|[^|]*\|([^|]*)\|([^|]*)\|([^|]*)$/<chapter data-chapter="\1"><column class="left">\2<\/column><column class="right">\3<\/column><\/chapter>/
s/\{\{/</g
s/\}\}/>/g

$a</book>
9 changes: 3 additions & 6 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:
let
db = pkgs.writeShellScriptBin "db" ''
${pkgs.rlwrap}/bin/rlwrap ${pkgs.sqlite}/bin/sqlite3 $@
'';
in
pkgs.mkShell {
buildInputs = [
pkgs.ghostscript
pkgs.gnumake
pkgs.gnused
pkgs.sqlite
db
];
}
22 changes: 22 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
:root { --size: 2vh; }

@font-face { font-family: greek; src: url(fonts/newathu.ttf); }
@font-face { font-family: mono; src: url(fonts/mono.ttf); }
@font-face { font-family: f1; src: url(fonts/freeserif.ttf); }
@font-face { font-family: f2; src: url(fonts/freesans.ttf); }

@page { margin: 1.6em .8em .8em .8em; }
@page book:left { @top-left { content: string(book); font-family: mono; font-weight: 600; font-size: var(--size); } }
@page book:right { @top-right { content: string(chapter); font-family: mono; font-weight: 600; font-size: var(--size); } }
@page book:blank { @top-left { content: ""; } @top-right { content: ""; } }

* { margin: 0; padding: 0; }
body { font-size: var(--size); text-align: justify; font-family: greek, mono, f1, f2; line-height: 1.2; }
h1 { font-family: mono; font-weight: 600; font-size: 5vh; margin: 40vh 0; padding: 0; text-align: center; }
info { display: flex; width: 100%; justify-content: space-between; }
book { string-set: book attr(data-book); display: block; break-before: left; page: book; }
chapter { string-set: chapter attr(data-chapter); display: flex; }
chapter:before { content: attr(data-chapter); font-family: mono; font-weight: 600; }
column { display: block; padding: 0 .5em; }
verse { margin: 0; padding: 0; display: inline; }
verse:before { content: attr(data-verse); font-family: mono; font-weight: 600; font-size: .6em; margin: 0 .5em; vertical-align: super; }

0 comments on commit 00318aa

Please sign in to comment.