Allow Printing and Assembly on encrypted PDF

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply kwtung77 (1) 5/25/2007 11:51:31 PM

See related articles to this posting

comp.text.pdf 5540 articles. 36 followers. Post

0 Replies
751 Views

Similar Articles

[PageSpeed] 41


Reply:

Similar Artilces:

Creating PDF without password that allows printing but not editing with Acrobat professional 7
Hello all, We just go adobe acrobat professional 7 instead of 5. And we can't figure out how to create a pdf file that everyone can open and print without password but that they cannot edit. Whatever we try with password security we can't seem to get this to work. Anyone has any ideas, this is rather urgent... "geurtd" <geurt@geurt.com> wrote: >We just go adobe acrobat professional 7 instead of 5. >And we can't figure out how to create a pdf file that everyone can open >and print without password but that they cannot edit. >Whatever we try with pass...

printing PDF direct to HP laserjet 4050 get raw content not PDF printed
>From a command prompt if I do type test.pdf > lpt3: on a HP LJ1320 I get the PDF nicely printed But when I try same thing on a HP LJ4050 I get the raw content printed as text like %PDF1.4 1 0 obj << /Type /Catalog /Version /1.4 kicking <k.king177@ntlworld.com> wrote: > >>From a command prompt if I do > > type test.pdf > lpt3: > > on a HP LJ1320 I get the PDF nicely printed > > B...

Printing a PDF from Another PDF
is there any way I can print a PDF Document from another PDF. The reason I am asking this is that I have a PDF list containing approx. 50 PDF Documents and would like to be able to print a chosen Document from my list rather than linking to it and then printing it when it has opened. Thanks in anticipation ...

Print Reports as PDF: Cannot print
I have a procedure to automate .pdf reports. I set the default printer to the pdfwriter driver before running. When the procedure runs, some of the reports get an error: "Cannot print, the file is in use or locked". Any ideas? Win2k and Access v8. This sounds like a problem with PDFWriter, not with Access. Is it possible that you're trying to print to an open file? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (No private e-mails, please) "Access Guy" <accessguy1010@yahoo.com> wrote in message news:365f86b8.0401090859.66eb2bb@posting.google...

Saving pdf is disabled but printing pdf to pdf is possible, some problems still
Hi! You know that saving editable PDF-files (I mean PDF-files where fields are editable) is disabled in Acrobat Reader. So I need a way to save edited PDF-files (with filled text-fields and other fields) to PDF. One way is to print PDF-file with some PDF-printer to new PDF, when edited field's data are saved to that new one within right way. That works sometimes but sometimes some of fonts are disabled and some text-fields are filled with different size of circles. Anyone know how to do that? Is Acrobat Reader protected against this kind of doing? Thanks a lot to everyone and I'm...

PDF for Printing Books Print-on-Demand: How to Discover "print quality"
Hello and thanks very much in advance, I've been preparing books for printing for print-on-demand. My question is: If I open a pdf file, how can I tell the "print-quality" of the file? I'm not sure I'm using the correct terms: I know that when creating a pdf, Acrobat offers various options, and some are better for printing books. What I want to do is use different PDF-making applications, create the PDF, and then discover what quality has been made. Thanks again ... RW "booklover" <robinwhitman@gmail.com> wrote in message news:1172329557.423364.23369...

Origin of PDF is shifted when PDF is printed
Hallo, we are in a test phase for the following project: Generate lots of PSFs with renderX's XEP and let them print on demand by a service provider specialized on this. The PDFs are printed on a highly automated basis. The problem is, that the service provider complains about that our PDFs contain some unknown error. That leads to a huge vertical shift of the printed output in a way that only approx. the two centimeters of the PDF is printed at the top of the paper sheet. Horizontally the PDF is shifted, too, but only a couple of millimeters. If you open the PDF in an Acrobat Reader or ...

