Post by antijoe » Sun Dec 06, 2009 5:47 pm

I'm working on some code to put a unique watermark on the bottom each page of every downloaded PDF, e.g. firstname, lastname, email.

That part I can do. What I can't figure out is how to get the user's name etc. from the database within the file /catalog/model/account/download.php

Seriously, I'm stumped. My mind has turned to mush.

If anyone could point me in the right direction, or throw me a snippet of code, I'd be ever so grateful. Then maybe I can upload my contribution!

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by nicudica » Mon Dec 07, 2009 4:06 pm

Hi, antijoe

I' think this idea its no so good, but anyway if this its very important for you, I' post an small exaple of using dompdf watermark

Code: Select all

<html>
<head>
<style type="text/css">
.main {
        width: 16cm;
        height: 28cm;
        margin: 0.2in auto;
        background-image: url(http://your_domain/images/
watermark.png);
        background-position: 50% 50%;
        background-repeat: no-repeat;
}

</style>
</head>
<body>
<div class="main">
Lorem ipsum dolor.
</div>
</body>
</html> 
The easy way its to make an footer for each page and writ down you advertising text.

Regards,
Nicu

User avatar
Active Member

Posts

Joined
Wed Nov 11, 2009 9:20 pm
Location - Bucharest / Romania

Post by antijoe » Mon Dec 07, 2009 7:12 pm

Sorry, my intention was not entirely clear!

If you are selling e-books you want some way of reducing the chance of copies being redistributed by marking them with a unique watermark or footer.

Because the original PDF is not generated on the fly I have used FPDF_PDFI to add a footer to each page. As the file is downloaded the footer is applied. That part is complete. I'm not familiar with the CVM method used by opencart so I'm having difficulty pulling out the correct details of the user who is downloading the file.

I suppose I only really need the firstname, lastname and email of the customer.

Any ideas anyone?

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by antijoe » Mon Dec 07, 2009 10:52 pm

In the hope that sharing may encourage some sharing... this is what I've come up with so far...

Grab http://chir.ag/projects/pdfb/pdfb_demo_compact.zip
and copy the fpdf_fpdi folder into
/catalog/controller/account/fpdf_fpdi

Thne change /public_html/testbed/catalog/controller/account/download.php to the file below...

Code: Select all

<?php		

  $path = $_ENV["DOCUMENT_ROOT"] . '/catalog/controller/account/fpdf_fpdi/font';
  set_include_path(get_include_path() . PATH_SEPARATOR . $path);
  $path = $_ENV["DOCUMENT_ROOT"] . '/catalog/controller/account/fpdf_fpdi';
  set_include_path(get_include_path() . PATH_SEPARATOR . $path);
  require('fpdf_fpdi/fpdi.php');
  
  class PDF extends FPDI
  {
    function Header()
    {
      //$this->Text(35, 35, "This could be a name and MD5 hash in the header!");
    }

    function Footer()
    {
      $this->Text(35, 800, "This could be a name and MD5 hash in the footer!");
    }

  } 
   
class ControllerAccountDownload extends Controller {
	public function getCustomer($customer_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
		
		return $query->row;
	}

	public function index() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->https('account/download');

