Allow Printing and Assembly on encrypted PDF

I'm using iText to create PDFs.  The Document Restrictions is set to
"Allow Printing = true" and it's not password protected (even though
according to java API that it is) when I try to print the PDFs. As
soon as I set the restriction "Allow Assembly" to true, I need to
provide a password when I try to insert one document into another.  Is
there a way to combine two PDFs but still prevent the user from
modifying the contents of the documents??  The following is the code
that I use to create and encrypt when generating the PDF:

import java.io.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class Encrypt extends java.lang.Object {

    /**
     * @param args the command line arguments
     */
    public static void main (String args[]) {
        if (args.length != 3) {
            System.err.println("This tools needs 3 parameters:\njava
Encrypt srcfile destfile password");
        }
        else {
            try {
                // we create a reader for a certain document
                PdfReader reader = new PdfReader(args[0]);
                // we retrieve the total number of pages
                int n = reader.getNumberOfPages();
                System.out.println("There are " + n + " pages in the
original file.");

                // step 1: creation of a document-object
                Document document = new
Document(reader.getPageSizeWithRotation(1));
                // step 2: we create a writer that listens to the
document
                PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(args[1]));
                writer.setEncryption(PdfWriter.STRENGTH128BITS,
args[2], null, PdfWriter.AllowPrinting | PdfWriter.AllowAssembly);
                // step 3: we open the document
                document.open();
                PdfContentByte cb = writer.getDirectContent();
                PdfImportedPage page;
                int rotation;
                int i = 0;
                // step 4: we add content
                while (i < n) {
                    i++;
 
document.setPageSize(reader.getPageSizeWithRotation(i));
                    document.newPage();
                    page = writer.getImportedPage(reader, i);
                    rotation = reader.getPageRotation(i);
                    if (rotation == 90 || rotation == 270) {
                        cb.addTemplate(page, 0, -1f, 1f, 0, 0,
reader.getPageSizeWithRotation(i).height());
                    }
                    else {
                        cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
                    }
                    System.out.println("Processed page " + i);
                }
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                System.err.println(e.getClass().getName() + ": " +
e.getMessage());
            }
        }
    }

}

Thanks.

0
kwtung77 (1)
5/25/2007 11:51:31 PM
comp.text.pdf 5583 articles. 0 followers. ramon (1518) is leader. Post Follow

0 Replies
845 Views

Similar Articles

[PageSpeed] 43
Reply:
Similar Artilces:

Canon CD Print Software With Epson Printer?
I have two printers that print directly onto CD's, the Canon i865 and Epson R310. I'm having problems with the CD Print software that came with the Epson one, so i was wondering if it's possible to just use the Canon one? Or is each piece of software designed with only one printer in mind? Kris ...

What function allows conversion md5 in text
Hello, What function allows conversion md5 in text? Thanks in advance Thierry What function reverse md5 result in original form? "Ziggy" <tpmsn2004nospam]@nospamfree.fr> a �crit dans le message de news: 47510e9c$1$11771$426a74cc@news.free.fr... > Hello, > > What function allows conversion md5 in text? > > Thanks in advance > > Thierry > > > Ziggy;106343 Wrote: > Hello, > > What function allows conversion md5 in text? > > Thanks in advance > > Thierry I am not sure I understand, MD5 returns a string http://...

Linear matrix index produces "??? Maximum variable size allowed by the program is exceeded."
All, I have a somewhat large, though not enormous, sparse matrix, size(A) ans = 26928000 26928000 nnz(A) ans = 50702160 as well as two index vectors, 'i' and 'j' (type double) whose values may be summarized as min([i j]) ans = 1 1 max([i j]) ans = 26928000 26928000 Then, if I generate the linear index 'k' as k = sub2ind(size(A), i, j); I get, max(k) % (== k(end)) ans = 7.251171840000000e+14 which is equal to NUMEL(A) and exactly repres...

what to allow or not allow
I'm running Zone Alarm Pro, and when the pop up warnings come up saying that a program wants to access the internet or it wants to act as a server, I very seldom know what to do. Some are obvious, but most are not, so I generally deny access. Is there a good rule of thumb to use on this? I can't be the only one out there that's unsure of this. Also, why would any of the programs want to act as a server? -- ------------------------------------------------------------------------- FIGHT BACK AGAINST SPAM! Download Spam Inspector, the Award Winning Anti-Spam Filter http://mail....

IT / Business Issues and Lifestyle Magazine Free
The October Issue of InfoLeader is online as http://www.infoleader.net Some of the articles include : Beyond eCommerce: the Next Wave The Future of I.T. Personnel The Importance of Ongoing Education The Power and Influence of a Quality Action Team Those Rude and Unfair Customers! Emotional Vampires - People That Sap Your Energy In The Work Place ...