Problem
# application server - JbossServer-4.0.4.# OS: windowsXP# IDE: Eclipse# Problem - I want to print Current Output of Pdf file and shouldprint once.I get print dialog box but it is not working properly.public void doPost(HttpServletRequest request, HttpServletResponseresponse) throws ServletException, IOException { String strId="QI0001"; ByteArrayOutputStream baosPDF = generatePDFDocumentBytes(strId); response.setContentType("application/pdf"); response.setContentLength(baosPDF.size()); ServletOutputStream out = response.getOutputStream...

Problem
# application server - JbossServer-4.0.4. # OS: windowsXP # IDE: Eclipse # Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working properly. public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String strId="QI0001"; ByteArrayOutputStream baosPDF = generatePDFDocumentBytes(strId); response.setContentType("application/pdf"); response.setContentLength(baosPDF.size()); ServletOutputStream out = response...

Printing to PDF uding Free PDF / GhostScript
I have installed Free PDF, Ghostscript, Redmon and Adobe Prostscript Printer on WinXP Home, and it worked nicely. But suddenly I get an errror: "The input postscript file file: c:\window Sorry, my keyboard went crazy (working over a GoToMyPC line which sometimes gives problems with the keyboeard). This was what I tried to write: I have installed Free PDF, Ghostscript, Redmon and Adobe Prostscript Printer on WinXP Home, and it worked nicely. But suddenly I get an errror: {"The input postscript file file: c:\window\reda02784} > > John Je ...

Encapsulated PDF Storage and Encrypted PDF file
Hi there, There is no such DICOM attribute as 'Encrypted PDF' ? This attribute would be used to identify whether the DICOM file encapsulate an encrypted PDF file or not... Just a random thought, -Mathieu ...

