باختصار
شهادات دورة لورشة طباعة، صفحة لكل طالب، بإطار مزخرف وختم. يكفي أن تكتب اسم الطالب مرة واحدة لتحصل على شهادة كاملة.
ما الذي ستنضده
شهادات إتمام دورة لورشة Quoin Room، وهي ورشة طباعة بالحروف البارزة متخيَّلة في بروفيدنس: صفحة واحدة بمقاس US Letter لكل طالب. وتنضّدها الطبعة الإسبانية دبلومات بمقاس A4 لورشة La Cuña في سرقسطة. يؤطّر الورقةَ شريطٌ أزرق مخضرّ مملوء بعدسات غيوشيه كريمية، وفي كل ركن وردة كريمية؛ وكلاهما مرسوم بالشيفرة من منحنيات جيبية ومنحنيات هيبوتروكويد. وتحت عنوان بحروف كبيرة متباعدة يُنضَّد اسم الطالب بخط Pinyon Script بحجم 48 نقطة فوق خط ذهبي، ويُوسَّط نص الشهادة بخط Rosarivo. ويقع ختم أحمر بذيلين من الشريط بين خطّي التوقيع، وتحته سطر واحد ببيانات الطبع. ولأن نمط عنوان واحدًا يرسم الصفحة كلها، فكل طالب عنوان Markdown واحد، ويضم ملف PDF الصف كله بإشارة مرجعية لكل اسم.
تجيب هذه الوصفة عن
- كيف أضيف علامة مائية أو لونًا خفيفًا للخلفية أو صورة زخرفية في كل صفحة؟
- كيف أنضد رسومًا غير مرقّمة: زخارف، وحليات، وشعارات؟
- كيف أثبّت شارة أو ملصقًا في موضع ثابت من الصفحة؟
- كيف أصدّر ملف PDF حقيقيًّا في المتصفح مع تضمين الخطوط؟
الجواب المختصر
const certificate = () => ({ // a function: it uses the elements defined below
id: 'certificate',
// Section geometry, for this style's pages only: a narrower measure, and a text area that
// ends at the seal, so a citation too long for the page moves on instead of running under it.
margins: { left: mm(SIDE), right: mm(SIDE), bottom: mm(H - SIGN) },
// Header and footer elements paint over the page and reserve nothing (gotcha:
// header-paints-over-text), so the frame, the seal and the signatures go there. In the
// opener the signature lines would count towards its height (gotcha:
// opener-reserves-anchored), and a design that reaches below the text area takes the page.
header: { elements: [frame, serial] },
footer: { elements: signatures },
// The citation starts 18 lines of the 17 pt grid under the top margin, 140 mm down (19
// lines, 146 mm, on A4): an opener's height rounds up to whole lines, and without
// marginBottom: 0 the level's 0.5 em under a heading would add a line. minHeight is a
// floor: the title block alone would start the citation at 128 mm (134 mm on A4).
advancedDesign: { enabled: true, minHeight: mm(y(106)), slot: { elements: title } },
marginBottom: mm(0),
});
// Hook-up: headingStyles: [certificate()], and in the Markdown one heading per student:
// # Imogen Achterberg {style="certificate" serial="26-031"}
المكونات
- الميزات
- ترويسات لكل قسمالصور في تصاميم الصفحةصفحات افتتاح مصمَّمةتثبيت عناصر التصميمالنصوص والخطوط والمربعات في تصاميم الصفحةأنماط العناوينهندسة القسمسمات العنوانلون الورقلوحة ألوان دلاليةالأشكال والجداول بوصفها مواردالبيانات الوصفية للمستندصفحات على اللوحة (Canvas)التصدير إلى PDFالخطوط المضمَّنة في PDFالعلامات المرجعية في PDF
- الخطوط
- Rosarivo, Pinyon Script, Aboreto (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · دع نمط عنوان واحدًا يرسم الصفحة
النمط نفسه هو الجواب المختصر أعلاه. يتحكم نمط العنوان في صفحات قسمه (أنماط العناوين): يحلّ header وfooter فيه محلّ ترويسة المستند وتذييله، وهما فارغان هنا، وتحدد margins منطقة النص، ويرسم advancedDesign صفحة الافتتاح. يُقرَّب ارتفاع صفحة الافتتاح إلى أعلى ليساوي عددًا صحيحًا من أسطر شبكة المتن ذات 17 نقطة. فيصير minHeight البالغ 106 مم ثمانية عشر سطرًا، ويبدأ نص الشهادة على بعد 140 مم من الحافة العليا؛ وعلى A4 يجعله y() يساوي 112.7 مم، أي 19 سطرًا، فيبدأ النص عند 146 مم. ولو كانت كتلة العنوان وحدها لبدأ النص عند 128 مم (134 مم على A4). وبدون marginBottom: 0 كانت مسافة 0.5 em الافتراضية تحت العنوان ستدفع الـ106 مم نفسها إلى 19 سطرًا.
#2 · علّق الإطار على الصفحة من الترويسة
const frame = { kind: 'image', id: 'frame', resourceId: 'guilloche',
placement: { anchor: { to: 'page', edge: 'top-left' }, // the trim box
size: { width: 'fill', height: 'fill' } } }; // the SVG has the page's proportions
const serial = { kind: 'text', id: 'serial', ...caps, fontSize: pt(8.5), letterSpacing: pt(1.6),
content: t({ en: 'No. {attr.serial}', es: 'N.º {attr.serial}' }), // from the heading line
color: col('seal'), align: 'right', placement: at('top-right', -MARGIN, 29) };
const PX = 10; // declared pixels per mm: an SVG resource only needs the right proportions
const svg = (id, w, h, altText) => ({ id, typeId: 'figure', kind: 'svg', createdAt: 0,
updatedAt: 0, altText, svg: { fileId: `${id}.svg`, width: w * PX, height: h * PX } });
const resources = [
svg('guilloche', W, H, t({ en: 'A teal guilloche border with cream rosettes at the corners.',
es: 'Una orla de guilloché verde azulado con rosetas color crema en las esquinas.' })),
svg('seal', SEAL.w, SEAL.h, t({ en: 'A red seal with a serrated edge and two ribbon tails.',
es: 'Un sello rojo de borde dentado con dos cintas.' })),
];
يرسم عنصر الصورة موردًا بحجم موضعه (عناصر الصور): حين يُربط بالركن الأيسر العلوي للصفحة ويكون جانباه كلاهما 'fill'، يغطي الغيوشيه مستطيل القصّ، ويملؤه ملف SVG المعلَن بنسب الصفحة دون أن يتمدد. ترسمه الترويسة فوق page.backgroundColor دون أن تحجز له مساحة، فتكفي الهوامش وحدها لإبقاء النص على بعد 32 مم على الأقل من حدّ القص، داخل الخط الداخلي الواقع عند 26 مم. ولو وُضعت علامة مائية في الترويسة لطُبعت فوق الكلمات، لأن الترويسة تُرسم بعد النص. وفي الترويسة يقرأ {attr.serial} سمة العنوان الذي تنتمي الصفحة إلى قسمه، فتطبع كل شهادة رقمها الخاص.
#3 · أبقِ كتلة العنوان وحدها في صفحة الافتتاح
const centred = (top) => at('top', 0, y(top)); // tracked or not, the letters are centred
const title = [
{ kind: 'text', id: 'kicker', ...caps, fontSize: pt(9.5), letterSpacing: pt(2.4),
content: '{attr.workshop}', placement: centred(39) }, // the wording: see merge
{ kind: 'text', id: 'title', content: t({ en: 'Certificate', es: 'Diploma' }), ...caps,
fontSize: pt(46), lineHeight: 1, letterSpacing: pt(3), placement: centred(48) },
{ kind: 'text', id: 'of', content: t({ en: 'of completion', es: 'de aprovechamiento' }),
...caps, fontSize: pt(11), letterSpacing: pt(4), placement: centred(68) },
{ kind: 'text', id: 'lead', content: '{attr.lead}',
fontFamily: 'Rosarivo', italic: true, fontSize: pt(13), color: col('muted'),
placement: centred(90) },
{ kind: 'text', id: 'name', content: '{titleText}', fontFamily: 'Pinyon Script',
fontSize: pt(48), lineHeight: 1.25, // 60 pt from line to line of a long name
color: col('ink'), align: 'center', overflow: 'wrap', // a long name takes a second line
placement: { ...centred(97), size: { width: mm(W - 2 * MARGIN) } } },
{ kind: 'rule', id: 'underline', direction: 'horizontal', thickness: pt(0.75),
color: col('gold'), placement: { anchor: { to: '#name', edge: 'below' },
offset: { x: mm(18), y: mm(5) }, size: { width: mm(W - 2 * MARGIN - 36) } } },
];
كل سطر مربوط بالحافة 'top' للصفحة، وهذا يوسّطه، مع قيمة y مقيسة من حدّ القص، فتحفظ الكتلة مكانها مهما كانت الهوامش؛ ويمدّ y() هذه المواضع من Letter إلى A4. والاسم هو نص العنوان نفسه، مقروءًا عبر {titleText}، فيظهر في الإشارات المرجعية ووسوم PDF. ويأخذ الاسم الطويل سطرًا ثانيًا، لأن تصميم العنوان يلفّ نصه (overflow: 'wrap'). ولا تحتاج الأسطر المتباعدة الحروف إلى تصحيح: تباعد الحروف بعد الحرف الأخير لا يدخل في القياس، فالحروف نفسها هي التي تتوسّط.
#4 · علّق الختم والتوقيعات من حافة واحدة
// mm: each signature line stops 3 mm short of the seal (56 on Letter, 53 on A4)
const LINE = (W - 2 * MARGIN - 2 * SEAL.r) / 2 - 3;
const under = (id, gap, x = 0) => ({ anchor: { to: `#${id}`, edge: 'below' },
offset: { x: mm(x), y: mm(gap) }, size: { width: mm(LINE) } });
const signatures = [
{ kind: 'image', id: 'seal', resourceId: 'seal',
placement: { ...at('top', 0, SIGN), size: { width: mm(SEAL.w) } } },
...[1, 2].flatMap((n, i) => [ // signer1 and role1, signer2 and role2: the wording again
{ kind: 'rule', id: `line${i}`, direction: 'horizontal', thickness: pt(0.6), color: col('rule'),
placement: { ...at('top-left', i ? W - MARGIN - LINE : MARGIN, SIGN + 23),
size: { width: mm(LINE) } } },
{ kind: 'text', id: `who${i}`, content: `{attr.signer${n}}`, fontFamily: 'Rosarivo',
fontSize: pt(10.5), color: col('ink'), align: 'center', placement: under(`line${i}`, 1.6) },
{ kind: 'text', id: `role${i}`, content: `{attr.role${n}}`, ...caps, fontSize: pt(7.5),
letterSpacing: pt(1.4), color: col('muted'), align: 'center',
placement: under(`who${i}`, 0.6) },
]),
{ kind: 'text', id: 'imprint', fontFamily: 'Rosarivo', italic: true, fontSize: pt(7),
content: '{attr.imprint}', color: col('muted'), placement: at('top', 0, SIGN + 50) },
];
كل ما في التذييل مقيس من SIGN، الحافة العليا للختم، وينهي الهامش السفلي للنمط منطقة النص عند الحافة نفسها، فإذا طال نص شهادة عن الصفحة انتقل إلى الصفحة التالية بدل أن يمتد تحت الختم. ولو نُقلت الخطوط والأسماء إلى صفحة الافتتاح لحُسبت ضمن ارتفاعها (الامتداد والتصميم المتقدم)؛ ولأنها تنزل تحت منطقة النص، كانت صفحة الافتتاح ستأخذ الصفحة كلها وتدفع النص إلى الصفحة التالية. يأخذ LINE العرض بين هوامش الصفحة، ويطرح منه قرص الختم البالغ 34 مم، ويقسم الباقي على اثنين وينقص منه 3 مم، فيتوقف كل خط قبل الختم بـ3 مم في المقاسين كليهما (طوله 56 مم على Letter و53 مم على A4). وكل اسم ووظيفة عنصر نصي بعرض خطّه، فيتوسّط تحته.
#5 · ادمج قائمة الصف في عناوين
// Name and serial: {titleText} and {attr.serial} in the designs (gotcha: attr-values). The
// lines every certificate shares are the front matter of content.<lang>.md, written onto each
// heading as attributes too: {attr.workshop}, {attr.lead}, the signers and the imprint.
const { metadata: wording, content: citation } = extractFrontmatter(markdown);
const shared = Object.entries(wording).map(([key, value]) => `${key}="${value}"`).join(' ');
const heading = (name, serial) => `# ${name} {style="certificate" serial="${serial}" ${shared}}`;
const CLASS = t({
en: [['Imogen Achterberg', '26-031'], ['Tomás Okafor', '26-032'], ['Ruth Adair', '26-033']],
es: [['Lucía Beltrán Ochoa', '26-017'], ['Íñigo Sarasola', '26-018'], ['Ana Rius', '26-019']],
});
const merged = CLASS.map(([name, serial]) => `${heading(name, serial)}\n\n${citation}`)
.join('\n\n');
const metadata = { // the PDF's title and author
title: t({ en: 'Certificates of completion, fall 2026',
es: 'Diplomas del curso de otoño de 2026' }),
author: t({ en: 'The Quoin Room', es: 'La Cuña' }) };
يصير كل صف عنوان # يحدّد النمط وفيه الرقم التسلسلي سمةً (سمات العناوين)، ويليه النص المأخوذ من content.en.md، فتُنتج ثلاثة صفوف ثلاث صفحات. ويبدأ breakBefore في المستوى 1 مع الزوجية 'any' كل عنوان على صفحة جديدة دون صفحة بيضاء بين الشهادات؛ ويرثه النمط.
#6 · ابنِ ملف PDF واحدًا للصف كله
offerPdf(() => renderToPdf(doc, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
`${RECIPE}.pdf`); // bookmarks: one per heading, so one per student
document.querySelector('[data-postext-pdf]').textContent = t({ en: 'Class list → one PDF',
es: 'Toda la clase en un PDF' });
الصف مستند واحد، فيكتب renderToPdf ملفًا واحدًا من ثلاث صفحات بإشارة مرجعية لكل عنوان، وكل إشارة باسم طالب. ويقبل renderToPdf أيضًا مصفوفة من المستندات، كفصول كتاب، لكن مستندًا لكل طالب يعني استدعاءً لـbuildDocument لكل واحد. أما بالعناوين فيُخرج الصف كله في بناء واحد، ويعرض المستعرض الشهادات الثلاث من ذلك البناء. ويضمّن ملف PDF أشكال الخط الأربعة التي تطبعها الصفحات، ويجلبها مزوّد الخطوط في العُدّة من Fontsource (لماذا مزوّد خطوط؟).
الوصفة كاملة
// ═══ Postext Cookbook · Nº 063 · Certificate with a guilloche border ═══════════════
// https://postext.dev/en/cookbook/certificate-single-page
// Code: MIT · Text: original (CC BY 4.0) · Guilloche and seal: generated in code (CC BY 4.0)
// Fonts: Rosarivo, Pinyon Script, Aboreto (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// End-of-course certificates, one page per student, drawn by one heading style, in one PDF.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, extractFrontmatter,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'certificate-single-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1f2a2e', // text and the student's name
teal: '#1f5f5b', // the frame, the title lines
gold: '#b08d57', // hairlines and the rule under the name; never text (2.9:1 on paper)
seal: '#8d2c2c', // the seal and the serial number
rule: '#8f8878', // signature lines
muted: '#6d6a60', // the lead-in, the signatories' roles, the imprint
paper: '#fbf8ef', // the sheet
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [W, H] = t({ en: [215.9, 279.4], es: [210, 297] }); // US Letter; A4 for the Spanish diploma
const MARGIN = 32; // mm on every side, inside the frame's inner rule (26 mm in)
const SIDE = 50; // mm: the certificate's side margins, a 116 mm measure (110 on A4)
// Positions are drawn on US Letter and stretched to A4: y(90) is 90 mm down on Letter.
const y = (mm) => (mm * H) / 279.4;
const SIGN = y(194); // mm from the top: the seal's top edge, where the text area ends
const SEAL = { w: 40, h: 45, r: 17 }; // mm: the seal with its ribbon tails, and its disc's radius
const at = (edge, x, top) => ({ anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(top) } });
const caps = { fontFamily: 'Aboreto', textTransform: 'uppercase', color: col('teal') };
// #region answer: one heading style draws the whole certificate
const certificate = () => ({ // a function: it uses the elements defined below
id: 'certificate',
// Section geometry, for this style's pages only: a narrower measure, and a text area that
// ends at the seal, so a citation too long for the page moves on instead of running under it.
margins: { left: mm(SIDE), right: mm(SIDE), bottom: mm(H - SIGN) },
// Header and footer elements paint over the page and reserve nothing (gotcha:
// header-paints-over-text), so the frame, the seal and the signatures go there. In the
// opener the signature lines would count towards its height (gotcha:
// opener-reserves-anchored), and a design that reaches below the text area takes the page.
header: { elements: [frame, serial] },
footer: { elements: signatures },
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#اطبع ملف PDF لكل طالب
زرّ لكل طالب يبني شهادته مستندًا قائمًا بذاته، بـbuildDocumentWithFonts كما في بناء المثال نفسه، ويسمّي الملف برقمه التسلسلي؛ ويزن كل ملف نحو 245 كيلوبايت.
-offerPdf(() => renderToPdf(doc, { fontProvider: fontsourceProvider, resourceBytes: imageBytes }),
- `${RECIPE}.pdf`); // bookmarks: one per heading, so one per student
-document.querySelector('[data-postext-pdf]').textContent = t({ en: 'Class list → one PDF',
- es: 'Toda la clase en un PDF' });
+for (const [name, serial] of CLASS) {
+ const one = `${heading(name, serial)}\n\n${citation}`;
+ offerPdf(async () => renderToPdf(await buildDocumentWithFonts({ markdown: one, metadata,
+ resources }, config(), kitFonts(FONTS)), { fontProvider: fontsourceProvider,
+ resourceBytes: imageBytes }), `${serial}.pdf`);
+ document.querySelector(`[data-postext-pdf="${serial}.pdf"]`).textContent = name;
+}#اطبع الإطار والعنوان بالأزرق الكحلي
يقرأ رسم SVG والإعدادات الكائن palette نفسه، فتغيير مدخل واحد يعيد تلوين الشريط وزخارف الوردات وأسطر العنوان.
- teal: '#1f5f5b', // the frame, the title lines
+ teal: '#2b3a67', // the frame, the title linesأخطاء شائعة
خطأ شائع
تحجز الافتتاحية ارتفاعًا يصل إلى أدنى عناصرها المثبّتة على الصفحة
تحجز الافتتاحية ذات التصميم المتقدّم ارتفاع أدنى عناصرها، وتُحتسب كذلك العناصر المثبّتة على الصفحة أو على النزف تحت العنوان، فالزخرفة في أسفل الصفحة تدفع النص إلى الصفحة التالية. أعطِ مثل هذا العنصر reserve: false (منذ postext 1.5): يُرسَم حيث ثُبّت ولا يحجز شيئًا. أما العناصر التي تتبع الشريط نفسه (المثبّتة على أسفله، أو التي ارتفاعها 'fill') فلا تحدّد ارتفاعه أبدًا. صفحات افتتاح مصمَّمة →
خطأ شائع
عناصر الترويسة والتذييل تُرسَم فوق النص
تُرسَم عناصر الترويسة والتذييل فوق الصفحة، ولا تُفسح منطقة النص لها مكانًا. أبقِها داخل الهوامش، فالهوامش هي التي تحجز مساحتها. الترويسات وأرقام الصفحات →
خطأ شائع
قيم السمات: لا { ولا }؛ ضع القيمة التي فيها " بين علامتي اقتباس مفردتين
تنتهي قيمة السمة عند القوس المعقوف الختامي، فلا يمكن أن تحتوي { أو }. القيمة التي فيها علامة اقتباس مزدوجة توضع بين علامتي اقتباس مفردتين؛ أما علامة الدولار فلا مشكلة فيها. سمات العنوان →
خطأ شائع
لا <marker> ولا مرشِّحات في رسوم SVG (وإلا البديل النقطي)
لا يبقى شكل SVG متّجهيًا في PDF إلا إذا خلا من <marker> والمرشِّحات والأقنعة؛ وإلا عاد إلى صورة نقطية، والمرشِّحات المتداخلة بعمق قد تجعله فارغًا في Chrome. ارسم رؤوس الأسهم مسارات. الأشكال والجداول بوصفها موارد →
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- نص أصلي, CC BY 4.0
- الخطوط
- Rosarivo (SIL OFL 1.1) · Pinyon Script (SIL OFL 1.1) · Aboreto (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


