Files
patrickandClaude Sonnet 5 75fdf9fb83
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
INT-06: scanner-anbindung über hot-folder
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-20 19:47:41 +02:00

37 lines
1.3 KiB
Go

package testcorpus
import (
"bytes"
"fmt"
)
// GenerateStack baut ein Mehrseiten-PDF, dessen Seite i den Text pageTexts[i] traegt.
func GenerateStack(pageTexts []string) []byte {
n := len(pageTexts)
var buf bytes.Buffer
var offsets []int
obj := func(s string) {
offsets = append(offsets, buf.Len())
buf.WriteString(s)
}
buf.WriteString("%PDF-1.4\n")
obj("1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n")
kids := ""
for i := 0; i < n; i++ {
kids += fmt.Sprintf("%d 0 R ", 3+2*i)
}
obj(fmt.Sprintf("2 0 obj<</Type/Pages/Kids[%s]/Count %d>>endobj\n", kids, n))
for i, text := range pageTexts {
obj(fmt.Sprintf("%d 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 300 300]/Resources<</Font<</F1<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>>>>>/Contents %d 0 R>>endobj\n", 3+2*i, 4+2*i))
content := fmt.Sprintf("BT /F1 12 Tf 20 150 Td (%s) Tj ET", escapePDFString(text))
obj(fmt.Sprintf("%d 0 obj<</Length %d>>stream\n%s\nendstream endobj\n", 4+2*i, len(content), content))
}
xref := buf.Len()
fmt.Fprintf(&buf, "xref\n0 %d\n0000000000 65535 f \n", len(offsets)+1)
for _, o := range offsets {
fmt.Fprintf(&buf, "%010d 00000 n \n", o)
}
fmt.Fprintf(&buf, "trailer<</Size %d/Root 1 0 R>>\nstartxref\n%d\n%%%%EOF\n", len(offsets)+1, xref)
return buf.Bytes()
}