			$this->redirect($this->url->https('account/login'));
		}
         		
		$this->language->load('account/download');

		$this->document->title = $this->language->get('heading_title');

      	$this->document->breadcrumbs = array();

      	$this->document->breadcrumbs[] = array(
        	'href'      => $this->url->http('common/home'),
        	'text'      => $this->language->get('text_home'),
        	'separator' => FALSE
      	); 

      	$this->document->breadcrumbs[] = array(
        	'href'      => $this->url->http('account/account'),
        	'text'      => $this->language->get('text_account'),
        	'separator' => $this->language->get('text_separator')
      	);
		
      	$this->document->breadcrumbs[] = array(
        	'href'      => $this->url->http('account/download'),
        	'text'      => $this->language->get('text_downloads'),
        	'separator' => $this->language->get('text_separator')
      	);
				
		$this->load->model('account/download');

		$download_total = $this->model_account_download->getTotalDownloads();
		
		if ($download_total) {
			$this->data['heading_title'] = $this->language->get('heading_title');

			$this->data['text_order'] = $this->language->get('text_order');
			$this->data['text_date_added'] = $this->language->get('text_date_added');
			$this->data['text_name'] = $this->language->get('text_name');
			$this->data['text_remaining'] = $this->language->get('text_remaining');
			$this->data['text_size'] = $this->language->get('text_size');
			$this->data['text_download'] = $this->language->get('text_download');
			
			$this->data['button_continue'] = $this->language->get('button_continue');

			if (isset($this->request->get['page'])) {
				$page = $this->request->get['page'];
			} else {
				$page = 1;
			}			
	
			$this->data['downloads'] = array();
			
			$results = $this->model_account_download->getDownloads(($page - 1) * 10, 10);
			
			foreach ($results as $result) {
				if (file_exists(DIR_DOWNLOAD . $result['filename'])) {
					$size = filesize(DIR_DOWNLOAD . $result['filename']);

					$i = 0;

					$suffix = array(
						'B',
						'KB',
						'MB',
						'GB',
						'TB',
						'PB',
						'EB',
						'ZB',
						'YB'
					);

					while (($size / 1024) > 1) {
						$size = $size / 1024;
						$i++;
					}

					$this->data['downloads'][] = array(
						'order_id'   => $result['order_id'],
						'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
						'name'       => $result['name'],
						'remaining'  => $result['remaining'],
						'size'       => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
						'href'       => $this->url->https('account/download/download&order_download_id=' . $result['order_download_id'])
					);
				}
			}
		
			$pagination = new Pagination();
			$pagination->total = $download_total;
			$pagination->page = $page;
			$pagination->limit = 10; 
			$pagination->text = $this->language->get('text_pagination');
			$pagination->url = $this->url->http('account/download&page=%s');
			
			$this->data['pagination'] = $pagination->render();
			
			$this->data['continue'] = $this->url->https('account/account');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/download.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/account/download.tpl';
			} else {
				$this->template = 'default/template/account/download.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',
				'common/column_right'
			);
		
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));				
		} else {
			$this->data['heading_title'] = $this->language->get('heading_title');

			$this->data['text_error'] = $this->language->get('text_error');

			$this->data['button_continue'] = $this->language->get('button_continue');

			$this->data['continue'] = $this->url->https('account/account');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',
				'common/column_right'
			);
		
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
		}
	}


	public function download() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->https('account/download');

			$this->redirect($this->url->https('account/login'));
		}

		$this->load->model('account/download');
		
		if (isset($this->request->get['order_download_id'])) {
			$order_download_id = $this->request->get['order_download_id'];
		} else {
			$order_download_id = 0;
		}
		
		$download_info = $this->model_account_download->getDownload($order_download_id);
	
		if ($download_info) {
			$file = DIR_DOWNLOAD . $download_info['filename'];
			$mask = basename($download_info['mask']);
			$mime = 'application/octet-stream';
			$encoding = 'binary';

// is the mask .pdf ? if so, process it here!
			if (strtolower(substr($mask, -3)) == "pdf") {
 
				$pdf = new PDF("p", "pt", "A4");
 				$pdf->SetAuthor("Someone");
  				$pdf->SetTitle("Something");
  				$pdf->SetFont("times", "", 10);
  				$pdf->SetTextColor(255,0,0);
  				$pagecount = $pdf->setSourceFile($file);
  				for($i=1;$i<=$pagecount;$i++)
  				{
					$tplidx = $pdf->importPage($i);
					$pdf->AddPage();
					$pdf->useTemplate($tplidx);  
  				}
				$tmpfname = tempnam("/tmp", "PDF");
				$pdf->Output($tmpfname, 'F');
				$pdf->closeParsers();
			 



			if (!headers_sent()) {
				header('Pragma: public');
				header('Expires: 0');
				header('Content-Description: File Transfer');
				header('Content-Type: ' . $mime);
				header('Content-Transfer-Encoding: ' . $encoding);
				header('Content-Disposition: attachment; filename=' . ($mask ? $mask : basename($tmpfname)));
				header('Content-Length: ' . filesize($tmpfname));
			
				if (file_exists($tmpfname)) {

						$file = readfile($tmpfname, 'rb');
						print($file);
						unlink($tmpfname);
  
					} else {
						exit('Error: Could not find file ' . $file . '!');
					}
				} else {
					exit('Error: Headers already sent out!');
				}
			} else {
			
				if (!headers_sent()) {
				header('Pragma: public');
				header('Expires: 0');
				header('Content-Description: File Transfer');
				header('Content-Type: ' . $mime);
				header('Content-Transfer-Encoding: ' . $encoding);
				header('Content-Disposition: attachment; filename=' . ($mask ? $mask : basename($file)));
				header('Content-Length: ' . filesize($tmpfname));
			
				if (file_exists($tmpfname)) {

						$file = readfile($file, 'rb');
						print($file);
					} else {
						exit('Error: Could not find file ' . $file . '!');
					}
				} else {
					exit('Error: Headers already sent out!');
				}
			
			}
			
			$this->model_account_download->updateRemaining($this->request->get['order_download_id']);
		} else {
			$this->redirect($this->url->https('account/download'));
		}
	}
}
?>
Should all go to plan your PDFs will now be stamped with the message "This could be a name and MD5 hash in the footer!"

Of course this would be better if it was say, the user's name and email address. The SQL is a little beyond me. Anyone care to suggest a fix? ;D

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by The Alchemist » Tue Dec 08, 2009 2:46 pm

