Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Then open `http://127.0.0.1:5000`.
The configurator accepts an uploaded Markdown file or pasted Markdown and lets you control the generated PDF without modifying the source text. Settings include:

- output filename
- PDF metadata: document title, author, subject, and keywords
- optional previous PDF upload that reuses Title, Author, Subject, and Keywords when the corresponding metadata fields are blank
- PDF metadata beneath Letterhead: Title and Subject inherit the visible document title, Author inherits the wordmark, and each can be overridden independently
- optional previous PDF upload that fills otherwise-unset Title, Author, Subject, and Keywords; manual metadata values take priority
- optional smart quotes in rendered text
- section numbering: legal form such as `I.B.3.a.i`, decimal form such as `1.2.3.4.5`, or no visible numbering
- optional visible table of contents using the generated section labels and page locations
Expand Down Expand Up @@ -120,7 +120,7 @@ If `ref-a` is ultimately note 7, the rendered text reads `See supra note 7.` The
## Optional PDF/A-4 output

Standard PDF remains the default. Choose **PDF/A-4 (ISO 19005-4:2020)**
on the Output metadata page, or use `--pdfa4` in the command-line
on the Document page, or use `--pdfa4` in the command-line
compiler. Only the base PDF/A-4 profile is supported: no PDF/A-4e,
PDF/A-4f, PDF/A-4a, PDF/A-4u, or PDF/UA claim is made.

Expand Down
18 changes: 16 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def index():
' <script src="/static/plain-link-options.js"></script>\n'
' <script src="/static/render-styles.js"></script>\n'
' <script src="/static/configuration.js"></script>\n'
' <script src="/static/emoji-styles.js"></script>\n</body>',
' <script src="/static/emoji-styles.js"></script>\n'
' <script src="/static/metadata-inheritance.js"></script>\n</body>',
1,
)

Expand Down Expand Up @@ -286,8 +287,21 @@ def render_pdf():
if error:
return jsonify({"error": error}), 400

# PDF information follows the visible letterhead unless the user supplied
# an explicit metadata override. Imported metadata fills any remaining gaps.
letterhead_metadata = {
"title": request.form.get("document_title", "").strip(),
"author": request.form.get("wordmark", "").strip(),
"subject": request.form.get("document_title", "").strip(),
}

def metadata_value(name: str) -> str | None:
return request.form.get(name, "").strip() or previous_metadata.get(name) or None
return (
request.form.get(name, "").strip()
or letterhead_metadata.get(name)
or previous_metadata.get(name)
or None
)

preset = request.form.get("letterhead_preset", "").strip()
if preset and preset not in LETTERHEAD_PRESETS:
Expand Down
42 changes: 42 additions & 0 deletions static/metadata-inheritance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(() => {
function inheritedMetadataValues(form) {
const value = name => (form.elements.namedItem(name)?.value || '').trim();
const title = value('document_title');
return { title, author: value('wordmark'), subject: title };
}

function updateMetadataHints(form, documentRoot = document) {
const values = inheritedMetadataValues(form);
const origins = { title: 'visible document title', author: 'branding wordmark',
subject: 'visible document title' };
for (const [name, value] of Object.entries(values)) {
const field = form.elements.namedItem(name);
if (!field) continue;
if (!field.dataset.basePlaceholder) {
field.dataset.basePlaceholder = field.placeholder;
}
// A placeholder shows the live inheritance without turning it into
// an explicit override. Users can still type any value independently.
field.placeholder = value || field.dataset.basePlaceholder;
const hint = documentRoot.getElementById('metadata-' + name + '-hint');
if (hint && value) {
hint.textContent = 'Default: ' + value + ' (from ' + origins[name]
+ '). Type a different value to override.';
} else if (hint) {
hint.textContent = 'Leave blank to inherit from the previous PDF when available'
+ (name === 'title' ? ', otherwise use the source filename stem.' : '.');
}
}
}

if (typeof module !== 'undefined') {
module.exports = { inheritedMetadataValues, updateMetadataHints };
}
if (typeof document !== 'undefined') {
const form = document.getElementById('compiler-form');
if (!form) return;
form.addEventListener('input', () => updateMetadataHints(form));
form.addEventListener('change', () => updateMetadataHints(form));
updateMetadataHints(form);
}
})();
86 changes: 45 additions & 41 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@
}

