1 (edited by poncho1234 05/07/2019 07:40:02 pm)

Topic: Add stamp or watermark to reports on the fly – ad hoc.

The following modification will improve the paperless office workflow – no more rubber stamps (and add a watermark when you want).

--- reporting\reports_main ORIGINAL.php
+++ reporting\reports_main.php
@@ -110,6 +110,8 @@
             _('To') => 'INVOICE',
             _('Currency Filter') => 'CURRENCY',
             _('email Customers') => 'YES_NO',
+            _('Stamp/Watermark Text') => 'TEXT',
+            _('Stamp/Watermark Colour') => 'COLOR',
             _('Payment Link') => 'PAYMENT_LINK',
             _('Comments') => 'TEXTBOX',
             _('Customer') => 'CUSTOMERS_NO_FILTER',

--- reporting\rep107 ORIGINAL.php
+++ reporting\rep107.php
@@ -58,10 +58,12 @@
     $to = $_POST['PARAM_1'];
     $currency = $_POST['PARAM_2'];
     $email = $_POST['PARAM_3'];
-    $pay_service = $_POST['PARAM_4'];
-    $comments = $_POST['PARAM_5'];
-    $customer = $_POST['PARAM_6'];
-    $orientation = $_POST['PARAM_7'];
+    $watermark_text = $_POST['PARAM_4'];
+    $watermark_color = $_POST['PARAM_5'];
+    $pay_service = $_POST['PARAM_6'];
+    $comments = $_POST['PARAM_7'];
+    $customer = $_POST['PARAM_8'];
+    $orientation = $_POST['PARAM_9'];
 
     if (!$from || !$to) return;
 
@@ -122,6 +124,8 @@
             $rep->SetCommonData($myrow, $branch, $sales_order, $baccount, ST_SALESINVOICE, $contacts);
             $rep->SetHeaderType('Header2');
             $rep->NewPage();
+            if ($watermark_text != '')
+            $rep->Draw_watermark($watermark_text, $watermark_color);
             // calculate summary start row for later use
             $summary_start_row = $rep->bottomMargin + (15 * $rep->lineHeight);

--- reporting\includes\reports_classes ORIGINAL.inc
+++ reporting\includes\reports_classes.inc
@@ -263,6 +263,9 @@
                 case 'TEXT':
                     return "<input type='text' name='$name'>";
 
+                case 'COLOR':
+                    return "<input type='color' name='$name'>";
+
                 case 'TEXTBOX':
                     $value = (isset($_POST[$name]) ? $_POST[$name] : "");
                     return "<textarea rows=4 cols=30 maxlength=130 name='$name'>$value</textarea>";

I added the new function to the report construct so its available for all reports

--- reporting\includes\pdf_report ORIGINAL.inc
+++ reporting\includes\pdf_report.inc
@@ -291,6 +291,25 @@
         $this->footerEnable = $footerenable;
         $this->footerText = $footertext;    
     }
+
+    function Draw_watermark($watermark_text, $watermark_color)
+    {
+        $this->SetX(30);
+        $this->SetY(550);
+        $this->SetFontSize(48);
+        $this->setAlpha(0.5);
+        $this->SetTextColorArray($this->convertHTMLColorToDec($watermark_color));
+        $this->Font('B');
+        $this->StartTransform();
+        $this->Rotate(45);
+        $this->MultiCell(0,10, $watermark_text,0,'C',0,1,0,0);
+        $this->StopTransform();
+        $this->setAlpha(1);
+        $this->SetTextColor(0, 0, 0);
+        $this->SetFontSize(9);
+        $this->Font();
+    }
+
     //
     //    Header for listings
     //

Demo here
username: demo
Password: password


Currently I have only modified rep107.php so go to Sales->Customer and Sales Reports->Print Invoices: Choose a lighter-ish shade as transparency is set to 50%.
All ten document files would need to be changed as well (Paid, Payment Due Immediately, Urgent, etc) as well as all Banking and General Ledger Reports (Confidential, For Your Eyes Only, Projected, etc) Not sure if it would be required on anyother reports?

Notes:

  • I’ve used MultiCell, so long text will wrap and center; function MultiCell states that ‘\n’ can be used to start a new line, whilst this works it still prints the \n! Using report class ‘TEXTBOX’ (and pressing enter for a newline) instead of ‘TEXT’ does work perfectly, but is there a solution to just using ‘TEXT’ with \n? As 'TEXTBOX' takes up so much room on the page and for most cases would not be needed

  • I’ve also hard coded most of the variables, as a) It could possibly over complicate the input and b)There is not that much space left in some of the report options.  I can only think of a popup window to add the rest of the variables: Anyone else have an idea?

Screenshots
Interface

Result

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Add stamp or watermark to reports on the fly – ad hoc.

Can't find any watermark in this report

Post's attachments

FA_Inv_NoWatermark.jpg 28.2 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.
www.boxygen.pk

3 (edited by poncho1234 05/07/2019 02:32:27 am)

Re: Add stamp or watermark to reports on the fly – ad hoc.