PCL printing doubts
Hello to all, I have been asked by a customer if it is possible to use "PCL backgrounds" in a print job. With "using PCL background", he means something like this: 1) send to the printer the image which will be printed as background on all pages (the printer then waits for the pages to print) 2) send to the printer the various pages to print, and now the printer should start printing these pages with the background + the pages data. As an example, first I send to the printer a PDF document which is a form to fill in (imagine an official income-tax form) and...

How to assemble a Utility
In so far as I understand gcc it should be possible to control the process via gcc which acts as an intelligent front end to other tools. I can assemble with a single gcc command and the output is an AIF headered Absolute. Perfect. The bit I have not worked out is how to assemble a Utility with just a gcc command. I am using this :- Dir <Obey$Dir> gcc -mthrowback -c HelloGCC.s drlink -bin HelloGCC.o -output HelloGCC SetType HelloGCC Utility Is there a better way. Thanks. -- David Pitt. Computing with RISC OS. ...

attributed name print issue
Hello, some of my attributed names prints their name, others their attributed value: this behaviour sounds random. Is there a way to fix it ? In particular, I would like to the names, not the attributed values. Thanks, Jerome In article <51f1b8f1$0$2268$426a74cc@news.free.fr>, Jerome BENOIT <g6299304p@rezozer.net> wrote: > Hello, > > some of my attributed names prints their name, others their attributed value: > this behaviour sounds random. > Is there a way to fix it ? In particular, I would like to the names, not the > attributed values. &g...

Characters change when going from Frame 7 to PDF
I've run into a strange problem, in two different jobs over the last three weeks, that I've never seen before, and I'm hoping that someone out there has a solution to it. The basic problem is that characters in graphics in PDFs made from Framemaker 7 change. In one example all the instances of lower case "l" change to a lower case "z". In the other example all the instances of lower case "b" change to a lower case "z". There are similarities between these 2 jobs. In both cases, the graphics that had been placed into Frame containe...

antialiasing with print?
Does anyone know if there's a way to get the matlab print command to use antialiased lines / fonts when rasterizing? My web searchs have turned up blank. ...

Re: allow-resursion stuff #3
> On Thu, 8 Jun 2006, Mark Andrews wrote: > > > > > > On Thu, 8 Jun 2006, Mark Andrews wrote: > > > > > > > > > > > > Hi All, > > > > > > > > > > The allow-recursion { trusted; }; is very nice. > > > > > However, isn't it true to when you haven't also got > > > > > allow-query { trusted; }; there is still an issue with just > > > > > allow-recursion? For example, suppose that somebody within the trusted ra > > > nge > > &...

Print bitmap file
I need to print a bitmap file in C under Windows. I'm a senior in college so please show me the respect I'm due. I don't want any of you jokers telling me that it can't be done because I know it can. Post the code here no later than Friday by noon, please. I'm counting on you guys to come through. I really need this. Benefits for those that help. I have more money and friends than most if not all of you could ever dream of. Thx in advance -- myombi Myombi Natuse <mn120384@aol.com> wrote: > I need to print a bitmap file in C under Windows. I'm a senior i...

US-TX-Austin: RF Eng., MSEE, Developer amplifier assemblies, PCB layouts; Perm (45328514410)
US-TX-Austin: RF Eng., MSEE, Developer amplifier assemblies, PCB layouts; Perm (45328514410) ============================================================================================ Position: RF Eng. Reference: SMC01735 Location: Austin TX Duration: Perm Skills: MSEE Proven exp in analysis, design, and PCB layout of RF circuits and components for wireless infrastructure equipment. Significant exp developing RF power amplifiers capable of transmitting at least 15 Watts, which would incl...

Internet Page Printing problem
Hi Could anyone tell me why a Lexmark Printer, would work fine when printing Documents that are stored on my computer (XP Home), but just get a Blank page when printing an Internet page. The computer is clean there is no spyware, or virus's on the computer. I have tried uninstalling/reinstalling the drivers, still the same problem. Can anybody help on this please Even though Lexmark is a piece of shit it is not the problem directly. It might be the OS, the browser, the settings, security, or the print driver. I would download (free) Mozilla 1.75 suite. Install wi...

Am I allowed
To post here? Just checking. Wow this group has changed a lot since i was on here. Where did all the discussion and experts go? Just meeting at the conferences I guess. Does anybody find it disturbing that the internet has turned into a streaming media platform and lost the most important and interesting aspect, centralized discussions? The internet is now a decentralized mess of message boards with no experts at site. I can't find any discussions or answers anymore Is this a government plot to keep people from meeting in groups or sometihng. "lorber_sean2002&...

Print error #2
Warning: Problems in UIW_SetUpGLPrinting > In C:\Program Files\MATLAB\R2006a\toolbox\matlab\graphics\private\render.p>render at 129 In print at 263 In printdlg at 84 I get this error when trying to print on Matlab 64 R2006a version. Anybody know how to fix this? There is no problem with the R2006a 32-bit version... Thanks, Peter ...

