PHP code example of xorgxx / neox-pdf-bundle

1. Go to this page and download the library: Download xorgxx/neox-pdf-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xorgxx / neox-pdf-bundle example snippets


  ....
  ###> NeoxToPdf ###
    PDFLAYER_DSN=pdflayer://opps:[api-key]@api.pdflayer.com/api/convert
  ###> NeoxToPdf ###
  ....

  neox_to_pdf:
      directory_save: "/public/neoxPdf/"
      services:
          pdfLayer: "%env(PDFLAYER_DSN)%"

  
  
  namespace App\Controller\Admin;
  
  use NeoxToPdf\NeoxToPdfBundle\NeoxPdf\NeoxToPdfFactory;
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Attribute\Route;
  use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  
  #[Route('/neox-to-pd')]
  class NeoxToPdfController extends AbstractController
  {
      /**
       * @throws TransportExceptionInterface
       */
      #[Route('/', name: 'app_neox_to_pdf')]
      public function index( NeoxToPdfFactory $neoxToPdf): Response
      {
          return $neoxToPdf->pdfLayerService()
              ->setParams('document_html',"Neox Wooooonnnn convert to pdf")
              ->setParams('test',true)
              ->convert()
              ->display_pdf();
              
          // Advance** (read Bellow) section ADVANCE
          $pdf = $neoxToPdf->customService("pdfLayerA")
              ->setPostData('document_html',"Neox Wooooonnnn convert to pdf") // in body
              ->setQuery('test',true) // in url
              ->convert()
              ->display_pdf();
      }
  }
 
  neox_to_pdf:
      ...
      # path to class customs
      directory_class: "App/Services"
      # Important | [pdfLayerAService] name have to be same "format" as the class name without "Service" ex: pdfLayerA not PdfLayera
      customs:
          pdfLayerA: "%env(PDFLAYERA_DSN)%"
    ...

 
    ###> NeoxToPdf ###
      ...
      PDFLAYERA_DSN=pdflayera://opps:[api-key]@api.pdflayer.com/api/convert
      ...
    ###> NeoxToPdf ###
 

    
    namespace App\Services;
    
    use NeoxToPdf\NeoxToPdfBundle\NeoxPdf\neoxPdfInterface;
    use NeoxToPdf\NeoxToPdfBundle\NeoxPdf\NeoxToPdfAbstract;
    use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
    use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
    use Symfony\Contracts\HttpClient\HttpClientInterface;
    
    class pdfLayerAService extends NeoxToPdfAbstract implements neoxPdfInterface
    {
        public readonly HttpClientInterface $httpClient;
        
        /**
         * method:  class construction
         * You can do your logic here!!.
         *
         * @param bool $redirect
         *
         * @return mixed
         * @throws TransportExceptionInterface
         */
        public function htmlConverter(bool $redirect = false): mixed
        {
            ...
            $request        = $this->buildRequest();
            ...
            $t = $this->sendRequest($request, $postData);
            
            return $this;
        }
        
        // Process to convert any (support) to pdf
        public function anyConverter(): mixed
        {
            // TODO: Implement anyConverter() method. Woooooooonnnn !
        }
        
        public function buildRequest(): string
        {
            return $this->build_request();
        }
        
        /**
         * @throws TransportExceptionInterface
         */
        public function sendRequest(string $request, array $postData): string
        {
            return $this->doApi($request, $postData);
        }
    }
    
    // This class have to extends NeoxToPdfAbstract and implements neoxPdfInterface
    // $this->buildRequest() will construct base on Dsn request API
    // $this->sendRequest($request, $postData) will send Api request : Note that this have to return string !!