@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
/** Valid original bytes for QA only; never an official/legal document. */
|
||||
final class SyntheticDocument
|
||||
{
|
||||
public static function pdf(string $text = 'Synthetic QA document - no official or legal value'): string
|
||||
{
|
||||
$text = str_replace(['\\', '(', ')'], ['\\\\', '\\(', '\\)'], $text);
|
||||
$stream = 'BT /F1 12 Tf 12 60 Td ('.$text.') Tj ET';
|
||||
$objects = [
|
||||
'<< /Type /Catalog /Pages 2 0 R >>',
|
||||
'<< /Type /Pages /Kids [3 0 R] /Count 1 >>',
|
||||
'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 600 100] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>',
|
||||
'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>',
|
||||
'<< /Length '.strlen($stream)." >>\nstream\n".$stream."\nendstream",
|
||||
];
|
||||
$pdf = "%PDF-1.4\n% Synthetic QA original\n";
|
||||
$offsets = [];
|
||||
foreach ($objects as $index => $object) {
|
||||
$offsets[] = strlen($pdf);
|
||||
$pdf .= ($index + 1)." 0 obj\n".$object."\nendobj\n";
|
||||
}
|
||||
$xref = strlen($pdf);
|
||||
$pdf .= "xref\n0 6\n0000000000 65535 f \n";
|
||||
foreach ($offsets as $offset) {
|
||||
$pdf .= sprintf('%010d 00000 n ', $offset)."\n";
|
||||
}
|
||||
|
||||
return $pdf."trailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n".$xref."\n%%EOF\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user