What did you do to get your system to upload PDF files. I am trying to upload PDF files to the download section and it wont allow me to do pdf files.

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by antijoe » Tue Dec 08, 2009 4:59 pm

In the administration pages choose the "Catalog" tab, then choose "Download". Add your files here.

Then in your products add the files that are now listed under the "Data" tab.

Easy! :-)

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by The Alchemist » Wed Dec 09, 2009 1:02 am

Right

I keep getting error when I do a PDF file there.

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by antijoe » Fri Dec 11, 2009 6:00 pm

Check the directory permissions of the /download directory are 755

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by antijoe » Sun Dec 27, 2009 5:00 pm

A mod has been made and duly uploaded. Enjoy peeps!

PDF Watermark mod

Special shout-out to nicudica who helped me make this mod happen. He rocks, go hire him to do stuff for you! ;D

User avatar
Newbie

Posts

Joined
Sun Dec 06, 2009 5:35 pm

Post by nicudica » Sun Dec 27, 2009 6:06 pm

Hi antijoe,

Thank you for the credits and also for a very good collaboration.
Regards and wish to all an Happy New Year.

User avatar
Active Member

Posts

Joined
Wed Nov 11, 2009 9:20 pm
Location - Bucharest / Romania

Post by The Alchemist » Wed Dec 30, 2009 4:01 pm

antijoe wrote:Check the directory permissions of the /download directory are 755
Im sorry but excuse my ignorance, but who is that done?

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by nicudica » Wed Dec 30, 2009 4:06 pm

Hi,
Let say me and antijoe.. Why?

User avatar
Active Member

Posts

Joined
Wed Nov 11, 2009 9:20 pm
Location - Bucharest / Romania

Post by kksoft » Mon Jan 04, 2010 1:00 am

I have installed this mod and many other before it, but I am getting an error on the PDF download attempt. Dumb question... the PDF that I uploaded is password protected so it cannot be modified other than print and view. My guess is that this PDF stamping mod must "open" the PDF in order to stamp it, yes??

If yes, then the PDF is left vulnerable to modification because then there is not security. The end-user simply opens the stamped PDF in Adobe Pro and "loses" the headers and footers. Am I wrong or is the error I get unrelated to a "secure" PDF.
Thanks

Newbie

Posts

Joined
Wed Dec 30, 2009 5:42 am

Post by nicudica » Mon Jan 04, 2010 4:42 pm

Hi,

Yeah, it is not test it such of situations.

User avatar
Active Member

Posts

Joined
Wed Nov 11, 2009 9:20 pm
Location - Bucharest / Romania

Post by The Alchemist » Tue Jan 05, 2010 1:05 am

kksoft wrote:I have installed this mod and many other before it, but I am getting an error on the PDF download attempt. Dumb question... the PDF that I uploaded is password protected so it cannot be modified other than print and view. My guess is that this PDF stamping mod must "open" the PDF in order to stamp it, yes??

If yes, then the PDF is left vulnerable to modification because then there is not security. The end-user simply opens the stamped PDF in Adobe Pro and "loses" the headers and footers. Am I wrong or is the error I get unrelated to a "secure" PDF.
Thanks

That is the same issue I am having now. Im trying to figure out how to crack the passwords or open it with another program

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by The Alchemist » Tue Jan 05, 2010 1:14 pm

I found this program to unlock PDF files.http://www.ehow.com/how_4735211_unlock- ... ndows.html

Im waiting to see if this fixes my upload issues.

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by nicudica » Tue Jan 05, 2010 8:35 pm

Hi,
This its something else ..
If you want to do this on the fly.. hm.. must think and also work :)

The easy way: 1 unlock your file -> upload into o.cart -> download :)

Regards

So the PDF Protected Documents its out.

Please see:
http://www.opencart.com/index.php?route ... ion_id=477

User avatar
Active Member

Posts

Joined
Wed Nov 11, 2009 9:20 pm
Location - Bucharest / Romania

Post by KennyK » Wed Aug 15, 2012 2:37 am

I am not a coder, but here is my vqmod update for opencart 1.5.3.1
for product http://www.opencart.com/index.php?route ... search=pdf

Hope it helps

Newbie

Posts

Joined
Fri Jul 27, 2012 5:36 am

Post by ryancalderon » Wed Oct 24, 2012 9:10 am

Doesn't work on 1.5.3.1 for me any help please.. thanks

Newbie

Posts

Joined
Wed Oct 24, 2012 9:08 am

Post by ryancalderon » Mon Nov 05, 2012 1:02 pm

got it works.. thanks KennyG

Newbie

Posts

Joined
Wed Oct 24, 2012 9:08 am
Who is online

Users browsing this forum: No registered users and 32 guests