Announcement

Collapse
No announcement yet.

PDF Download

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PDF Download

    Hello,

    I have created a custom entity and I have figured out how to get a custom button on the page now, but I would like to create a script to create/download a pdf of some of the content. I am wondering where I can place my php file and what I need to do to honour the authentication so someone with the direct link can't access without being logged in.

    Thanks in advance,
    Stephen

  • #2
    Hi

    See application/Espo/EntryPoints/

    available by url ?entryPoint={entryPointName}

    Comment


    • #3
      Perfect, this is working great! Is this folder safe from updates? Can my custom EntryPoints be placed in the /custom/Espo/Custom/EntryPoints/ folder? Or would it better to create a module?

      Comment


      • #4
        Yep. Putting into custom/Espo/Custom/EntryPoints/ is the best way.

        Comment


        • #5
          I have tried moving my custom entrypoint in this folder and rebuild and cleared cache, but it just returns a 404. Is there something I need to do enable the checking for the custom folder as well? I'm using version 3.4.2.

          Comment


          • #6
            You also should change namespace.

            Comment


            • #7
              Excellent! That did the trick. Still learning, thanks for your help!

              Comment


              • #8
                Hello Stephen! I need to do same possibilities in my little project.

                Can you help me? If you can give me src files or instruction how can i do this at home.

                I really need it, please help!

                Comment


                • #9
                  Hi Stephen, same thing here, I would like to download in pdf some content of records, can you help us please?

                  Comment


                  • #10
                    Create custom/Espo/Custom/EntryPoints/MyPdf.php

                    PHP Code:
                    <?php

                    namespace Espo\Custom\EntryPoints;

                    class 
                    MyPdf extends \Espo\Core\EntryPoints\Base
                    {
                        public static 
                    $authRequired false;

                        public function 
                    run()
                        {
                              
                    here is code run by accessing http://your_espocrm_url?entryPoint=MyPdf
                        
                    }
                    }
                    Clear cache.

                    Comment


                    • #11
                      i create entryPoint like this

                      <?php

                      namespace Espo\Custom\EntryPoints;

                      require "vendor/tecnick.com/tcpdf/tcpdf.php";

                      class MyPdf extends \TCPDF
                      {
                      public static $authRequired = false;

                      public function run()
                      {
                      $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
                      $pdf->setPrintHeader(false);
                      $pdf->setPrintFooter(false);
                      $pdf->SetFont('freeserif', '', 12);
                      $pdf->SetMargins(20, 25, 25);
                      $pdf->SetTextColor(255, 255, 255);
                      $pdf->AddPage();
                      $pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0);
                      $pdf->Output('doc.pdf', 'I');

                      }
                      }


                      and i have this problem:

                      Fatal error: Cannot use object of type Espo\Core\Container as array in /.../vendor/tecnick.com/tcpdf/tcpdf.php on line 2257

                      can you help?

                      Comment


                      • #12
                        Anyone have any idea why i have such Fatal error?

                        or maybe there are other (working) options for generate PDF file from a text field form in EspoCRM?

                        Comment


                        • #13
                          You need to debug it. The error message tells you all you need. Check what TCPDF class receives as a constructor argument. You'd better order some development service.

                          Comment


                          • #14
                            Sorry for the delay, here is slightly stripped down version of my invoice pdf Entrypoint i made
                            Code:
                            <?php
                            namespace Espo\Custom\EntryPoints;
                            
                            use \Espo\Core\Exceptions\NotFound;
                            use \Espo\Core\Exceptions\Forbidden;
                            use \Espo\Core\Exceptions\BadRequest;
                            use \FPDF;
                            
                            class InvoiceDownload extends \Espo\Core\EntryPoints\Base
                            {
                                public static $authRequired = true;
                            
                                public function run()
                                {
                            
                                    $id = $_GET['id'];
                                    if (empty($id)) {
                                        throw new BadRequest();
                                    }
                            
                                    $invoice = $this->getEntityManager()->getEntity('Invoice',$id);
                                    if (!$invoice) {
                                        throw new NotFound();
                                    }
                                    
                                    $previousInvoice = $invoice->get('previousInvoice');
                                    if ($previousInvoice) {
                                        $attachment = $previousInvoice; 
                            
                                        if (!$attachment) {
                                            throw new NotFound();
                                        }
                            
                                        if ($attachment->get('parentId') && $attachment->get('parentType')) {
                                            $parent = $this->getEntityManager()->getEntity($attachment->get('parentType'), $attachment->get('parentId'));
                                            if (!$this->getAcl()->check($parent)) {
                                                throw new Forbidden();
                                            }
                                        }
                            
                                        $fileName = "data/upload/{$attachment->id}";
                            
                                        if (!file_exists($fileName)) {
                                            throw new NotFound();
                                        }
                            
                                        $type = $attachment->get('type');
                            
                                        $disposition = 'attachment';
                                        if (in_array($type, $this->fileTypesToShowInline)) {
                                            $disposition = 'inline';
                                        }
                            
                                        header('Content-Description: File Transfer');
                                        if ($type) {
                                            header('Content-Type: ' . $type);
                                        }
                                        header('Content-Disposition: ' . $disposition . '; filename=' . $attachment->get('name'));
                                        header('Expires: 0');
                                        header('Cache-Control: must-revalidate');
                                        header('Pragma: public');
                                        header('Content-Length: ' . filesize($fileName));
                                        ob_clean();
                                        flush();
                                        readfile($fileName);
                                        exit;
                                    }
                            
                                    
                                    $memberId = $invoice->get('memberId');
                                    
                                    $member = $this->getEntityManager()->getEntity('Member',$memberId);
                                    if (!$member) {
                                        throw new NotFound();
                                    }
                            
                                    $invoiceNumber = $invoice->get('invoiceNumber');
                                    $filename = "invoice-$invoiceNumber.pdf";
                                    $invoiceDate = $invoice->get('invoiceDate');
                                    $paid = $invoice->get('paymentReceived');
                                    $paidDate = $invoice->get('paymentReceivedDate');
                            
                                    $memberName = $member->get('name');
                                    $memberStreet = $member->get('mailingAddressStreet');
                                    $memberCity = $member->get('mailingAddressCity');
                                    $memberProv = $member->get('mailingAddressState');
                                    $memberCountry = $member->get('mailingAddressCountry');
                                    $memberPostal = $member->get('mailingAddressPostalCode');
                                    $memberPhone = $member->get('businessPhone');
                            
                                    $gstExempt = $invoice->get('gSTExempt');
                                    $yearly = $invoice->get('yearlyDues');
                                    $gst = floatval(str_replace(array('$',','),array('',''),$yearly) *0.05);
                                    $total = floatval(str_replace(array('$',','),array('',''),$yearly) *1.05);
                                    setlocale(LC_MONETARY, 'en_US');
                                    $gst = money_format('%(#1.2n', $gst);
                                    $total = money_format('%(#1.2n', $total);
                                    
                                    if ($gstExempt) {
                                        $gst = "0 (Exempt)";
                                        $total = $yearly;
                                    }
                            
                                    require('/public_html/espo/fpdf/fpdf.php');
                                    $pdf = new FPDF(); 
                                    $pdf->AddPage();
                                    $pdf->Image('fpdf/logo.png');
                                    $pdf->SetFont('Arial','','10');
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"Remit to:",0,0,"L");
                                    $pdf->Cell(0,5,"Invoice: ".$invoiceNumber,0,1,"R");
                                    $pdf->Cell(0,5,"",0,0,"L");
                                    $pdf->Cell(0,5,"Date: ".$invoiceDate,0,1,"R");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"Tel: ",0,1,"L");
                                    $pdf->Cell(0,5,"Fax: ",0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"Bill to:",0,1,"L");
                                    $pdf->Cell(0,5,"".$memberName,0,1,"L");
                                    $pdf->Cell(0,5,"".$memberStreet,0,1,"L");
                                    $pdf->Cell(0,5,"".$memberCity.", ".$memberProv,0,1,"L");
                                    $pdf->Cell(0,5,"".$memberCountry,0,1,"L");
                                    $pdf->Cell(0,5,"".$memberPostal,0,1,"L");
                                    $pdf->Cell(0,5,"Tel: ".$memberPhone,0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->Cell(0,5,"Yearly Dues: ".$yearly,0,1,"L");
                                    $pdf->Cell(0,5,"GST: ".$gst,0,1,"L");
                                    $pdf->Cell(0,5,"Total: ".$total,1,1,"L");
                                    if ($paid == 1) {
                                        $pdf->Cell(0,5,"",0,1,"L");
                                        $pdf->Cell(0,5,"Paid: ".$paidDate,1,1,"L");
                                    }
                                    $pdf->Cell(0,5,"",0,1,"L");
                                    $pdf->SetFont('Arial','','12');
                                    $pdf->Cell(0,5,"Please make cheque payable to the \"Company\" and paid in Canadian dollars.",0,1,"C");
                                    $pdf->Output($filename,'D'); //I
                            
                                    exit;
                                }
                            }
                            I'm using FPDF to create the file. Its not pretty but got the job done.

                            Comment


                            • krmn.msg
                              krmn.msg commented
                              Editing a comment
                              Hi!

                              How do you relate these code with a buttom? Where do you place the buttom code? Action?

                              Thanks!

                          • #15

                            Hi,

                            Actually now i am learning EspoCRM.

                            In contact page I add two contact.in contact list page its displayed.

                            The datas coming from EspoCRM\application\Espo\Core\Controllers - Record.php
                            ================================================== ========

                            This is that function

                            public function actionList($params, $data, $request)
                            {
                            if (!$this->getAcl()->check($this->name, 'read')) {
                            throw new Forbidden();
                            }

                            $where = $request->get('where');
                            $offset = $request->get('offset');
                            $maxSize = $request->get('maxSize');
                            $asc = $request->get('asc') === 'true';
                            $sortBy = $request->get('sortBy');
                            $q = $request->get('q');
                            $primaryFilter = $request->get('primaryFilter');
                            $textFilter = $request->get('textFilter');
                            $boolFilterList = $request->get('boolFilterList');

                            if (empty($maxSize)) {
                            $maxSize = self::MAX_SIZE_LIMIT;
                            }
                            if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
                            throw new Forbidden("Max should should not exceed " . self::MAX_SIZE_LIMIT . ". Use pagination (offset, limit).");
                            }

                            $params = array(
                            'where' => $where,
                            'offset' => $offset,
                            'maxSize' => $maxSize,
                            'asc' => $asc,
                            'sortBy' => $sortBy,
                            'q' => $q,
                            'textFilter' => $textFilter
                            );

                            if ($request->get('primaryFilter')) {
                            $params['primaryFilter'] = $request->get('primaryFilter');
                            }
                            if ($request->get('boolFilterList')) {
                            $params['boolFilterList'] = $request->get('boolFilterList');
                            }

                            $result = $this->getRecordService()->findEntities($params);

                            return array(
                            'data' => $data,
                            'params' => $params,
                            'request'=> $request,
                            'data' => $result['data'],
                            'total' => $result['total'],
                            'list' => isset($result['collection']) ? $result['collection']->toArray() : $result['list']
                            );
                            }

                            How i check with echo "<pre>";print_r($_POST);echo "</pre>";

                            I put this pre tag mean it get "Bad Service Response"

                            please check it.

                            Comment

                            Working...
                            X