Block Mail From Local Account But Allow It To Receive Mail?
Spammers are forging mail making it appear to come *from* one of my local accounts. These are accounts that do need to receive mail but are never used to send it. If I attempt to add such phony senders to my access file to be REJECTed, it also blocks the legitimate account from *receiving* mail as it should because I have blacklist_recipients enabled in my .mc file. (I do need to block some local users from ever receiving mail.) So how do I configure sendmail to: 1) Accept mail for some local accounts, but block mail that appears to be *sent* by them. 2) Also completely block send/re...

PDF 2 EPS using ghostscript
Hi Guys, I'm trying to convert a PDF to EPS using the GhostScript. Does anyone know if its possible to set the colorspace when doing so? It seems to default to RBG, which of course does not help too much in the print world. Thanks Warrick Warrick FitzGerald wrote: > I'm trying to convert a PDF to EPS using the GhostScript. Does anyone know > if its possible to set the colorspace when doing so? It seems to default > to RBG, which of course does not help too much in the print world. EPS generator in Ghostscript reduces everything to path, image, and image mask in device col...

Re: Printing two rows with different formats
first of all: such a "dataset" I'd like to restructure! A typical thing of relational structures is, that certain attributes have certain properties, but all the same over the whole dataset! What you have is a non-relational structure. With 2 records that might be possible to handle, but what do you do with 2 k, 2 m or 9 g? 2000 datasets? Or 2 billions? You should try data test; x=10000; output; x=0.02; output; run; data _null_; set test; file print; if _n_=1 then do; put x dollar9.; end; if _n_=2 then do; put x percent5.; end; run; for 2 records. For...

\multicolumn not allowed in macro with an optional argument
I have to write a tabular with several \multicolumn, so I would like to define macros including \multicolumn to save typing and improve the readability of the source file. In the code below, \foo has one mandatory argument and \FOO has an optional one. Their definition is almost identical. Both commands have \multicolumn in its definition. The \foo macro works as expected, but \FOO causes the error =AB! Misplaced omit=BB. Why does \FOO fail? Is this a known issue? In my real code, I can just go ahead without optional arguments, but it would be nice to be able to use them. By the way, this prob...

Good photo-editing/printing program
I'm trying to get recommendations for good programs for manipulating digital photographs for my wife. The priorities are: - Ease of use! - Lots of format and scrapbooking templates - Not horribly expensive (<$100) The ones I've been looking at are: -Microsoft Digital Image Suite -Adobe Elements and Album -Broderbund Digital Studio and Printshop -Art Explosion Scrap Book Deluxe -Roxio PhotoSuite 5 Any advice or impressions (positive or negative) would be appreciated. -Eric ...

Creating PDF with ReportPro3
Hi, I have to create many different (RP3-)reports as PDF. Unfortunately I didnt find any acceptable solution or example, neither in this group nor the web. Now I solved the problem and want to share my solutions. First I used RP3 to export the report in RTF, opened the RTF in Word2007 and saved the report as PDF: method WriteRTF(cReport,cFile) class MyClass local oReport as rp3Runtime local cDat as string cDat:=cFile+".RTF" oReport:=rp3Runtime{self} oReport:HyperLabel:=HyperLabel{#rp3Runtime,"rp3Runtime",null_string,null_string} oReport:Cr...

Colour laser print with HP's CP1515n
ok.. new start to identify the printer, a Hewlett Packard Colour LaserJet CP1515n, as there are many others that may not necessarily react in similar fashion: Original problem: Could not print files larger than 4MB, even though networked and using !Printers PoScript2 presents a superb printout, with natural colours almost indistinguishable from that seen 'on screen' and a superb clarity that is still a leader in the field... Two fold 'solution' - Printer: 1. Following a large number of emails and beta test prints for this droid to perform, the Maestro I...

TI assembly optimization
Hi all, IMG_LIB come together with .sa file and .asm file. When I recompile the sa file of an routine from IMG_LIB, I got the epilog of a loop longer than original asm file. May I know why? How can I get the same epilog as original one? Actually I have switched on all the optimizer already. These are the switch that I use for the assembler. Thanks... -o3, -mi, -mt, -k, -mh98 tnk Hi tnk, Did you set the build options in the right manner for your target ? Are there compiler switches in the lib providing conditional compilation ? Just some hints, ...

Printing Issue
Hi, I purchased a new iMac yesterday and am trying to print onto my company's network printer. I have a Mac running 10.2.8 and when i try and connect to the printer it works fine. I have another Mac laptop that connects fine. With this new iMac, it detects the printer on the network with appletalk, will install without problem. But, when i try and print to it through any program then it always comes up with a printing error and doesnt work. I have installed this printer on 3 other macs without problem. I have also shared a local printer on one of the other macs and tried to connect...