@boxygen, ????? Did you write what text you wanted? Choose the text colour?

Doing this

Gives me this

Post's attachments

WatermarkColorOnReports.zip 188.6 kb, 13 downloads since 2019-05-07 

You don't have the permssions to download the attachments of this post.
The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Add stamp or watermark to reports on the fly – ad hoc.

Hmmm. I was trying from Customer Transaction Inquiry. So there shall be an option to Fix the Water Mark in Company Preferences so that even from Customer Transaction Inquiry the WaterMark appears.

www.boxygen.pk

5 (edited by poncho1234 05/07/2019 03:32:02 am)

Re: Add stamp or watermark to reports on the fly – ad hoc.

@boxygen, Customer Transaction Inquiry does not give any of the report options, its not possible to email the report or add a payment link from there either.
Adding option to fix watermark in company options defeats the object of adding a watermark on the fly on an ad hoc basis.

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Add stamp or watermark to reports on the fly – ad hoc.

@joe: want to add it into the core?

Re: Add stamp or watermark to reports on the fly – ad hoc.

Janusz had already made an option for watermark and header includes in the fpdf class inside reporting/includes/class.pdf.inc.

It was a long time ago, but never documented.

I will try to contact him to explain.

/Joe

Re: Add stamp or watermark to reports on the fly – ad hoc.

Does this have anything to do with it's line 213 onwards:

function addText($xb,$yb,$size,$txt)//,$angle=0,$wordSpaceAdjust=0)

Line 4478 of tcpdf.php has watermark as part of unfinished coding:

case 'watermark': {

Image as background in TCPDF

Add Watermark using TCPDF

Post's attachments

TCPDF - Add a watermark.pdf 169.2 kb, 14 downloads since 2019-05-07 

You don't have the permssions to download the attachments of this post.

Re: Add stamp or watermark to reports on the fly – ad hoc.

Yes, indeed, there is possibility to insert watermark, or even whole externally designed blueprint in documents generated in FA.
The blueprint have to be designed as PDF-1.4 file (other pdf formats may also be supported), and you will have to put it  in the /reporting/forms folder.

Out of the box two blueprints are supported for two basic document layouts:
Header2.pdf - for reports 107-113, 209,210 and 409
Header.pdf - for all other documents

If you want to test this feature, just put attached file in the forms folder and generate Sales Invoice. In real design some small changes in repxxx.php files can be necessary.

Of course this feature does not address directly the problem of ad-hoc per document  watermarks, but is ready to use if e.g.  you plan to hire artist to design your  invoices wink.

Janusz

Post's attachments

Header2.pdf 11.1 kb, 27 downloads since 2019-05-07 

You don't have the permssions to download the attachments of this post.

10 (edited by poncho1234 05/07/2019 07:38:37 pm)

Re: Add stamp or watermark to reports on the fly – ad hoc.

I had not realised that TCPDF has its own html to rgb function:-

File: \reporting\includes\tcpdf.php
5671:         function convertHTMLColorToDec($color="#000000") {

I have changed the Draw_watermark function in post #1 above to reflect this and deleted the function html2rgb as it is no longer necessary.

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

11 (edited by poncho1234 05/07/2019 10:48:27 pm)

Re: Add stamp or watermark to reports on the fly – ad hoc.

Would it be better to call the function Draw_watermark within the 3 header functions?

If this is possible; I think it will write the watermark first, then the report text would overwrite and therefore still be legible: and then the two setAlpha lines can be removed from the function. (Light/contrasting colours would have to be selected)
Also possibly the setX & Y could be removed: their settings would be moved to to the last two parameters of  MultiCell. (As it is using these parameters moves the watermark 3/4 of the way across the page; cutting off some of the text)

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Add stamp or watermark to reports on the fly – ad hoc.

@janusz: any improvements to the core with dynamic setting of watermark attributes?

13 (edited by poncho1234 05/08/2019 07:20:23 pm)

Re: Add stamp or watermark to reports on the fly – ad hoc.

@apmuthu, in this post you have shown how header.php & header2.php can be used as alternatives to the .pdf versions @Janusz mentions above.

So a suggested alternative could be:-

create file /reporting/forms/header.php with function Draw_watermark from above (header2.php as well)

create popup window on F2

enter watermark text and colour (The other variables could be included as well) parse to header.php

close popup, choose rest of report options and process report

Would this work?

If it does, then I think the only changes to existing core would be to enable the popup ($popup_editors array, etc.) and additional files header.php, header2.php (does header3.php also work?) and the popup window file.

Also the watermark could be used on all reports(including report exts) as and when required.

Thoughts please

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: Add stamp or watermark to reports on the fly – ad hoc.

This is an excellent feature!  However, could we also add an automatic watermark so that fully paid invoices would be stamped PAID across the top?

Re: Add stamp or watermark to reports on the fly – ad hoc.

The way to do is listed in this post and it is upto the ingenuity of the deployer to do it as they deem fit.

Re: Add stamp or watermark to reports on the fly – ad hoc.

Use this version and you can write what you want on what document you want

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/