Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Separation colors #1322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
143 changes: 143 additions & 0 deletions apps/deno/tests/test12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,154 @@ const thirdPage = async (pdfDoc: PDFDocument, assets: Assets) => {
});
};

const fourthPage = async (pdfDoc: PDFDocument) => {
const page = pdfDoc.addPage();

const pdfSeparation = await pdfDoc.embedSeparation(
'PANTONE 123 C',
cmyk(0, 0.22, 0.83, 0),
);

const color = page.getSeparationColor(pdfSeparation, 0.5);
const borderColor = page.getSeparationColor(pdfSeparation, 1);

page.drawRectangle({
x: inchToPt(0),
y: inchToPt(0),
width: inchToPt(8.5),
height: inchToPt(12),
color: cmyk(0, 0, 0, 1),
});

page.drawText('This text will be printed using a spot color', {
x: inchToPt(0.5),
y: inchToPt(11),
size: 16,
color,
});

// No overprint

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(12),
color,
borderColor,
borderWidth: 2,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(8),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(9),
color,
borderColor,
borderWidth: 2,
});

// Overprint

page.drawText('This text will be printed over the existing background', {
x: inchToPt(0.5),
y: inchToPt(7),
color,
size: 16,
overprint: true,
});

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(8),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(4),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(5),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

// Overprint only for strokes

page.drawText(
'Only the filling will be overprinted on the following shapes',
{
x: inchToPt(0.5),
y: inchToPt(3),
color,
size: 16,
overprint: true,
},
);

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(4),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(0),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(1),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});
};

export default async (assets: Assets) => {
const pdfDoc = await PDFDocument.create();
await firstPage(pdfDoc);
await secondPage(pdfDoc);
await thirdPage(pdfDoc, assets);
await fourthPage(pdfDoc);

const pdfBytes = await pdfDoc.save();
return pdfBytes;
Expand Down
143 changes: 143 additions & 0 deletions apps/node/tests/test12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,154 @@ const thirdPage = async (pdfDoc: PDFDocument, assets: Assets) => {
});
};

const fourthPage = async (pdfDoc: PDFDocument) => {
const page = pdfDoc.addPage();

const pdfSeparation = await pdfDoc.embedSeparation(
'PANTONE 123 C',
cmyk(0, 0.22, 0.83, 0),
);

const color = page.getSeparationColor(pdfSeparation, 0.5);
const borderColor = page.getSeparationColor(pdfSeparation, 1);

page.drawRectangle({
x: inchToPt(0),
y: inchToPt(0),
width: inchToPt(8.5),
height: inchToPt(12),
color: cmyk(0, 0, 0, 1),
});

page.drawText('This text will be printed using a spot color', {
x: inchToPt(0.5),
y: inchToPt(11),
size: 16,
color,
});

// No overprint

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(12),
color,
borderColor,
borderWidth: 2,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(8),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(9),
color,
borderColor,
borderWidth: 2,
});

// Overprint

page.drawText('This text will be printed over the existing background', {
x: inchToPt(0.5),
y: inchToPt(7),
color,
size: 16,
overprint: true,
});

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(8),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(4),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(5),
color,
borderColor,
borderWidth: 2,
overprint: true,
});

// Overprint only for strokes

page.drawText(
'Only the filling will be overprinted on the following shapes',
{
x: inchToPt(0.5),
y: inchToPt(3),
color,
size: 16,
overprint: true,
},
);

page.drawSvgPath('M 100 100 L 300 100 L 200 300 z', {
x: inchToPt(-1),
y: inchToPt(4),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});

page.drawRectangle({
x: inchToPt(2),
y: inchToPt(0),
width: 60,
height: 160,
rotate: degrees(-30),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});

page.drawCircle({
x: inchToPt(5),
y: inchToPt(1),
color,
borderColor,
borderWidth: 2,
overprint: false,
nonStrokingOverprint: true,
});
};

export default async (assets: Assets) => {
const pdfDoc = await PDFDocument.create();
await firstPage(pdfDoc);
await secondPage(pdfDoc);
await thirdPage(pdfDoc, assets);
await fourthPage(pdfDoc);

const pdfBytes = await pdfDoc.save();
return pdfBytes;
Expand Down
Loading