PDFPipe

Getting paid / Refund and credit block

A credit block that cannot be mistaken for an amount owed

The amount being credited or refunded, on a credit note, laid out so nobody reads it as another bill.

Why this block is harder than it looks

A credit note looks exactly like an invoice, is produced by the same code, and carries a large number in the same place. Every failure here is somebody paying a credit note. The layout has to invert the reading: the document must announce that money is going the other way, before the reader recognises the familiar shape and processes it out of habit. Doing that with a minus sign alone does not work, because a minus at nine point in a totals block is not what the eye lands on.

The decisions that make it work

Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.

  • Say credit in words, large, above the figure. A negative sign is a modifier and words are the statement.
  • Do not print a due date, a payment instruction or bank details anywhere on a credit note. Their presence is what triggers the payment.
  • Print the figure as a positive number under a heading that says what it is, rather than as a negative under a heading that says total. Minus five thousand under the word total is read as five thousand.
  • Reference the original invoice on the same line as the amount, since that is how the credit gets matched.
  • Keep the block together with break-inside: avoid, and keep it in the same position an invoice total would occupy, so the difference between the two documents is the words rather than the layout.
  • State how the credit will be applied, against a future invoice or refunded, because the two have different consequences for the recipient.

The fragment

Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.

html
<section class="credit">
  <p class="kind">Credit to your account</p>
  <div class="row">
    <span>Against invoice 2026-118</span>
    <span class="v">620.00</span>
  </div>
  <p class="method">This credit will be applied to your next invoice. No payment
    is due on this document.</p>
</section>

<style>
  .credit {
    break-inside: avoid;
    width: 56%;
    margin-left: auto;
    margin-top: 12pt;
    padding-top: 8pt;
    border-top: 1.5pt solid currentColor;
  }
  .credit .kind {
    margin: 0 0 4pt;
    font-size: 12pt;
    font-weight: 700;                  /* words, before the figure */
  }
  .credit .row {
    display: flex;
    justify-content: space-between;
    gap: 10pt;
    font-size: 13pt;
  }
  .credit .v {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-weight: 700;
  }
  .credit .method { margin: 6pt 0 0; font-size: 8.5pt; color: #444; }
</style>

What breaks when it is built the obvious way

Reusing the invoice template unchanged and negating the total. The document then carries a due date, bank details and a payment instruction alongside a negative number, and a proportion of recipients pay it. Removing the payment furniture matters more than the sign.

How to prove it survived pagination

Show the rendered page for three seconds and ask whether money is owed and by whom. Then search the page for any bank detail, due date or payment instruction: there should be none.

Where it sits in a finished document

This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The credit note template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.

Frequently asked

Will this fragment work on its own?

Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.

Why does it look right in a browser and wrong in the PDF?

Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.

Do I need a special option on the render request for this?

No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.

Other parts of a document

The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.

Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.