12 replies [Last post]
nathane's picture
Offline
Joined: 08/12/2010
Juice: 4
Was this information Helpful?

Good day,

We're trying to implement file downloads on our site - we want to sell PDFs. However, we would like to stamp/watermark every pdf with the user's name and order information upon download.

I'm guessing this is possible, but I could not find a mondule that performs this currently. Does anyone know of anything that is in work? The only thing I could find was PDF Stamper: http://drupal.org/project/pdfstamper - but this stamps incomming fils and it is NOT what we are looking for.

And IF nothing is out there or in work - can anyone offer any sage advice on how big of a project this would be to enable this?

Admin for Untold the Game!

s2
s2's picture
Offline
Joined: 08/11/2010
Juice: 11
Re: PDF Watermark

I would start by looking at what the pdfstamper project is doing. You want to do the same thing, just at a different point in the process. I am still learning about the ubercart api, but I assume that there is a hook you could use to call code that stamps the pdf before making it available for download. I think the hard work is done, it is just a matter of wrapping up in a package for use in ubercart.

betauli's picture
Offline
Joined: 11/18/2010
Juice: 24
Re: PDF Watermark

hi nathane and s2, I also have the same need to stamp downloadable file from Ubercart products. I suggest we make a team to build a module to have this done. I think modifying pdfstamper to fill our need is a good start.

I have identify some obstacles:
1. file download is not a node, hence not a Product. it is an attribute to a Product node. A module ussually deal with node, not attribute.
2. stamping or watermarking is processed when drupal (uc_file_download) making link. So, hook implementation is rather difficult without modifying the uc_file_download.
3. how to place an exact coordinate to various dimension of pdf files.

laho's picture
Offline
Joined: 04/18/2011
Juice: 8
Re: Re: PDF Watermark

Has anyone made any progress with this?

I am very crappy with php and yet unfamiliar with drupal/ubercart modifying, and have not succeeded in my attempts to
create dynamic stamping (timestamp, username, email for example) to downloadable products.

I would need to get the product-pdf to be stamped when downloaded and stamped again always when user redownloads the same product.

Any suggestions?

laho's picture
Offline
Joined: 04/18/2011
Juice: 8
progress

I'll updata myself.

I managed to get drupal save a watermarked pdf file with customer's info to the server, but how could I get download links
and email's point to that user-specific file?

bjornarneson's picture
Offline
Joined: 09/27/2011
Juice: 19
Subscribing

I have this need too -- to watermark a PDF with the purchaser's name, date, and other tokens from the Ubercart order. Anyone figured this out yet? If not, let's work together to make this possible!

bjornarneson's picture
Offline
Joined: 09/27/2011
Juice: 19
First Draft

OK--here is a first draft of a module that will watermark or stamp outgoing file downloads. This module as written below will place a red "sample text" along the left margin of a PDF document. Here is what I still need:

1. I want to mark the PDF download with tokens from the order: name, quantity, date, etc.
2. Would like eventually to expose some configurable options in the Drupal/Ubercart interface, though this not an immediate priority for me.

Who can help me sort out #1 above?

<?php
// uc_pdf_watermark.module
//
// This module expects these pdf libraries in
// the module directory
require_once('fpdf/fpdf.php');
require_once(
'fpdi/fpdi.php');

// FPDF Addon: ROTATIONS
// from http://fpdf.org/en/script/script2.php
require('rotation.php');

// Extend the FPDF classes to rotate text
// Needed in order to place text along spine of PDF documents
class PDF extends PDF_Rotate {
  function
RotatedText($x,$y,$txt,$angle) {
   
//Text rotated around its origin
   
$this->Rotate($angle,$x,$y);
   
$this->Text($x,$y,$txt);
   
$this->Rotate(0);
  }
  function
RotatedImage($file,$x,$y,$w,$h,$angle) {
   
//Image rotated around its upper-left corner
   
$this->Rotate($angle,$x,$y);
   
$this->Image($file,$x,$y,$w,$h);
   
$this->Rotate(0);
  }
}

