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

Feature/custom font #417

Closed
wants to merge 7 commits into from
Closed

Conversation

skch-17
Copy link

@skch-17 skch-17 commented Oct 3, 2023

@schoero Morning
As we currently have the requirement to create PDF/A-2b, we need to adjust the font for the QR-Bill so that we are able to embed it into the pdf. As 'Helvetica' is a .afm font in PDFKit it is not embeddable. That's why we use now Liberation-Sans as it is compatible with the Swiss-QR-Standards and free of charge.

I opened a pull request so that you see the changes I made. As my fork is in quite strange state, so that we can work you probably must decline the pull or remove the change to the addPath.

@schoero schoero mentioned this pull request Oct 28, 2023
29 tasks
@schoero
Copy link
Owner

schoero commented Nov 10, 2023

Thank you for the contribution. I have released you changes with SwissQRBill v4.0.0.

Keep in mind, that the font has to be registered before using. You can now change the font like this:

const data = {
  amount: 1994.75,
  creditor: {
    account: "CH44 3199 9123 0008 8901 2",
    address: "Musterstrasse",
    buildingNumber: 7,
    city: "Musterstadt",
    country: "CH",
    name: "SwissQRBill",
    zip: 1234
  },
  currency: "CHF",
  debtor: {
    address: "Musterstrasse",
    buildingNumber: 1,
    city: "Musterstadt",
    country: "CH",
    name: "Peter Muster",
    zip: 1234
  },
  reference: "21 00000 00003 13947 14300 09017"
};

const stream = createWriteStream("different-font.pdf");

const pdf = new PDFDocument({ autoFirstPage: false });

// Register the font
pdf.registerFont("Liberation-Sans", "path/to/LiberationSans-Regular.ttf");
pdf.registerFont("Liberation-Sans-Bold", "path/to/LiberationSans-Bold.ttf");

const qrBill = new SwissQRBill(data, { fontName: "Liberation-Sans" });

qrBill.attachTo(pdf);

pdf.pipe(stream);
pdf.end();

@schoero schoero closed this Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants