PDF title

775 views
Skip to first unread message

Paul Bolger

unread,
Apr 1, 2012, 11:34:12 PM4/1/12
to siwapp...@googlegroups.com
Is there any way of getting Siwapp to write a custom title for
generated PDF's? Mine all come out as "invoice-(number).pdf" which
isn't that convenient.

José de Zárate

unread,
Apr 1, 2012, 11:59:49 PM4/1/12
to siwapp...@googlegroups.com
this is the function where pdf names are created.
it's in apps/siwapp/modules/print/actions/actions.class.php, on line 102

  /**
   * PDF output
   * @param array ids - Object IDs as request parameter
   */
  public function executePdf(sfWebRequest $request)
  {
    $model = $request->getParameter('model');
    switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1:
        $name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }
    try
    {
      $this->render($model, true)->stream("$name.pdf");
      return sfView::NONE;
    }
    catch(LogicException $le)
    {
      throw $le;
      //return $this->renderText($this->templateNotFoundMsg);
    }
    catch(TemplateNotFoundException $tnfe)
    {
      return $this->renderText($this->templateNotFoundMsg);
    }
  }

you can change the value of the "$name" variable just before the call to $this->render($model, true)->stream("$name.pdf");

--
You received this message because you are subscribed to the Google Groups "siwapp-users" group.
To post to this group, send email to siwapp...@googlegroups.com.
To unsubscribe from this group, send email to siwapp-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/siwapp-users?hl=en.




--
uh, oh.



Fons De Vrij

unread,
Apr 27, 2012, 5:39:05 AM4/27/12
to siwapp...@googlegroups.com
Hey JoeZ,

Maybe you can help out with something.

Im trying to achieve the PDF's number the same as the invoice's
For example: the Pre-fix for the invoice numbering is DVG-2012-XXXXX (x= for automatic numbering from siwapp)

Is it possible to get the PDF's numbers the same as the invoice numbers? like this: DVG-2012-xxxxx

I dont know where to look, to chance the numbering.

Thx a lot in advance.

With kind regards,

Fons


Op maandag 2 april 2012 05:59:49 UTC+2 schreef JoeZ het volgende:
To unsubscribe from this group, send email to siwapp-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/siwapp-users?hl=en.




--
uh, oh.



José de Zárate

unread,
Apr 27, 2012, 9:33:43 AM4/27/12
to siwapp...@googlegroups.com
Well, this is a hack I haven't had the chance to test. Just figured it out now that you asked for it. Please MAKE A BACKUP COPY OF YOUR apps/siwapp/modules/print/actions/actions.class.php first

open your apps/siwapp/modules/print/actions/actions.class.php and locate the function "executePdf" on Line 73:

  /**
   * PDF output
   * @param array ids - Object IDs as request parameter
   */
  public function executePdf(sfWebRequest $request)
  {
    $model = $request->getParameter('model');
    switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1:
        $name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }
    try
    {
      $this->render($model, true)->stream("$name.pdf");
      return sfView::NONE;
    }
    catch(LogicException $le)
    {
      throw $le;
      //return $this->renderText($this->templateNotFoundMsg);
    }
    catch(TemplateNotFoundException $tnfe)
    {
      return $this->renderText($this->templateNotFoundMsg);
    }
  }

the line in red is the line that actually renders the pdf. As you can see, there is  a $name variable which is the one that sets the filename. We're going to change that $name variable before it's used in this line. In order to do that, we need to know if we're going to render one or several invoices, and we're going to need the method:


$this->getInvoiceDataFromRequest($request)

that method fetchs all the invoice data. 


just before the red line, there is a switch, in which tells us if we're going to render one or multiple invoices.

 switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1:
        $name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }


as you can see, the "case 1" statement sets the name for the case there's only one invoice, and the "default" statement sets the name for the case when there are several invoices. That is a good place to put our hack:

$invoice_data = $this->getInvoiceDataFromRequest($request); 
switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1:        // only one invoice
        $invoice = $invoice_data[0];
        $name = $invoice;
        //$name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }


if you get it working please post it here so other users can benefit too.
again, I've not tested it, hope it works.



To view this discussion on the web visit https://groups.google.com/d/msg/siwapp-users/-/JqYlWANP1vgJ.

To post to this group, send email to siwapp...@googlegroups.com.
To unsubscribe from this group, send email to siwapp-users...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/siwapp-users?hl=en.



--
uh, oh.



Marcellino Santoso

unread,
Apr 27, 2012, 10:24:34 AM4/27/12
to José de Zárate
Hello José & SIWAPP users,

This trick works. *YAAAAYYY
Here's the bubble burster: at least for me.
Be advised : MAKE BACKUP FIRST! (caps is intentional)


<Friday, April 27, 2012, 8:33:43 PM>
> Well, this is a hack I haven't had the chance to test. Just figured it out now that you
> asked for it. Please MAKE A BACKUP COPY OF YOUR
> apps/siwapp/modules/print/actions/actions.class.php first

> open your apps/siwapp/modules/print/actions/actions.class.php and locate the function "executePdf" on Line 73:

> $invoice_data = $this->getInvoiceDataFromRequest($request); 
> switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
>
>     {
>       case 0:
>         $this->forward404();
>
>         break;
>       case 1:        // only one invoice
>
>         $invoice = $invoice_data[0];
>         $name = $invoice;
>
>         //$name = $model."-{$ids[0]}";
>         break;
>
>       default:
>         $name = "$n-".$model."s";
>
>         break;
>     }

> if you get it working please post it here so other users can benefit too.
> again, I've not tested it, hope it works.


Best regards,
Marcellino Santoso
marcellin...@gmail.com

José de Zárate

unread,
Apr 27, 2012, 10:28:27 AM4/27/12
to siwapp...@googlegroups.com
great!

2012/4/27 Marcellino Santoso <marcellin...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "siwapp-users" group.
To post to this group, send email to siwapp...@googlegroups.com.
To unsubscribe from this group, send email to siwapp-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/siwapp-users?hl=en.




--
uh, oh.



jorisx

unread,
Jun 2, 2012, 1:47:01 PM6/2/12
to siwapp...@googlegroups.com
Works great!! for one pdf. 

:-)
great!

2012/4/27 Marcellino Santoso <marcellin...@gmail.com>
To unsubscribe from this group, send email to siwapp-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/siwapp-users?hl=en.




--
uh, oh.



jorisx

unread,
Jun 2, 2012, 2:09:20 PM6/2/12
to siwapp...@googlegroups.com
Ok works nice for downloading, but where do I change/hack some to have the title on the pdf when sending the pdf by email? 
Thanks for the help :) 

J!

José de Zárate

unread,
Jun 2, 2012, 2:51:39 PM6/2/12
to siwapp...@googlegroups.com
go to lib/EmailMessages.php, find this piece of code, and apply the red modifications

   try
    {
      $body = $printer->render($data);
      $pdf = $printer->renderPdf($data)->output();
      $attachment = new Swift_Attachment(
                            $pdf,
                           // $model.'-'.$invoice->getId().'.pdf',
                            $invoice,
                            'application/pdf'
                            );
      $this
        ->setSubject(PropertyTable::get('company_name').' ['.$model.': '.$invoice.']')
        ->setBody($printer->render($data), 'text/html')
        ->attach($attachment);
      $this->setReadyState(true);
      
    }
warning. I'm guessing the "$invoice" object will automatically output its string representation (which is the series and the number of the invoice) when called as a string. In case it doesn't work, you can put there whatever var you want.
--
uh, oh.



jorisx

unread,
Jun 2, 2012, 3:30:13 PM6/2/12
to siwapp...@googlegroups.com
Thanx for the quick reply! 
Works Great ! just had to add the .'.pdf',

//$model.'-'.$invoice->getId().'.pdf',
$invoice.'.pdf',

:-) 


uh, oh.



jorisx

unread,
Dec 13, 2012, 1:50:20 PM12/13/12
to siwapp...@googlegroups.com
Ah just got it, 
to change the pdf names a need to change them on 2 places (one for the mail out to customer and one for the direct download via siwapp)

Change name of pdf for customer email here; 
/siwapp_files/lib/EmailMessages.php
changed line 98
      $attachment = new Swift_Attachment(
                            $pdf,
                            //$model.'-'.$invoice->getId().'.pdf',
                            //$invoice.'.pdf',  // just the number
                            $invoice.'-'.$invoice['customer_name'].'.pdf',
                            'application/pdf'
                            );

Change name of pdf in donwload via siwapp, here: 
/siwapp_files/apps/siwapp/modules/print/actions/actions.class.php
changed line 100
      case 1: // only one invoice
        $invoice = $invoice_data[0];
        $name = $invoice.'-'.$invoice['customer_name'];



Love the customization  :) 
joris

nitras

unread,
Feb 27, 2013, 6:46:15 PM2/27/13
to siwapp...@googlegroups.com
Hello again :)

I stumbled upon this topic, but it does not really help me out.

Maybe someone can help me out? 
I filled in the label in 'invoicing series" also the initial value

so my invoice is called right now "mycompany-180" It looks good on the invoice. However I want this to be identical to my filename.
How to fix this please? The methods presented above does not work for me :/

Thanks kindly

Op maandag 2 april 2012 05:34:12 UTC+2 schreef pbolger het volgende:

jorisx

unread,
Jan 26, 2016, 12:49:48 AM1/26/16
to siwapp-users
Hi Nitras,

I changed the following 2 files so that the file name is :  [invoicenumber]-[clientname].pdf
(this only works for one invoice:)

/siwapp_files/lib/EmailMessages.php
/siwapp_files/apps/siwapp/modules/print/actions/actions.class.php
 

/siwapp_files/lib/EmailMessages.php
Change in line 82, change:      
     $name = $model."-{$ids[0]}";
to:
     $invoice = $invoice_data[0];
     $name = $invoice.'-'.$invoice['customer_name'];
     //$name = $model."-{$ids[0]}";



/siwapp_files/apps/siwapp/modules/print/actions/actions.class.php
Change from line 75
  public function executePdf(sfWebRequest $request)
  {

/*  original */
/*
    $model = $request->getParameter('model');
    switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1:
        $name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }
*/
    $model = $request->getParameter('model');
    $invoice_data = $this->getInvoiceDataFromRequest($request); 
    switch($n = count($ids = (array) $this->getRequestParameter('ids', array())))
    {
      case 0:
        $this->forward404();
        break;
      case 1: // only one invoice
        $invoice = $invoice_data[0];
        $name = $invoice.'-'.$invoice['customer_name'];
        //$name = $model."-{$ids[0]}";
        break;
      default:
        $name = "$n-".$model."s";
        break;
    }


Reply all
Reply to author
Forward
0 new messages