Watermarking PDFs

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Watermarking PDFs

Brad Lindsay-2
I'm looking to take a PDF that has been stored on my server and personalize it with a watermark before serving it to users. (I'll be using Lasso 9.) Before I start figuring out how to do this, I figured I'd check to see if anyone has done this before, in either 8 or 9? Any pointers would be greatly appreciated.

Thanks,
Brad
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

Ke Carlton-3
A guess it depends on how secure you need it.

First port of call would be to check if Lasso / the PDF library supports
secured PDFs:

http://www.locklizard.com/pdf-watermarking.htm

If not, then it's purely aesthetic — a transparent PNG has worked well for
me in the past (secure not being a requirement).

Ke

On 24 July 2012 18:25, Brad Lindsay <[hidden email]> wrote:

> I'm looking to take a PDF that has been stored on my server and
> personalize it with a watermark before serving it to users. (I'll be using
> Lasso 9.) Before I start figuring out how to do this, I figured I'd check
> to see if anyone has done this before, in either 8 or 9? Any pointers would
> be greatly appreciated.
>
> Thanks,
> Brad
> #############################################################
> This message is sent to you because you are subscribed to
>   the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

Brad Lindsay-2
On Jul 24, 2012, at 3:26 PM, Ke Carlton <[hidden email]> wrote:

> A guess it depends on how secure you need it.
>
> First port of call would be to check if Lasso / the PDF library supports
> secured PDFs:
>
> http://www.locklizard.com/pdf-watermarking.htm
>
> If not, then it's purely aesthetic — a transparent PNG has worked well for
> me in the past (secure not being a requirement).

I'm not too worried about trying to make it so that people can't remove the watermark, I'd just like to add the text: "This Document Prepared For: John Doe on 7/24/2012" to the bottom of every page.

In other words, the watermark will be dynamic. Before I go digging into the ImageMagik and PDF methods, if anyone has some example code they could share, that'd be great.


Brad
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

Wade Maxfield
On 25/07/2012, at 7:54 AM, Brad Lindsay wrote:

> I'm not too worried about trying to make it so that people can't remove the watermark, I'd just like to add the text: "This Document Prepared For: John Doe on 7/24/2012" to the bottom of every page.
>
> In other words, the watermark will be dynamic. Before I go digging into the ImageMagik and PDF methods, if anyone has some example code they could share, that'd be great.
>
>
> Brad

I haven't done anything PDF related since trying it out for a very simple proof of concept in 2006, but isn't that just placing some text in a PDF at a particular place on the page, rather a watermark?

What I'm thinking is, have a cache directory, grab the source PDF, save it with a unique filename (probably with some form of datestamp in the name), modify it with the appended text, then file_serve or file_stream the result.  Have a daily cron script to clean up the cache directory after a grace period (say 48 hours - hence the datestamp in the filename).

For the actual inserted text, this is what I had. Super simple but it was only to prove the concept for the client.


Local: 'voucherCode' = 'ABC123';
Local: 'voucherValue' = '100.00';

Local: 'thePDFFile' = '/_cache/uniqueID.pdf';

Local: 'valueFont' = (PDF_Font: -Color='#cc3333', -Face='Courier', -Size=18);
Local: 'codeFont' = (PDF_Font: -Color='#CC3333', -Face='Courier', -Size=18);