.letterhead-layout-settings { display: grid; gap: 10px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.settings-subheading { margin: 0; color: var(--text); font-size: 16px; }
.settings-help { margin: 0; color: var(--muted); font-size: 13px; }
.letterhead-editor { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(190px, 1fr); gap: 14px; align-items: start; }
.letterhead-editor[hidden], #letterhead-custom-controls[hidden] { display: none; }
.letterhead-stage-column { min-width: 0; display: grid; gap: 8px; }
Expand Down Expand Up @@ -276,7 +278,7 @@ <h1>PDF Compiler</h1>
<div class="wizard">
<div class="wizard-progress" aria-live="polite">
<div class="wizard-progress-row">
<span id="step-count" class="step-count">Step 1 of 11</span>
<span id="step-count" class="step-count">Step 1 of 10</span>
<span id="step-title" class="step-title">Document</span>
</div>
<div class="progress-track" aria-hidden="true"><div id="progress-fill" class="progress-fill"></div></div>
Expand All @@ -286,14 +288,13 @@ <h1>PDF Compiler</h1>
<button class="step-tab" type="button" data-step-target="0">Document</button>
<button class="step-tab" type="button" data-step-target="1">Typography</button>
<button class="step-tab" type="button" data-step-target="2">Sections</button>
<button class="step-tab" type="button" data-step-target="3">Metadata</button>
<button class="step-tab" type="button" data-step-target="4">Branding</button>
<button class="step-tab" type="button" data-step-target="5">Signature</button>
<button class="step-tab" type="button" data-step-target="6">Letterhead</button>
<button class="step-tab" type="button" data-step-target="7">Headers</button>
<button class="step-tab" type="button" data-step-target="8">Style</button>
<button class="step-tab" type="button" data-step-target="9">Licensing</button>
<button class="step-tab" type="button" data-step-target="10">Validate document</button>
<button class="step-tab" type="button" data-step-target="3">Branding</button>
<button class="step-tab" type="button" data-step-target="4">Signature</button>
<button class="step-tab" type="button" data-step-target="5">Letterhead</button>
<button class="step-tab" type="button" data-step-target="6">Headers</button>
<button class="step-tab" type="button" data-step-target="7">Style</button>
<button class="step-tab" type="button" data-step-target="8">Licensing</button>
<button class="step-tab" type="button" data-step-target="9">Validate document</button>
</nav>

<fieldset class="wizard-page" data-step-title="Document">
Expand Down Expand Up @@ -334,6 +335,13 @@ <h1>PDF Compiler</h1>
</select>
<small>Word exports are editable drafts. Check court-specific rules or the Office of the Federal Register's drafting requirements before submission.</small>
</label>
<label class="full">PDF format
<select name="pdf_format">
<option value="standard" selected>Standard PDF (default)</option>
<option value="pdfa4">PDF/A-4 (ISO 19005-4:2020)</option>
</select>
<small>Applies to PDF exports only. PDF/A-4 needs pikepdf and veraPDF on the server; archival output is returned only after validation.</small>
</label>
<label>Image files
<input id="inline-images" type="file" name="inline_images" accept="image/png,image/jpeg,image/gif,image/webp,image/bmp,image/tiff" multiple>
<small>Attach image files individually or use the document folder picker.</small>
Expand Down Expand Up @@ -464,37 +472,6 @@ <h1>PDF Compiler</h1>
</div>
</fieldset>

<fieldset class="wizard-page" data-step-title="Output metadata">
<legend>Output metadata</legend>
<div class="grid">
<label class="full">PDF format
<select name="pdf_format">
<option value="standard" selected>Standard PDF (default)</option>
<option value="pdfa4">PDF/A-4 (ISO 19005-4:2020)</option>
</select>
<small>PDF/A-4 preserves the existing renderer and validates with veraPDF. Requires pikepdf and a veraPDF installation on the server; if validation fails, no archival PDF is returned. This does not add PDF/UA accessibility certification.</small>
</label>
<label class="full">Previous PDF
<input type="file" name="previous_pdf" accept=".pdf,application/pdf">
<small>Optionally reuse Title, Author, Subject, and Keywords from an earlier PDF. Values entered below override inherited metadata.</small>
</label>
<label class="full">PDF title metadata
<input name="title" placeholder="Comment Letter">
<small>Stored only as the PDF Title metadata. If blank, the source filename stem is used.</small>
</label>
<label>Author
<input name="author" placeholder="Organization or author">
</label>
<label>Subject
<input name="subject" placeholder="Document subject or filing description">
</label>
<label class="full">Keywords
<input name="keywords" placeholder="securities, transfer agents, comment letter">
<small>Stored in the PDF Keywords metadata; comma-separated terms work well.</small>
</label>
</div>
</fieldset>

<fieldset class="wizard-page" data-step-title="Branding">
<legend>Branding</legend>
<div class="grid">
Expand Down Expand Up @@ -542,7 +519,7 @@ <h1>PDF Compiler</h1>
</label>
<label class="full">Visible document title
<input name="document_title" placeholder="In re File No. SR-OCC-2025-801">
<small>Rendered prominently on page 1. This is separate from the PDF Title metadata above.</small>
<small>Rendered prominently on page 1. PDF Title and Subject metadata inherit this title unless you override them below.</small>
</label>
<label>Quote #
<input name="quote_number" placeholder="Optional reference number">
Expand Down Expand Up @@ -613,6 +590,33 @@ <h1>PDF Compiler</h1>
</div>
</section>

<section class="letterhead-layout-settings full" aria-label="PDF metadata settings">
<h3 class="settings-subheading">PDF metadata</h3>
<p class="settings-help">Metadata defaults to the visible letterhead where possible. Leave a field empty to inherit; enter a value to override it without changing the printed letterhead.</p>
<div class="grid">
<label class="full">Previous PDF
<input type="file" name="previous_pdf" accept=".pdf,application/pdf">
<small>Optionally reuse metadata from an earlier PDF when neither an override nor a letterhead default supplies the value. Keywords can also be inherited this way.</small>
</label>
<label class="full">PDF title metadata
<input name="title" placeholder="Comment Letter" aria-describedby="metadata-title-hint">
<small id="metadata-title-hint">Inherits the visible document title, then the previous PDF title; otherwise uses the source filename stem. Enter a different title to override.</small>
</label>
<label>Author
<input name="author" placeholder="Organization or author" aria-describedby="metadata-author-hint">
<small id="metadata-author-hint">Inherits the branding wordmark, then the previous PDF author. Enter a different author to override.</small>
</label>
<label>Subject
<input name="subject" placeholder="Document subject or filing description" aria-describedby="metadata-subject-hint">
<small id="metadata-subject-hint">Inherits the visible document title, then the previous PDF subject. Enter a different subject to override.</small>
</label>
<label class="full">Keywords
<input name="keywords" placeholder="securities, transfer agents, comment letter">
<small>Inherits keywords from a previous PDF, if uploaded. Otherwise enter comma-separated keywords here.</small>
</label>
</div>
</section>

</div>
</fieldset>

Expand Down
31 changes: 31 additions & 0 deletions tests/configuration.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,34 @@ console.log('Configuration round-trip, preset overrides, validation, and documen
assert.throws(()=>importConfiguration(fields.form,bad));
assert.deepEqual(exportConfiguration(fields.form),disabled);
}

{
const { inheritedMetadataValues, updateMetadataHints } = require('../static/metadata-inheritance.js');
const fields = new Map(Object.entries({
document_title: { value: 'Comment letter' },
wordmark: { value: 'BlockTransfer' },
title: { value: '', placeholder: 'PDF title', dataset: {} },
author: { value: 'Custom author', placeholder: 'Author', dataset: {} },
subject: { value: '', placeholder: 'Subject', dataset: {} },
}));
const form = { elements: { namedItem: name => fields.get(name) } };
const hints = new Map(['title', 'author', 'subject'].map(name =>
['metadata-' + name + '-hint', { textContent: '' }]));
const root = { getElementById: id => hints.get(id) };
assert.deepEqual(inheritedMetadataValues(form), {
title: 'Comment letter', author: 'BlockTransfer', subject: 'Comment letter',
});
updateMetadataHints(form, root);
assert.equal(fields.get('title').placeholder, 'Comment letter');
assert.equal(fields.get('subject').placeholder, 'Comment letter');
assert.equal(fields.get('author').value, 'Custom author', 'Explicit metadata must remain intact');
fields.get('document_title').value = 'Updated filing';
updateMetadataHints(form, root);
assert.equal(fields.get('title').placeholder, 'Updated filing');
assert.equal(fields.get('title').value, '', 'Inherited placeholders do not become overrides');
fields.get('document_title').value = '';
updateMetadataHints(form, root);
assert.equal(fields.get('title').placeholder, 'PDF title');
assert.match(hints.get('metadata-title-hint').textContent, /previous PDF/);
}
console.log('Letterhead metadata inheritance previews passed.');
20 changes: 20 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ def test_config_controls_and_script_are_served(self):
with app.test_client().get('/static/configuration.js') as script:
self.assertEqual(script.status_code, 200)

def test_metadata_appears_beneath_letterhead_not_as_a_separate_step(self):
response = app.test_client().get('/')
self.assertEqual(response.status_code, 200)
page = response.data.decode('utf-8')
self.assertIn('Step 1 of 10', page)
self.assertNotIn('data-step-title="Output metadata"', page)
self.assertNotIn('>Metadata</button>', page)
letterhead = page.split('data-step-title="Letterhead"', 1)[1].split(
'data-step-title="Running header', 1
)[0]
self.assertLess(letterhead.index('name="document_title"'),
letterhead.index('name="title"'))
self.assertLess(letterhead.index('name="title"'),
letterhead.index('name="keywords"'))
self.assertIn('/static/metadata-inheritance.js', page)
document = page.split('data-step-title="Document"', 1)[1].split(
'data-step-title="Typography"', 1
)[0]
self.assertIn('name="pdf_format"', document)

@unittest.skipUnless(shutil.which('node'), 'Node is required for configuration browser logic tests')
def test_configuration_round_trip_and_validation(self):
result = subprocess.run(
Expand Down
59 changes: 59 additions & 0 deletions tests/test_previous_pdf_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,65 @@ def test_explicit_metadata_overrides_previous_pdf(self):
self.assertEqual(metadata["subject"], "Current Subject")
self.assertEqual(metadata["keywords"], "current")

def test_letterhead_values_inherit_when_metadata_is_blank(self):
response = self.client.post(
"/render",
data={
"markdown": "## Body\n\nText",
"document_title": "Visible Filing Title",
"wordmark": "BlockTransfer",
},
)
self.assertEqual(response.status_code, 200)
with pymupdf.open(stream=response.data, filetype="pdf") as rendered:
metadata = rendered.metadata
self.assertEqual(metadata["title"], "Visible Filing Title")
self.assertEqual(metadata["author"], "BlockTransfer")
self.assertEqual(metadata["subject"], "Visible Filing Title")

def test_explicit_metadata_precedes_letterhead_and_previous_pdf(self):
previous = pdf_with_metadata(
title="Old title", author="Old author", subject="Old subject",
keywords="old keywords",
)
response = self.client.post(
"/render",
data={
"markdown": "## Body\n\nText",
"document_title": "New visible title",
"wordmark": "New wordmark",
"previous_pdf": (BytesIO(previous), "old.pdf"),
"title": "Custom PDF title",
"author": "Custom author",
"subject": "Custom subject",
},
)
self.assertEqual(response.status_code, 200)
with pymupdf.open(stream=response.data, filetype="pdf") as rendered:
metadata = rendered.metadata
self.assertEqual(metadata["title"], "Custom PDF title")
self.assertEqual(metadata["author"], "Custom author")
self.assertEqual(metadata["subject"], "Custom subject")
self.assertEqual(metadata["keywords"], "old keywords")

def test_letterhead_defaults_precede_previous_pdf_metadata(self):
previous = pdf_with_metadata(title="Old title", author="Old author", subject="Old subject")
response = self.client.post(
"/render",
data={
"markdown": "## Body\n\nText",
"document_title": "Current filing",
"wordmark": "Current organization",
"previous_pdf": (BytesIO(previous), "old.pdf"),
},
)
self.assertEqual(response.status_code, 200)
with pymupdf.open(stream=response.data, filetype="pdf") as rendered:
metadata = rendered.metadata
self.assertEqual(metadata["title"], "Current filing")
self.assertEqual(metadata["author"], "Current organization")
self.assertEqual(metadata["subject"], "Current filing")

def test_invalid_previous_pdf_is_rejected(self):
response = self.client.post(
"/render",
Expand Down
Loading