There is a need to generate certificates for users, they will be sent to them by mail after a certain procedure. Certificates in the sense of a file with a username and some text, then to be able to view or print it and hang it on the wall.

Easier: the administrator downloads a pdf template file with the text you need, for example, replace Ivan% Ivanovich Ivanovich% Username% . The script passes, and changes the required values.

  • Can. But for this you need to parse pdf at the beginning. Which is not the ideal format for this, replace placeholders and generate a new pdf. Possible loss and distortion in the final file. Depends on the complexity of the source file. Look in the direction of the libraries for this pdfparser, htmltopdf, mpdf or if it is possible to implement this via COM OpenOffice - Ninazu
  • The matter was complicated by the fact that in those pdf a lot of fonts and unsuited objects are used, even Illustrator could not parse it, what to say about the rest. I think to come from the other end, in connection with this question: is it possible to put a block with text in a certain place and of a certain size on top of a pdf? - Andrew
  • Save as a picture and overlay the coordinates already. In general, it will be best to make a certificate editor on the site and not bind to third-party files - Ninazu
  • The image will be quite large as the certificate files must be provided for printing, therefore the pdf format is preferred. The certificate editor is great, but two words interfere with implementation: budget and deadline, so you need to generate files using the loaded templates. I asked the question below, is it possible to overlay the original pdf (without touching its structure in order not to break) to add certain text blocks in certain coordinates? - Andrew
  • “Without touching” this is most likely not ((But you can add a layer as it is possible github.com/Distrotech/PDFlib-Lite/blob/master/bind/pdflib/php/… - Ninazu

1 answer 1

Perhaps in your case it will be more convenient to create a pdf template of the document using php, generate it on the server.

You can use the FPDF library.

Official documentation

Its functionality should be enough to create a fairly complex template, an example of how its code looks like:

require('fpdf.php'); class PDF extends FPDF { function Header() { $this->Image('logo.png',10,8,33); $this->SetFont('Helvetica','B',15); $this->SetXY(50, 10); $this->Cell(0,10,'This is a header',1,0,'C'); } function Footer() { $this->SetXY(100,-15); $this->SetFont('Helvetica','I',10); $this->Write (5, 'This is a footer'); } } $pdf=new PDF(); $pdf->AddPage(); $pdf->Output('example2.pdf','D'); 

PDFLib is also there - but it is paid.

Here is an example of code that allows you to put a picture on the background and impose the desired inscription:

 $name = "Vasilyy Popov"; $pdf =""; $pdf=new FPDF('P', 'pt', array(<PageHeight>, <PageWidth>)); $pdf->AddPage(); $pdf->Image('background-image.jpg', 0, 0, <ImageHeight>, <ImageWidth>); $pdf->SetFont('Arial', 'B', 23); $pdf->Text(<TextPositionFromLeft>, <TextPositionFromTop>, $name); $pdf->Output('pdfSert.pdf','D'); 
  • Please try to publish detailed answers containing a specific example of the minimum solution, supplementing them with a link to the source. Answers –references (like comments) do not add knowledge to Runet. - Nicolas Chabanovsky ♦
  • @NicolasChabanovsky thanks, edited the answer. More in this case will not work) - Vlad
  • The problem is that you need the ability to download different certificate templates, that is, the design changes constantly and for each case. Is there a possibility in FPDF to load a ready-made template like, so to say, a background in which empty spaces are provided, for example, and to put text blocks on top with the same tools? That is, we work with the original templates simply as with a substrate, and put text blocks on top? - Andrew
  • @AndrewVieru Yes, this option is suitable, I checked - the answer was edited with a piece of code that suits you. All that in the <> replace the desired value. - Vlad
  • In the proposed version of yours, it turns out that everything will be rasterized in the background, if this is the only way to add text to a pdf layout, does the pdf format value decrease to zero, in which case, it might be easier to use the GD and jpeg background? Examples of certificates can be viewed at the link above in the comments. - Andrew