A warehouse operator has already picked the order and confirmed its contents. When they click Export PDF, the application has the order number, the customer’s display name and every line item. A local render lets the Node process use those values directly and return a packing slip in the same request.
Build the slip where the order lives
The TypeScript SDK’s builders describe the document. In a Linux Node
application with the SDK and matching renderer installed,
renderLocal starts the native binary for one export and
resolves with PDF bytes. The Node examples run locally. Python, Go
and PHP generate the same slip through the HTTP service. Choose JSON
to see the exact request body for POST /v1/generate.
import { writeFile } from "node:fs/promises";
import { document, page, text } from "pressjet";
import { renderLocal } from "pressjet/local";
const order = { id: "0041", items: ["4 proof sets", "1 cover sheet"] };
const slip = document({ title: "Packing slip " + order.id },
page({ size: "A4", style: { padding: 40 } },
text({ style: { fontSize: 22 } }, "Packing slip " + order.id),
...order.items.map(item => text({}, item))
)
);
const bytes = await renderLocal(slip);
await writeFile("packing-slip.pdf", bytes);
import { writeFile } from "node:fs/promises";
import { document, page, text } from "pressjet";
import { renderLocal } from "pressjet/local";
const order: { id: string; items: string[] } = { id: "0041", items: ["4 proof sets", "1 cover sheet"] };
const slip = document({ title: "Packing slip " + order.id },
page({ size: "A4", style: { padding: 40 } },
text({ style: { fontSize: 22 } }, "Packing slip " + order.id),
...order.items.map(item => text({}, item))
)
);
const bytes = await renderLocal(slip);
await writeFile("packing-slip.pdf", bytes);
from os import environ
from pathlib import Path
import pressjet
order_id, items = "0041", ["4 proof sets", "1 cover sheet"]
title = f"Packing slip {order_id}"
slip = pressjet.document(
pressjet.page(
pressjet.text(title, style={"fontSize": 22}),
*(pressjet.text(item) for item in items),
size="A4",
style={"padding": 40},
),
title=title,
)
with pressjet.Client(api_key=environ["PRESSJET_API_KEY"], base_url="http://localhost:8080") as client:
Path("packing-slip.pdf").write_bytes(client.generate(slip))
package main
import (
"context"
"os"
pressjet "github.com/tonysantana1492/pressjet/sdks/go"
)
func must[T any](value T, err error) T {
if err != nil {
panic(err)
}
return value
}
func main() {
ctx := context.Background()
client := pressjet.NewClient()
title := "Packing slip 0041"
lines := []any{pressjet.Text(
pressjet.TextProps{Style: &pressjet.Style{FontSize: pressjet.Pt(22)}},
title,
)}
for _, item := range []string{"4 proof sets", "1 cover sheet"} {
lines = append(lines, pressjet.Text(pressjet.TextProps{}, item))
}
slip := pressjet.Document(pressjet.DocumentProps{Title: title},
pressjet.Page(pressjet.PageProps{
Size: pressjet.A4,
Style: &pressjet.Style{Padding: pressjet.Pt(40)},
}, lines...),
)
pdf := must(client.Generate(ctx, slip))
if err := os.WriteFile("packing-slip.pdf", pdf, 0644); err != nil {
panic(err)
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use Pressjet\Client;
use function Pressjet\{document, page, text};
$client = new Client(
apiKey: getenv('PRESSJET_API_KEY'),
baseUrl: 'http://localhost:8080',
);
$title = 'Packing slip 0041';
$items = ['4 proof sets', '1 cover sheet'];
$slip = document(['title' => $title], page(
['size' => 'A4', 'style' => ['padding' => 40]],
text(['style' => ['fontSize' => 22]], $title),
...array_map(fn(string $item) => text([], $item), $items),
));
file_put_contents('packing-slip.pdf', $client->generate($slip));
{
"version": 1,
"layout": {
"type": "document",
"properties": {
"title": "Packing slip 0041"
},
"children": [
{
"type": "page",
"properties": {
"size": "A4",
"style": {
"padding": 40
}
},
"children": [
{
"type": "text",
"properties": {
"style": {
"fontSize": 22
}
},
"children": [
"Packing slip 0041"
]
},
{
"type": "text",
"properties": {},
"children": [
"4 proof sets"
]
},
{
"type": "text",
"properties": {},
"children": [
"1 cover sheet"
]
}
]
}
]
}
}
Wire the result to the download action
In the existing authenticated order route, load the authorized
order, build the same tree and set the response content type to
application/pdf. A
Content-Disposition attachment filename based on the
internal order ID lets the operator recognize it in Downloads.
Return the bytes only after rendering succeeds, so an invalid layout
produces an application error instead of a partial PDF.
Test the packaged app on its target architecture. A tagged SDK
release can select an optional native package for Linux x64 or
ARM64. A source build can point PRESSJET_BINARY at the
matching executable. Keep the optional package when bundling, and
embed any PNG or JPEG bytes in the document. To cancel abandoned
work, pass the request’s abort signal to renderLocal.
For an acceptance test, open the resulting slip and check that “0041” keeps its leading zeros and both items appear in source order. Repeat with an order long enough to span several pages. That second fixture tests the behavior the short example can’t show.