<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Password protect a PDF document in PHP</title>
	<atom:link href="http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php</link>
	<description>Security news, software to protect your computer</description>
	<lastBuildDate>Thu, 22 Dec 2011 16:08:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: kumar</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-24185</link>
		<dc:creator>kumar</dc:creator>
		<pubDate>Thu, 22 Dec 2011 16:08:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-24185</guid>
		<description>When I encrypted the file it is opening with out asking for password on Mac
Is that normal? Am I missing something?</description>
		<content:encoded><![CDATA[<p>When I encrypted the file it is opening with out asking for password on Mac<br />
Is that normal? Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ParthaSarathi</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-24145</link>
		<dc:creator>ParthaSarathi</dc:creator>
		<pubDate>Thu, 22 Dec 2011 06:50:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-24145</guid>
		<description>We used this api to protect the pdf file while uploading. It works on Windows machine, but, when the file opened in MAC machine it&#039;s not asking for the password.. any help?</description>
		<content:encoded><![CDATA[<p>We used this api to protect the pdf file while uploading. It works on Windows machine, but, when the file opened in MAC machine it&#8217;s not asking for the password.. any help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarker</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-19840</link>
		<dc:creator>Sarker</dc:creator>
		<pubDate>Mon, 22 Aug 2011 20:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-19840</guid>
		<description>Hi,
I have this code below to create a pdf on the fly and send as an email attachment. I like to make it password protected for open and everything. Is there any way I could use your code?

// download fpdf class (from fpdf.org)
require(&quot;fpdf/fpdf.php&quot;);

// fpdf object
$pdf = new FPDF();

// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf-&gt;AddPage();
$pdf-&gt;SetFont(&quot;Arial&quot;,&quot;B&quot;,14);
$pdf-&gt;Cell(40,10, &quot;this is a pdf example&quot;);

// email stuff (change data below)
$to = &quot;info@XXXXX.com&quot;;
$from = &quot;info@XXXXXX.com&quot;;
$subject = &quot;send email with pdf attachment&quot;;
$message = &quot;Please see the attachment.&quot;;

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = &quot;bookingrequest.pdf&quot;;

// encode data (puts attachment in proper format)
$pdfdoc = $pdf-&gt;Output(&quot;&quot;, &quot;S&quot;);
$attachment = chunk_split(base64_encode($pdfdoc));

// main header (multipart mandatory)
$headers  = &quot;From: &quot;.$from.$eol;
$headers .= &quot;MIME-Version: 1.0&quot;.$eol;
$headers .= &quot;Content-Type: multipart/mixed; boundary=\&quot;&quot;.$separator.&quot;\&quot;&quot;.$eol.$eol;
$headers .= &quot;Content-Transfer-Encoding: 7bit&quot;.$eol;
$headers .= &quot;This is a MIME encoded message.&quot;.$eol.$eol;

// message
$headers .= &quot;--&quot;.$separator.$eol;
$headers .= &quot;Content-Type: text/html; charset=\&quot;iso-8859-1\&quot;&quot;.$eol;
$headers .= &quot;Content-Transfer-Encoding: 8bit&quot;.$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= &quot;--&quot;.$separator.$eol;
$headers .= &quot;Content-Type: application/octet-stream; name=\&quot;&quot;.$filename.&quot;\&quot;&quot;.$eol;
$headers .= &quot;Content-Transfer-Encoding: base64&quot;.$eol;
$headers .= &quot;Content-Disposition: attachment&quot;.$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= &quot;--&quot;.$separator.&quot;--&quot;;

// send message
mail($to, $subject, &quot;&quot;, $headers);</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have this code below to create a pdf on the fly and send as an email attachment. I like to make it password protected for open and everything. Is there any way I could use your code?</p>
<p>// download fpdf class (from fpdf.org)<br />
require(&#8220;fpdf/fpdf.php&#8221;);</p>
<p>// fpdf object<br />
$pdf = new FPDF();</p>
<p>// generate a simple PDF (for more info, see <a href="http://fpdf.org/en/tutorial/" rel="nofollow">http://fpdf.org/en/tutorial/</a>)<br />
$pdf-&gt;AddPage();<br />
$pdf-&gt;SetFont(&#8220;Arial&#8221;,&#8221;B&#8221;,14);<br />
$pdf-&gt;Cell(40,10, &#8220;this is a pdf example&#8221;);</p>
<p>// email stuff (change data below)<br />
$to = &#8220;info@XXXXX.com&#8221;;<br />
$from = &#8220;info@XXXXXX.com&#8221;;<br />
$subject = &#8220;send email with pdf attachment&#8221;;<br />
$message = &#8220;Please see the attachment.&#8221;;</p>
<p>// a random hash will be necessary to send mixed content<br />
$separator = md5(time());</p>
<p>// carriage return type (we use a PHP end of line constant)<br />
$eol = PHP_EOL;</p>
<p>// attachment name<br />
$filename = &#8220;bookingrequest.pdf&#8221;;</p>
<p>// encode data (puts attachment in proper format)<br />
$pdfdoc = $pdf-&gt;Output(&#8220;&#8221;, &#8220;S&#8221;);<br />
$attachment = chunk_split(base64_encode($pdfdoc));</p>
<p>// main header (multipart mandatory)<br />
$headers  = &#8220;From: &#8220;.$from.$eol;<br />
$headers .= &#8220;MIME-Version: 1.0&#8243;.$eol;<br />
$headers .= &#8220;Content-Type: multipart/mixed; boundary=\&#8221;".$separator.&#8221;\&#8221;".$eol.$eol;<br />
$headers .= &#8220;Content-Transfer-Encoding: 7bit&#8221;.$eol;<br />
$headers .= &#8220;This is a MIME encoded message.&#8221;.$eol.$eol;</p>
<p>// message<br />
$headers .= &#8220;&#8211;&#8221;.$separator.$eol;<br />
$headers .= &#8220;Content-Type: text/html; charset=\&#8221;iso-8859-1\&#8221;".$eol;<br />
$headers .= &#8220;Content-Transfer-Encoding: 8bit&#8221;.$eol.$eol;<br />
$headers .= $message.$eol.$eol;</p>
<p>// attachment<br />
$headers .= &#8220;&#8211;&#8221;.$separator.$eol;<br />
$headers .= &#8220;Content-Type: application/octet-stream; name=\&#8221;".$filename.&#8221;\&#8221;".$eol;<br />
$headers .= &#8220;Content-Transfer-Encoding: base64&#8243;.$eol;<br />
$headers .= &#8220;Content-Disposition: attachment&#8221;.$eol.$eol;<br />
$headers .= $attachment.$eol.$eol;<br />
$headers .= &#8220;&#8211;&#8221;.$separator.&#8221;&#8211;&#8221;;</p>
<p>// send message<br />
mail($to, $subject, &#8220;&#8221;, $headers);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Heiko</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-16776</link>
		<dc:creator>Heiko</dc:creator>
		<pubDate>Fri, 22 Apr 2011 17:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-16776</guid>
		<description>The FPDI-Encryption (40 bit) is not very secure.
It&#039;s &quot;cracked&quot; in about 5-10 Minutes.</description>
		<content:encoded><![CDATA[<p>The FPDI-Encryption (40 bit) is not very secure.<br />
It&#8217;s &#8220;cracked&#8221; in about 5-10 Minutes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel Braila</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-13501</link>
		<dc:creator>Gabriel Braila</dc:creator>
		<pubDate>Mon, 14 Feb 2011 11:36:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-13501</guid>
		<description>I&#039;m doing an online calendar generator as pdfs but encrypting files it takes forever at least 5-10 times more than raw pdf version. I believe a more practical method will be  to stamp every month file. But with a powerfull enough online system and with just few users trying to generate pdfs it may be acceptable.
I guess encrypting images take a lot more processing power and time than simply aplying password to text only documents.</description>
		<content:encoded><![CDATA[<p>I&#8217;m doing an online calendar generator as pdfs but encrypting files it takes forever at least 5-10 times more than raw pdf version. I believe a more practical method will be  to stamp every month file. But with a powerfull enough online system and with just few users trying to generate pdfs it may be acceptable.<br />
I guess encrypting images take a lot more processing power and time than simply aplying password to text only documents.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yanke</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-11014</link>
		<dc:creator>yanke</dc:creator>
		<pubDate>Sun, 21 Nov 2010 02:46:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-11014</guid>
		<description>hi Jose ,  there is for loop error  in your code  right ?</description>
		<content:encoded><![CDATA[<p>hi Jose ,  there is for loop error  in your code  right ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ZaieN</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-9414</link>
		<dc:creator>ZaieN</dc:creator>
		<pubDate>Thu, 23 Sep 2010 19:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-9414</guid>
		<description>I tried but failed.. Where the errors?..

FPDF(‘P’, ‘in’, array(’6&#039;,’9&#039;));

//calculate the number of pages from the original document
$pagecount = $pdf-&gt;setSourceFile($origFile);

// copy all pages from the old unprotected pdf in the new one
for ($loop = 1; $loop importPage($loop);
$pdf-&gt;addPage();
$pdf-&gt;useTemplate($tplidx);
}

// protect the new pdf file, and allow no printing, copy etc and leave only reading allowed
$pdf-&gt;SetProtection(array(), $password, ”;
$pdf-&gt;Output($destFile, ‘F’);

return $destFile;
}

//password for the pdf file (I suggest using the email adress of the purchaser)
$password = “info@domain.com”;

//name of the original file (unprotected)
$origFile = “book.pdf”;

//name of the destination file (password protected and printing rights removed)
$destFile =“book_protected.pdf”;

//encrypt the book and create the protected file
pdfEncrypt($origFile, $password, $destFile );
?&gt;</description>
		<content:encoded><![CDATA[<p>I tried but failed.. Where the errors?..</p>
<p>FPDF(‘P’, ‘in’, array(’6&#8242;,’9&#8242;));</p>
<p>//calculate the number of pages from the original document<br />
$pagecount = $pdf-&gt;setSourceFile($origFile);</p>
<p>// copy all pages from the old unprotected pdf in the new one<br />
for ($loop = 1; $loop importPage($loop);<br />
$pdf-&gt;addPage();<br />
$pdf-&gt;useTemplate($tplidx);<br />
}</p>
<p>// protect the new pdf file, and allow no printing, copy etc and leave only reading allowed<br />
$pdf-&gt;SetProtection(array(), $password, ”;<br />
$pdf-&gt;Output($destFile, ‘F’);</p>
<p>return $destFile;<br />
}</p>
<p>//password for the pdf file (I suggest using the email adress of the purchaser)<br />
$password = “info@domain.com”;</p>
<p>//name of the original file (unprotected)<br />
$origFile = “book.pdf”;</p>
<p>//name of the destination file (password protected and printing rights removed)<br />
$destFile =“book_protected.pdf”;</p>
<p>//encrypt the book and create the protected file<br />
pdfEncrypt($origFile, $password, $destFile );<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OG</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-9093</link>
		<dc:creator>OG</dc:creator>
		<pubDate>Fri, 10 Sep 2010 11:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-9093</guid>
		<description>I have the same question as James Doc,

Is there a way to allow input into this script and not having to set the page format? It will default to landscape A4, but is there a way getting it to auto-detect the dimensions of the PDF that I am putting in?</description>
		<content:encoded><![CDATA[<p>I have the same question as James Doc,</p>
<p>Is there a way to allow input into this script and not having to set the page format? It will default to landscape A4, but is there a way getting it to auto-detect the dimensions of the PDF that I am putting in?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maxime</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-9065</link>
		<dc:creator>Maxime</dc:creator>
		<pubDate>Wed, 08 Sep 2010 11:57:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-9065</guid>
		<description>I read all those comments, but none relate the fact that on a PC, setting &#039;print&#039; allows printing + saving the document and no editing, while on a MAC, only printing is allowed.... All I awant is to allow &quot;print&quot; and &quot;Save as&quot; with no password when the destination computer is a MAC. Any idea someone .... thanks in advance

M</description>
		<content:encoded><![CDATA[<p>I read all those comments, but none relate the fact that on a PC, setting &#8216;print&#8217; allows printing + saving the document and no editing, while on a MAC, only printing is allowed&#8230;. All I awant is to allow &#8220;print&#8221; and &#8220;Save as&#8221; with no password when the destination computer is a MAC. Any idea someone &#8230;. thanks in advance</p>
<p>M</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Doc</title>
		<link>http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php/comment-page-1#comment-8222</link>
		<dc:creator>James Doc</dc:creator>
		<pubDate>Tue, 06 Jul 2010 12:03:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.idsecuritysuite.com/blog/password-protect-a-pdf-document-in-php#comment-8222</guid>
		<description>Hey Arthur,

To get allow printing replace the line:
$pdf-&gt;SetProtection(array(), $password, &quot;&quot;);

With
$pdf-&gt;SetProtection(array(&#039;print&#039; =&gt; &#039;print&#039;), $password, &quot;&quot;);

Should do the trick for you.

---

Cristina,

Is there a way to allow input into this script and not having to set the page format?  It will default to landscape A4, but is there a way getting it to auto-detect the dimensions of the PDF that I am putting in?

Many thanks,

James Doc</description>
		<content:encoded><![CDATA[<p>Hey Arthur,</p>
<p>To get allow printing replace the line:<br />
$pdf-&gt;SetProtection(array(), $password, &#8220;&#8221;);</p>
<p>With<br />
$pdf-&gt;SetProtection(array(&#8216;print&#8217; =&gt; &#8216;print&#8217;), $password, &#8220;&#8221;);</p>
<p>Should do the trick for you.</p>
<p>&#8212;</p>
<p>Cristina,</p>
<p>Is there a way to allow input into this script and not having to set the page format?  It will default to landscape A4, but is there a way getting it to auto-detect the dimensions of the PDF that I am putting in?</p>
<p>Many thanks,</p>
<p>James Doc</p>
]]></content:encoded>
	</item>
</channel>
</rss>