function

uc_pdf_watermark_file_transfer_alter($file_user, $ip, $fid, $file) {
   
// initiate FPDI with standard U.S. dimensions
   
$pdf = new PDF('P','in','Letter');
   
// add a page
   
$pdf->AddPage();
   
// set the sourcefile from the Ubercart un-marked file
   
$pdf->setSourceFile($file);
   
// import page 1
   
$tplIdx = $pdf->importPage(1);
   
// use the imported page at full resolution
   
$pdf->useTemplate($tplIdx);
    
   
// now write some text on the imported page
   
$pdf->SetFont('Arial','I','8');
       
// red text
   
$pdf->SetTextColor(255,0,0);
   
// place some rotated text just inside the left edge of the page
       
$pdf->RotatedText(0.35,6,'sample text',90);
   
//$pdf->Output('newpdf.pdf', 'D');
   
    // put the watermarked file in the tmp directory and make
    // it available for download by the buyer
   
$file_stamped = tempnam(file_directory_temp(),'tmp');
   
file_put_contents($file_stamped, $pdf->Output());
    return
$file_stamped;
}
?>
betauli's picture
Offline
Joined: 11/18/2010
Juice: 24
PDF Marker project initiated

Hi all, I have made a module that can stamp PDF file attached in a Ubercart Product nodes. You have to activate File Downloads first in your Ubercart suite. It can add username, date/time of download, etc, to a PDF file you want to sell.

Actually, I didn't make it myself. I paid a developer agency to write it for me. The result is functional but only under particular condition (only in a VPS server). Now, I want to modify it to be a high-quality module: can be run in many environments, follow coding standard, add functionalities, and so on.

The module is called PDF Marker. I have uploaded the files to drupal.org but it still considered as a sandbox project. It means that the source can only be accessed through git command from your Linux shell prompt or git client in Windows. I have asked drupal.org to make PDF Marker a full project, so we all can access it through drupal.org/project/pdfmarker link. But now, we can only wait for the review process.

Meanwhile, PDF Marker can be acessed through this URL: http://drupal.org/sandbox/betauli/1328550. You can join me as a committer to the project.

jbenjamin's picture
Offline
Joined: 04/14/2009
Juice: 41
PDF watermark

Hey folks,

I'd like to offer my implementation of a pdf watermark module. I used the foundation supplied by bjornarneson, but have added page iteration, token support (limited), and a configuration page that allows you set the font size, color, rotation, etc. Please keep in mind that this is a first release, so be kind Smiling

thanks!

AttachmentSize
pdf_watermark-6.x-1.0-alpha.tar.gz 4.26 KB
betauli's picture
Offline
Joined: 11/18/2010
Juice: 24
Pdfmarker for VPS

Hi all,

its been a long time since my first visit in this thread.

As said before, I have an implementation to stamp attached pdf files in products node types. It is still in early stage development. Currently, it only works in VPS environment, since the usage of exec() function. Most shared hosting doesn't allow exec(). I don't know about Drupal convention, but I think exec() is not a Drupal way to write code.

I have put the module in Drupal git server: http://drupal.org/sandbox/betauli/1328550. But since you may meet difficulties downloading from it, I attached it in this post as tar.gz archive.

AttachmentSize
pdfmarker.zip 4.02 MB
Hawkcode's picture
Offline
Joined: 06/02/2009
Juice: 50
Hi

We need to get this implemented on our site.

Has there been any movement on this?

I believe you mentioned that you had paid developers to come up with that, is it possible to pass that information on.

gerbreown's picture
Offline
Joined: 03/21/2012
Juice: 5
PDF watermark

I don't know how to do it but I know it can be done because any book I order from PACKTPUB.COM comes with my information on each page.

tohide's picture
Offline
Joined: 06/25/2012
Juice: 3
Drupal 7, Ubercart 3 - PDF Watermarking

Looking to sponsor a project providing PDF watermarking on file downloads from Ubercart asap.

Let me know if anyone interested.