There are many libraries to create pdf files with php : fpdf, tcpdf, domPdf, ...
There is also a php extension PDFlib, but it's not free.
My quetion is how to create a simple pdf file using only native php ?
There are many libraries to create pdf files with php : fpdf, tcpdf, domPdf, ...
There is also a php extension PDFlib, but it's not free.
My quetion is how to create a simple pdf file using only native php ?
I provided a link to how a PDF might be build from scratch using basic text structures as discussed in https://stackoverflow.com/a/68442444/10802527 however like in the discussion for another limited Arduino solution https://stackoverflow.com/a/68876321/10802527 the topic usually leads to how to handle images.
I am going to suggest the simplest of all 3rd party library methods that works across platforms is Artifex Mutool so to build a simple page via scripting we simply need to use text building blocks like this.
%%MediaBox 0 0 595 842
%%Font Helv Helvetica Latin
%%Image Flowers1 C:/Users/name/Documents/WelcomeScan.jpg
% Draw an image. x width, H line elevation (y skew), x skew, y height, left offset, bottom offset, units are pt.'s cm is not centimetres
q 512 0.0 0.0 384 41.5 400 cm /Flowers1 Do Q
% Draw a rectangle. move line fill
q 1 0.5 1 rg 41.5 370 m 553.5 370 l 553.5 270 l 41.5 270 l f Q
% Show some text.
q 0 0 1 rg
BT /Helv 24 Tf 210 330 Td (Hello, Flowers!) Tj ET
BT /Helv 24 Tf 100 290 Td (Microsoft Windows Welcome Scan) Tj ET
Q
This was the code to produce
mutool create -o "output.pdf" -O ascii "Page1.txt" ["page2.txt" ...]