printer print out different pdf print out different
Hello! I have a strange problem which look like this.... I print out the report into the screen (in Oracle Reports (Oracle 9.0)) and then I print it out on the paper (this is: into the printer). I also print out the report into the screen and then I saves it into the pdf file. My client told me that report printed out into the pdf file is OK, but report printed out into the paper & screen (this is into printer) is NOT OK. I`ve checked and my client is right, because report printed out on the paper and screen contains different values than report printed out into the pdf ...

Printing A4 Pdf to A5 landscape Pdf for ebook
Hello, is it possible to print an A4 Pdf to an A5 landscape Pdf for ebook, in order to zoom each A4 page on 2 smaller A5 pages in landscape, without having to reflow the pdf file (a very difficult task) : I tried a lot of combinations without success : the destination page is never rotated from source page. Thanks for help. P.S.: I am using CutePdf to print the pdf into another pdf. ------------------------------------------------------- Patrice Dargenton patrice.dargenton@free.fr http://patrice.dargenton.free.fr/index.html ------------------------------------------------------- Patrice D...

PDF printing problem: Size changes when printing from Acrobat??
A design made in Illustrator 9, which i put on a CD-Rom in the following formats: Illustrator 9.0 native (Win) Illustrator 9.0, saved as Illustrator 8.0 compatible (Win) Illustrator 8.0 compatible EPS PDF I then took the CD to my local 'copyshop' to have some A3-sized laserprints made. Naturally the operator opened the PDF file, t looked good, then printed it...but too small?! The file is basically an A3 sized page (no bleed) with an a-4 sized area in the middle of it, with trim-marks and some design on it. When printing it in any other of the 3 formats supplied, the pint is the perf...

only banner is printed when print pdf from acrobat reader on AIX
When I print a pdf document from acrobat reader using "lpr -Pprintername" I get only banner page. Could anyone tell me what is missed/wrong? ...

How to print print pdf on the network with OS400 4.3
Hello, I have an AS400 runing the 4.3 OS version. I would like to be able to create pdf documents from the AS400 adding Company logo and all. I know the OS version I have can not create them, but I have CUPS on my Mac OS X machines. Does any one know how I can do this? If not is there another "cheap" solution since we will change the machine in the coming months and I don't really want to invest in software solutions that are not needed, afak, when runing the latest OS versions. TIA -- Les gens sans humour manquent de s�rieux. Benoit Leraillez wrote: > ...

Magicolor 2300DL printing problems (prints from PDF but not from Word?)
I previously posted a query regarding a Magicolor 2300DL and a false paper jam issue. I have since found a workaround but not actually solved the original problem. It appears that if I print a document to PDF and then print the PDF it works fine. If I try to print directly from Word the printer picks up the paper and draws it a couple of inches into the printer and then reports 'Media Error - Tray 1', if I open the right printer door and close it the printer picks it up and carries on printing (after a considerable wait as it warms up again). If I try to print multi-pag...

Windows vs. GTK printing (was Allowable print area)
A little more work on this has revealed something interesting. It seems WIndows reports GetPageSizeMM() as the printable page area (so for an A4 sheet that has a physical size (210x297), Windows reports 198x287 for my default printer. GTK on the other hand reports the entire 210 x 297mm sheet. So...If I was to plot a pixel at (0, 0), Windows would happily print that pixel (at approx 5mm x 5mm in from the top left) where GTK would not as it is trying to print off the printable area. If I was to print some text at (what I thought was) 10mm from the left edge of the paper, on GTK i...

Pdf for each print
Hi, i want to make a pdf each time that i print on one of my printer. So i have one copy in pdf for each documents that i print. Could you say me if is there a software to do that? Thanks -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG Hi, There are many software applications which could help. What is the source of your documents? What is your throughput requirements (volume)? How ofter do you want to run? Are your PDFs to be posted or emailed out? Would printing the PDF be acceptable or do you print from your application directly? Knowing a bit more about what you want ...

Printing to PDF
(FMP7:WXPHome) I think I posted this before with no reponse, but like so many things these days, can't be sure (too many brain cells killed off in the Sixties-Seventies). At any rate... In FMP6, I could print to Adobe Acrobat to produce a PDF of a report, layout, invoice, whatever. Now that I have converted the relevant FMP6 files to FMP7, my PDF output is basically gibberish. The various elements are correctly positioned, layout elements (lines, mostly) are in their proper places, but the text is unreadable, as if a ROT13 conversion or some such had been performed. Can anyone e...

Print to PDF
Run into a problem that I am not sure how to solve. I figured I would ask here - and maybe get some ideas. In the past I have had students print out work and turn it in to me. I am working on reducing waste, making things easier for me, and helping to get my students using computers more (being that these are computer classes!) For my Mac students this is easy... assuming they are on OS X. I simply show them how to "print" to a PDF. Granted, there is some learning curve to know how and where to save it and then to put it into an electronic drop box I have set up, but that is a ...

PDF printing
Hi, is there any way to print PDF file which sits on IFS from iSeries? Thanks! Hi Bruno, A solution to your question was posted into the forum a few months ago. I have copied the relevant parts into thi message. The print file QSYSPDF was a copy of QSYSPRT with the device type set to *USERASCII and the replace unprintable character action changed from *YES to *NO. On 15 Dec 2004 08:35:35 -0800, in comp.sys.ibm.as400.misc you wrote: >Hi Paul... >I have found the solution: > > >#include <stdio.h> >#include <string.h> >#include <stdlib.h> >#include...

Print PDF
Hi! Thanks to the excellent advise of VinceH I got PrintPDF working and have managed to convert a number of files. However, on some of them I get an error and cannot see why. The error is in the form of: Error: /unregistered in --%op_show_continue-- Operand stack: --nostringval-- --nostringval-- (Over Bloomin\221 Eighty) 186840 0 Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 ...

print pdf
Hi, I'm using shellexecute() to print PDF-Files. But this prints to the Windows default printer. How can I print a pdf file to any desired windows printer ? Thank you. Michael Hagl Hello, On 17 ian., 09:11, "Michael Hagl" <hag...@hagl.de> wrote: > Hi, > > I'm using shellexecute() to print PDF-Files. But this prints to the Windows > default printer. > > How can I print a pdf file to any desired windows printer ? > > Thank you. > > Michael Hagl The SetDefaultPrinter() is implemented in xHarbour. See also: http://msdn.microsoft.c...