Local: 'thePDF' = (PDF_Doc: -File=#thePDFFile, -Width='576', -Height='268');
#thePDF->(AddImage: -Image='/_images/groovy-image.jpg', -Left=0.0, -Top=0.0);

#thePDF->(DrawText: #voucherCode, -Font=#codeFont, -Leading=2, -Left=254.0, -Top=204.0);
#thePDF->(DrawText: '$'+#voucherValue, -Font=#valueFont, -Leading=2, -Left=427.0, -Top=161.0);

#thePDF->(Close);


 - Wade


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

Brad Lindsay-2
On Jul 24, 2012, at 7:36 PM, Wade Maxfield <[hidden email]> wrote:

> I haven't done anything PDF related since trying it out for a very simple proof of concept in 2006, but isn't that just placing some text in a PDF at a particular place on the page, rather a watermark?
>
> What I'm thinking is, have a cache directory, grab the source PDF, save it with a unique filename (probably with some form of datestamp in the name), modify it with the appended text, then file_serve or file_stream the result.  Have a daily cron script to clean up the cache directory after a grace period (say 48 hours - hence the datestamp in the filename).
>
> For the actual inserted text, this is what I had. Super simple but it was only to prove the concept for the client.
>
>
> Local: 'voucherCode' = 'ABC123';
> Local: 'voucherValue' = '100.00';
>
> Local: 'thePDFFile' = '/_cache/uniqueID.pdf';
>
> Local: 'valueFont' = (PDF_Font: -Color='#cc3333', -Face='Courier', -Size=18);
> Local: 'codeFont' = (PDF_Font: -Color='#CC3333', -Face='Courier', -Size=18);
>
> Local: 'thePDF' = (PDF_Doc: -File=#thePDFFile, -Width='576', -Height='268');
> #thePDF->(AddImage: -Image='/_images/groovy-image.jpg', -Left=0.0, -Top=0.0);
>
> #thePDF->(DrawText: #voucherCode, -Font=#codeFont, -Leading=2, -Left=254.0, -Top=204.0);
> #thePDF->(DrawText: '$'+#voucherValue, -Font=#valueFont, -Leading=2, -Left=427.0, -Top=161.0);
>
> #thePDF->(Close);

Thanks Wade. Just out of curiosity, is there a way to programmatically get the width and height of the PDF? Also, some pages in the PDF might be landscape while the others are portrait, so maybe I need to get the height & width on a page-by-page basis.


Brad
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

stevepiercy
On 7/25/12 at 9:52 AM, [hidden email] (Brad Lindsay) pronounced:

>Thanks Wade. Just out of curiosity, is there a way to
>programmatically get the width and height of the PDF? Also,
>some pages in the PDF might be landscape while the others are
>portrait, so maybe I need to get the height & width on a
>page-by-page basis.

Yup.

[PDF_Read->PageSize] when reading, else you declare its size
when creating it with [PDF_Doc(-size='value')] or
[PDF_Doc(-height=points, -width=points)], or you can use [PDF_Doc->GetSize].

I forget off the top of my head the actual pixel height and
width for each page size (letter, A4, etc.).

Anyway, the 8.x Language Guide is the single best source for the
documentation of PDF at the moment, or possibly the v=8 on the
Language Reference:
http://www.lassosoft.com/LassoDocs/languageReference?ls=PDF&v=8

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking PDFs

Jolle Carlestam-3
In reply to this post by Brad Lindsay-2
24 jul 2012 kl. 19:25 skrev Brad Lindsay:

> I'm looking to take a PDF that has been stored on my server and personalize it with a watermark before serving it to users. (I'll be using Lasso 9.) Before I start figuring out how to do this, I figured I'd check to see if anyone has done this before, in either 8 or 9? Any pointers would be greatly appreciated.
>

Getting late into the discussion but here's a Lasso 9 demo.

local(pdf_original = pdf_read('/test_origin.pdf'))
local(pdf_original_size = #pdf_original -> pagesize(1))
local(pdf_width = #pdf_original_size -> get(3))
local(pdf_height = #pdf_original_size -> get(4))
local(pdf = pdf_doc(-width = #pdf_width, -height = #pdf_height, -nocompress))

#pdf -> add(pdf_text( 'My watermark',
        -type = 'paragraph'),
        -height = 80,
        -leading = 14,
        -width = 240,
        -left = (#pdf_width / 2) - 40,
        -top = #pdf_height / 2)

#pdf -> insertpage(#pdf_original, 1)

#pdf -> close

pdf_serve( -content = #pdf, -file = 'demo.pdf')

HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>