Re: [iText-questions] Hyperlink Regression in iText 2.1.6 (SVN revision 3721 by mstorer)

2009-04-16 Thread Michael Schierl
On Thu, 16 Apr 2009 00:38:04 + (UTC), Mark Storer wrote:

 Yes, I know, that getLinks method has initially been implemented by me
 (so shame on me) but it seems the PDFReader got that much more
 complexity since then that I cannot really understand what is going on
 here, especially since the non-partial constructor of PdfReader works.
 
 That or share the code to PdfReader.getLinks() so we can find your bugs.  ;)  
 I,
 being infallible, am clearly not to blame.

Sorry if my statement was ambiguous. Although initially implemented by me,
the code of getLinks has been committed to iText svn by Paulo in revision
2880 (in August 2007).

Commit:
http://itext.svn.sf.net/viewvc/itext?view=revrevision=2880

Version of the method as of 3721:
http://itext.svn.sf.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/PdfReader.java?view=markuppathrev=3721#l_2645

Hope that helps.

Michael


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php


[iText-questions] NullPointerException in PdfWriter.getNewObjectNumber

2009-04-16 Thread Michael Schierl
Hello again,

now I managed to condense the bad PDF I wrote about in the
postscriptum of my last email to one small page that still shows the
behaviour.

This time, the code to reproduce is a bit longer:

PdfReader currentReader = new PdfReader(D:/temp/bug.pdf);
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.getInstance(document, new
ByteArrayOutputStream());
document.open();
document.newPage();
List links = currentReader.getLinks(1);
PdfAnnotation.PdfImportedLink link =
(PdfAnnotation.PdfImportedLink) links.get(0);
writer.addAnnotation(link.createAnnotation(writer));
document.close();

This results (when applied to the PDF attached) in the following stack
trace:

 java.lang.NullPointerException
   at 
 com.lowagie.text.pdf.PdfWriter.getNewObjectNumber(PdfWriter.java:2251)
   at 
 com.lowagie.text.pdf.PRIndirectReference.toPdf(PRIndirectReference.java:98)
   at com.lowagie.text.pdf.PdfDictionary.toPdf(PdfDictionary.java:152)
   at 
 com.lowagie.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:168)
   at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:395)
   at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:375)
   at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:367)
   at com.lowagie.text.pdf.PdfWriter.addToBody(PdfWriter.java:792)
   at 
 com.lowagie.text.pdf.internal.PdfAnnotationsImp.rotateAnnotations(PdfAnnotationsImp.java:206)
   at com.lowagie.text.pdf.PdfDocument.newPage(PdfDocument.java:940)
   at com.lowagie.text.pdf.PdfDocument.close(PdfDocument.java:803)
   at com.lowagie.text.Document.close(Document.java:484)

This is reproducible both with iText 2.1.5 and with the latest SVN
(revision 3863). The stacktrace above is from SVN.

By the way, revision 3863 seems to fix my last reported bug in the
example document I attached, but not in the original document where I
got it reported. It seemed to be much harder to reproduce it now,
however. I'll try to build a small new PDF that can reproduce it properly.


Regards,


Michael


bug.pdf
Description: Adobe PDF document
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Re: [iText-questions] Hyperlink Regression in iText 2.1.6 (SVN revision 3721 by mstorer)

2009-04-16 Thread Michael Schierl
On Thu, 16 Apr 2009 18:21:34 +0200, 1T3XT info wrote:

 Michael Schierl wrote:
 To reproduce, just run the following code on the attached PDF.
 
  String filename = D:\\temp\\buggy.pdf;
  PdfReader rdr = new PdfReader(new
  RandomAccessFileOrArray(filename), new byte[0]);
  // this one works: PdfReader rdr = new PdfReader(filename);
  rdr.consolidateNamedDestinations(); // does not help
  rdr.getLinks(1);
 
 I applied a hack (see SVN) based on the analysis of the other Michael
 (the one from wir-sind-cool; who really is cool ;-) ).
 As Michael points out, it's not very elegant to depend on a side effect,
 and that's why I talk about a hack when referring to the change I made,
 but I tested your example and it seems to work now.

Thanks for your quick fix.

Unfortunately it still does not work for the original PDF (which is a bit
too large to attach it here). I managed to build a smaller PDF that shows
the same behaviour, this time when requesting the links for page 4. This
causes the same error as the one before, but the error remains in latest
SVN (3865) as well.

Regards,

Michael

pagefour.pdf
Description: Attached file: pagefour.pdf
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Re: [iText-questions] NullPointerException in PdfWriter.getNewObjectNumber

2009-04-16 Thread Michael Schierl
On Thu, 16 Apr 2009 19:56:34 +0200, 1T3XT info wrote:

 Xavier Le Vourch wrote:
 I've just added two new tests cases in SVN based on the two pdf files
 you sent to the list. The first one is now fixed by Bruno's change but
 the one from this thread still fails with a NPE.
 
 And it SHOULD fail! Maybe not with a NullPointerException,
 but the example doesn't make sense and some exception has to be thrown.

The same exception is thrown if I include the PdfContentByte of that page
and copy it over to the new document. I removed that part from the example
to make it clear that the hyperlinks are the culprit.

 Unless Michael can explain what he expects to happen.

The hyperlink that happens to be the first one of the hyperlinks on the
first page of the source PDF should be copied onto the first page of the
new PDF (i. e. clicking the same position should result in browsing to the
same location).

The same exception appears if I use a loop to move all the hyperlinks. And
it still appears if I transform/scale the rectangles of hyperlinks.

And, it still crashes, if you use jPDF Tweak and let it rescale the PDF
(scaling both the content and the hyperlinks) to, say, A3 format.


Perhaps you could be so kind and explain me why rescaling a PDF like this
does not make sense?


Thank you,

Michael


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php


Re: [iText-questions] Hyperlink Regression in iText 2.1.6 (SVN revision 3721 by mstorer)

2009-04-16 Thread Michael Schierl
On Thu, 16 Apr 2009 19:54:46 +0200, 1T3XT info wrote:

 Michael Schierl wrote:
 Thanks for your quick fix.
 
 In SVN, I added a toString() for the imported link objects.
 
 Unfortunately it still does not work for the original PDF (which is a bit
 too large to attach it here). I managed to build a smaller PDF that shows
 the same behaviour, this time when requesting the links for page 4. This
 causes the same error as the one before, but the error remains in latest
 SVN (3865) as well.
 
 I tried the example, see attachment.
 
 In other words: I can't reproduce the problem with your new file.

I'm sorry for stealing your time, I should have checked my original test
case again. In fact, it does not work with the original test case. For some
reason, JPdf Tweak also calls

r.removeUnusedObjects();
r.shuffleSubsetNames();

after the r.consolidateNamedDestinations();
(I think I added this to avoid problems in case there were more files to be
merged with different font subsets of the same name.)

I just changed the order, to call consolidateNamedDestinations() after the
two others, and it fixed the problem, all files could be converted fine
now. So, the real bug must be hidden in one of these two methods :(


Regards,

Michael


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php


Re: [iText-questions] NullPointerException in PdfWriter.getNewObjectNumber

2009-04-16 Thread Michael Schierl
On Thu, 16 Apr 2009 20:32:35 +0200, 1T3XT info wrote:

 Michael Schierl wrote:
 The same exception is thrown if I include the PdfContentByte of that page
 and copy it over to the new document.
 
 What do you mean by this? A PdfImportedPage or just a content stream?

// after document.newPage();
PdfContentByte cb = writer.getDirectContent();
cb.addTemplate(writer.getImportedPage(currentReader, 1), 0, 0);
 
 I removed that part from the example
 to make it clear that the hyperlinks are the culprit.
 
 Can you confirm that the hyperlink problem also existed in older versions?

Yes, it also existed in 2.1.2a version.

 Unless Michael can explain what he expects to happen.
 
 The hyperlink that happens to be the first one of the hyperlinks on the
 first page of the source PDF should be copied onto the first page of the
 new PDF (i. e. clicking the same position should result in browsing to the
 same location).
 
 The first link on the first page of pagefour.pdf refers to the
 page with reference 27 0 R; in other words to object 27 which is
 the page dictionary of page 3.
 When you copy this link to a new document, there is no page 3 yet.
 You can't use 27 0 R because you don't even know if object 27 exists
 (or if it contains a page dictionary).

Okay. The original document does not have a page 3 either. So, if I
understand you correctly, the problem is that there is am internal
hyperlink which refers to a nonexisting page? 

The problem seems to be that the isInternal() method of that link returns
false, so I assumed it must be an external hyperlink. (if the
link.isInternal() method returns true, the original code of jPDF Tweak
performs checks whether the destination page number - i. e.
link.getDestinationPage() - is still inside the document to prevent these
kind of problems. I removed them from the testcase to make it a bit more
clear, since I thought the offending link was an external one. Sorry for
the confusion.

 The same exception appears if I use a loop to move all the hyperlinks. And
 it still appears if I transform/scale the rectangles of hyperlinks.
 
 All this seems irrelevant to me.
 The links don't point to a valid page anymore when you copy them.

Then it would be cool if there would be a way for me to distinguish these
internal links that do not point to anything from really external links.
At the moment, isInternal() is false for both types. If I could distinguish
them, I could just drop those broken links as I do with links that point
outside the range.

 Because using the combination PdfReader/PdfWriter is not the way to go?
 Why don't you use PdfReader/PdfStamper?

I did not know I can move around (scale, rotate, change borders, combine
next to each other) pages in a PdfStamper. JPDF Tweak does all of this, for
example if you want to create 2-up printings or booklets.

 BUT BEFORE WE GO ON: can you please confirm that the new problem
 also existed in older iText versions?

It did, as far as I have looked.

 Michael Schierl wrote:
  And, it still crashes, if you use jPDF Tweak and let it rescale the PDF
  (scaling both the content and the hyperlinks) to, say, A3 format.
 
 Let me rephrase my question: has this ever worked?
 Because at first sight, I can't see how it would work.

It worked very well for thousands of other PDF files with lots of internal
links (that did not point to pages that did not exist). But not for that
one I received.

 Take a look at the destinations: 33 0 R and 27 0 R refer to page 
 dictionaries in the original file. What do you expect to happen when you 
 copy those links to another document? There's no way anybody can guess 
 to which page you want the copied links to point at.

That's what the getDestinationPage() and setDestinationPage() are for, as
far as I know, but only for links where isInternal() is true.
Unfortunately, for this link, isInternal() was false, so I thought it must
have been some link to http://www.lowagie.com/ or somewhere else.

 I don't think your second problem was introduced.
 You could copy the links but you can't copy the parts 33 0 R and 27 0 R 
 to a newly created document. It just doesn't make sense.

You are right. If I could just get true for links like this when I call
isInternal(), I would be very happy :-)

Michael


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php


[iText-questions] Hyperlink Regression in iText 2.1.6 (SVN revision 3721 by mstorer)

2009-04-15 Thread Michael Schierl
Hello,


when trying to update jPDF Tweak to use the latest released iText
version (2.1.5), I noticed that current iText is quite bad to
hyperlinks. I did some bisection search today and found that the problem
appeared in SVN revision 3721:

http://itext.svn.sf.net/viewvc/itext?view=revrevision=3721

(that's why I put mstorer into Cc).

The symptom is that whenever you try to read the hyperlinks from a PDF
document created by LaTeX + dvips + ps2pdf which contains hyperlinks,
you get the following exception (this stacktrace is from revision 3721):

 java.lang.IllegalArgumentException: You have to consolidate the named 
 destinations of your reader.
   at 
 com.lowagie.text.pdf.PdfAnnotation$PdfImportedLink.init(PdfAnnotation.java:818)
   at com.lowagie.text.pdf.PdfReader.getLinks(PdfReader.java:2656)

This only happens if the PDF is partial.
To reproduce, just run the following code on the attached PDF.

String filename = D:\\temp\\buggy.pdf;
PdfReader rdr = new PdfReader(new
RandomAccessFileOrArray(filename), new byte[0]);
// this one works: PdfReader rdr = new PdfReader(filename);
rdr.consolidateNamedDestinations(); // does not help
rdr.getLinks(1);

Yes, I know, that getLinks method has initially been implemented by me
(so shame on me) but it seems the PDFReader got that much more
complexity since then that I cannot really understand what is going on
here, especially since the non-partial constructor of PdfReader works.

Should I just use the non-partial version (with the filename instead of
the RandomAccessFileOrArray)? Or stay with iText 2.1.4?


Thanks in advance,


Michael


PS: I have yet another bug report about hyperlinks, that seems to have
been there forever (at least since iText 2.1.0), but it only happens on
one specific PDF file (involving a NullPointerException at
PdfWriter.getNewObjectNumber). Is anyone willing to dig into it or
should I just ignore it since it is not reproducable with any different
files?


buggy.pdf
Description: Adobe PDF document
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

[iText-questions] [PATCH] Suggestion: Add SeekableInput interface

2007-12-16 Thread Michael Schierl
Hello,

Current iText has a disadvantage for me: it only supports
RandomAccessFiles or arrays as source for the PDF. Other seekable inputs
like Blobs (from java.sql) cannot be used. So I suggest to add an
interface SeekableInput and a constructor to RandomAccessFileOrArray
that takes an instance of this interface as parameter. In the long term,
it might be a good idea to rename the RandomAccessFileOrArray class (or
to eliminate it totally where applicable), but that is not necessary.

The zip file attached contains 3 new files, a patch for
RandomAccessFileOrArray, and the new version of this file after applying
this patch to revision 3079 (latest at time of writing this).

It introduces a new interface, SeekableInput, that can be used to
implement other seekable input classes and looks like this:

--
package com.lowagie.text.pdf;

import java.io.IOException;

public interface SeekableInput {

public void close() throws IOException;
public int getFilePointer() throws IOException;
public boolean isOpen();
public int length() throws IOException;
public int read() throws IOException;
public int read(byte b[], int off, int len) throws IOException;
public void reOpen() throws IOException;
public void seek(int pos) throws IOException;
}
-

Two classes, SeekableArrayInput and SeekableFileInput, implement this
interface and incorporate the pieces from RandomAccessFileOrArray that
are specific for files or array.

RandomAccessFileOrArray has a new constructor that takes SeekableInput
instances. The old constructors create appropriate
Seekable(Array|File)Input instances. Some of the old methods in
RandomAccessFileOrArray call the interface methods now.

The patch was tested by running a few of the jPdfTweak tests against the
patched iText library. Its behaviour should be 100% equivalent before
and after the change.

What do you think about it?

Michael

package com.lowagie.text.pdf;

import java.io.IOException;

public interface SeekableInput {

	public void close() throws IOException;
	public int getFilePointer() throws IOException;
	public boolean isOpen();
	public int length() throws IOException;
	public int read() throws IOException;
	public int read(byte b[], int off, int len) throws IOException;
public void reOpen() throws IOException;
public void seek(int pos) throws IOException;
}
package com.lowagie.text.pdf;

import java.io.IOException;

public class SeekableArrayInput implements SeekableInput {
	
	byte arrayIn[];
	int arrayInPtr;

	public SeekableArrayInput(byte arrayIn[]) {
		this.arrayIn = arrayIn;
	}

	public void close() {}

	public int getFilePointer() {
		return arrayInPtr;
	}

	public boolean isOpen() {
		return true;
	}

	public int length() {
		return arrayIn.length;
	}

	public int read() {
		if (arrayInPtr = arrayIn.length)
			return -1;
		return arrayIn[arrayInPtr++]  0xff;
	}

	public int read(byte[] b, int off, int len) {
		if (arrayInPtr = arrayIn.length)
			return -1;
		if (arrayInPtr + len  arrayIn.length)
			len = arrayIn.length - arrayInPtr;
		System.arraycopy(arrayIn, arrayInPtr, b, off, len);
		arrayInPtr += len;
		return len;

	}

	public void reOpen() {}
	public void seek(int pos) {
		arrayInPtr = pos;	
	}
}
package com.lowagie.text.pdf;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class SeekableFileInput implements SeekableInput {

	MappedRandomAccessFile rf;
	RandomAccessFile trf;
	boolean plainRandomAccess;
	String filename;

	public SeekableFileInput(String filename, boolean plainRandomAccess) throws IOException {
		this.plainRandomAccess = plainRandomAccess;
		this.filename=filename;
		if (plainRandomAccess)
			trf = new RandomAccessFile(filename, r);
		else
			rf = new MappedRandomAccessFile(filename, r);
	}

	public void close() throws IOException {
		if (rf != null) {
			rf.close();
			rf = null;
			// it's very expensive to open a memory mapped file and for the usage pattern of this class
			// in iText it's faster the next re-openings to be done as a plain random access
			// file
			plainRandomAccess = true;
		}
		else if (trf != null) {
			trf.close();
			trf = null;
		}
	}

	public int getFilePointer() throws IOException {
		insureOpen();
		return (int)(plainRandomAccess ? trf.getFilePointer() : rf.getFilePointer());
	}

	protected void insureOpen() throws IOException {
		if (!isOpen())
			reOpen();
	}

	public boolean isOpen() {
		return (rf != null || trf != null);
	}

	public int length() throws IOException {
		insureOpen();
		return (int)(plainRandomAccess ? trf.length() : rf.length());
	}

	public int read() throws IOException {
		return plainRandomAccess ? trf.read() : rf.read();
	}

	public int read(byte[] b, int off, int len) throws IOException {
		return plainRandomAccess ? trf.read(b, off, len) : rf.read(b, off, len);
	}

	public void reOpen() throws IOException {
		if (rf == null  trf == null) {
			if (plainRandomAccess)
trf = new 

[iText-questions] jPDF Tweak 0.9 released

2007-09-10 Thread Michael Schierl
Hi,


jPDF Tweak 0.9 has been released.

Lots of changes, as usual. The most important ones:
 - batch processing (select several files and process them the same way)
 - command line support
 - rotating / scaling / shuffling / n-up preserves all hyperlinks now
   (both internal and external ones)
 - Uses iText 2.0.5

Full changelog and downloads are available from

http://jpdftweak.sourceforge.net/


Best regards,

Michael

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Reqt. of a hack proof PDF

2007-07-18 Thread Michael Schierl
On Wed, 18 Jul 2007 16:48:59 +0530, Manoj wrote:

 Would like to know whether the encrypted  password protected PDF files are
 hack proof. Once encrypted will anybody be able to crack the password
 easily?

The password itself is pretty safe. As far as I know, the easiest way of
getting the password is brute force (try passwords until you find it).

Getting content from the PDF, on the other hand, is easier in some cases.
So, if you use the password for different things, it will still be safe
although your users have unprotected their PDF files ;-)

Any scheme that uses only the Owner Password and an empty User Password (i.
e. everyone can open the document but Adobe Reader does not allow you to
print it) is easy to circumvent. The only protection of this scheme is
the fact that for getting the PDF specification from Adobe you have to
agree that you do not try to circumvent its protection features (plus the
fact that PDF files got quite hard to parse nowadays, but you can of course
use itext's parser to avoid that). In fact, it takes less than 20 lines of
code to write a program using iText that creates an unprotected version
from any PDF protected that way (This is similar to spreadsheet protection
in MS Excel). Elcomsoft sells/sold products to do so, and they also
provide/provided a service to unprotect single PDF files for a fee.

Of course, I will not post code to the list how to do that (and I won't
unprotect PDF files for a fee either), because I do not want to get sued by
Adobe. :-)

If you use a user password as well (that is needed by the user to open the
PDF), at least all texts and images in the PDF will be encrypted (maybe,
depending on the PDF version and your settings, more). It might still be
possible to extract metadata like the number of pages from an encrypted
PDF, but no actual content. On the other hand, if your users do not use
Adobe Reader but other products to view the PDF, please note that some of
them cannot open PDF files encrypted that way. In that case, it might be a
better idea to use some strong file encryption (like TrueCrypt or PGP)
around your PDF files instead of using a password. If someone knows the
User password, he can (like in the case where the user password is empty)
use it to create an unprotected PDF file, so the only disadvantage of
another encryption method is that your users need the program to decrypt it
(but you can use self-decrypting archives if your users all use Windows).

The main use for encrypted PDFs is to show that you dislike this file to be
printed/copied/whatever and it might be illegal to do so.

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Bookmark in concatenated PDF

2007-07-18 Thread Michael Schierl
On 18 Jul 2007 08:12:56 -, Animesh Mondal wrote:

 My requirement is that I've some existing pdfs which I've to concatenate
 and at the same time have to put bookmarks at each constituents pdf's
 contents' starting portion in the resulting pdf. Whether this can be
 done at time of concatenation or i've to put outlines in each
 constituent pdf or i make a single pdf from scratch rather making
 multiple pdf. But at current I'm given the multiple pdfs with which i
 can manipulate only. 

jPdfTweak (http://jpdftweak.sourceforge.net/) supports this. Open your
PDFs, select to insert bookmarks and use the bookmarks from the original
files, and you will get one bookmark for each file plus the file's original
bookmarks one level indented below them. You may also edit the bookmarks
interactively.

If you have to do this regularly: jPDFTweak uses IText, the source code is
available, so you can also look there :)

Basically, you have to track page numbers while concatenating your PDFs and
build a new outlines list; this list is used in a second pass with
PdfStamper#setOutlines.

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Problem while digitally sighning pdf using IText.

2007-07-16 Thread Michael Schierl
On Mon, 16 Jul 2007 05:05:08 -0700 (PDT), linkjaya wrote:

 Second by using tool given by acrobat professional.
  when i use this key following key
   Exception in thread main java.lang.NoClassDefFoundError:
 org/bouncycastle/asn1/DEREncodable

Add lib\bcprov-jdk14-135.jar (from SVN) to your runtime class path to avoid
this error.

HTH,

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Populate forms that do not use Acro Fields

2007-07-16 Thread Michael Schierl
On Sat, 14 Jul 2007 15:35:56 -0500, scott carter wrote:

 I have a collection of forms that I need to automatically populate based on
 data in our database. 

Does it need to be a form afterwards or is it just for printing? In the
latter case, use a PdfStamper, get a PdfContentByte to lay over the page,
and add your texts on there (like it is done in the watermark example). You
will need a tool to get coordinates for that, GSView (from
http://www.cs.wisc.edu/~ghost/) does the job well for me (it shows
coordinates of the mouse pointer in the status bar).

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] [PATCH] Preserve hyperlinks in PdfImportedPage

2007-07-12 Thread Michael Schierl
On Thu, 5 Jul 2007 21:45:03 +0200, Michael Schierl wrote:

 But I don't manage to get the page number of the current target - I get a
 PRIndirectReference, but how to make a page number from it?

I now solved it by doing a linear scan over all pages and look for the 
one with the same reference number. It works, but it might get slow for 
documents with lots of pages and lots of links. Better solutions still 
appreciated.

My Patch is attached. I tested it on a bunch of PDF files, no problems so 
far. Test program is the same as posted last week.

 The new function PdfReader#getLinks() will return an array of
 PdfAnnotation.PdfImportedLink. This link knows if it is internal to the pdf
 (#isInternal), and you can transform the bounding rectangle and the
 destination point by a 2x3 matrix (the same matrix you used for tranforming
 the pages with PdfContentByte#addTemplate(template,a,b,c,d,e,f)). These
 PdfImportedLinks can later be converted to PdfAnnotation objects and added
 to the PdfWriter (or discarded if the destination page is not in the new
 PDF).

Michael

keep-hyperlinks.patch
Description: Attached file: keep-hyperlinks.patch
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] [PATCH] Uncompress streams if Document.compressis false

2007-07-08 Thread Michael Schierl
On Sat, 7 Jul 2007 21:18:56 +0100, in gmane.comp.java.lib.itext.general you 
wrote:

 There are other ways to uncompress streams and your patch will fail with dct 
 encoded images, for example.

I don't care about images - they may remain compressed or get uncompressed. 
I only want to uncompress all streams that may contain source code 
(PdfNames, PdfDictionaries and similar things) - or at least all of those 
that are produced by popular applications. Of course, the resulting PDF 
should still be a valid PDF file.

Does my patch just leaves them compressed or does it create invalid PDF 
files? (I tested my code with a bunch of PDFs and all appeared fine in 
Adobe Reader afterwards; but obviously I did not test all PDFs that exist 
so if you tell me that my patch can corrupt PDFs I will believe you.) If 
the latter, I'd like to know how to do it correctly.

TIA,

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] PdfReader#getPermissions() returns strange results

2007-07-08 Thread Michael Schierl
Hello,

I thought that PdfReader#getPermissions returns the permissions used when
encrypting a document, in the same format as
PdfEncryptionSettings#setEncryption wants them. However, I only get strange
results. For example, a document without any permissions (like the one
created in the code below) will have permissions of -64 and not 0 as I used
for creating it.

Bug or feature?

Michael

Example code:
-
import java.io.FileOutputStream;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class StrangePermissions {
public static void main(String[] args) throws Exception {
Document d = new Document();
PdfWriter w = PdfWriter.getInstance(d, new 
FileOutputStream(test.pdf));
w.setEncryption(new byte[0], Test.getBytes(ISO-8859-1), 
0, PdfWriter.STANDARD_ENCRYPTION_40);
d.open();
d.add(new Chunk(Hello, World!));
d.close();
PdfReader r = new PdfReader(test.pdf, 
Test.getBytes(ISO-8859-1));
System.out.println(r.getPermissions()); // returns -64
}
}
-


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] PdfReader#getPermissions() returns strange results

2007-07-08 Thread Michael Schierl
On Sun, 8 Jul 2007 20:05:27 +0100, Paulo Soares wrote:

 Unused bits are set to one. You can feed it to setEncryption() and it will 
 work.

Okay, got it. If anyone else wonders: 40-bit encryption does not support
HQPrinting (2048), Assembly (1024), ScreenReaders (512) and FillIn (256).
So these bits end up set which confused me (and my GUI).

Thank you for the quick reply,

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] [PATCH] Uncompress streams if Document.compress is false

2007-07-07 Thread Michael Schierl
Hello,

Currenlty, Document.compress==false will only prevent newly created
streams from being compressed.

The attached patch will also decompress already existing compressed
streams (imported from other PDF files).

This is useful especially for debugging files that have been created
previously or that have been created by another program.

Michael
Index: com/lowagie/text/pdf/PRStream.java
===
--- com/lowagie/text/pdf/PRStream.java  (revision 2865)
+++ com/lowagie/text/pdf/PRStream.java  (working copy)
@@ -174,6 +174,11 @@
 
 public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
 byte[] b = PdfReader.getStreamBytesRaw(this);
+if (!Document.compress) {
+   b = PdfReader.getStreamBytes(this);
+   remove(PdfName.FILTER);
+   remove(PdfName.DECODEPARMS);
+}
 PdfEncryption crypto = null;
 if (writer != null)
 crypto = writer.getEncryption();
@@ -192,4 +197,4 @@
 }
 os.write(ENDSTREAM);
 }
-}
\ No newline at end of file
+}
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-07-05 Thread Michael Schierl
On Sat, 30 Jun 2007 17:23:41 +0200, Michael Schierl wrote:

 I will have a look if I can make up a general patch for itext to do things 
 like that - obviously links with their target in the same PDF will be 
 harder.

There is one more problem :(

I can get the links and get them into the target PDF just fine, I can
adjust the bounding box and the target point. I can also change the page
number.

But I don't manage to get the page number of the current target - I get a
PRIndirectReference, but how to make a page number from it?

Anyway, my current patch is attached.

The new function PdfReader#getLinks() will return an array of
PdfAnnotation.PdfImportedLink. This link knows if it is internal to the pdf
(#isInternal), and you can transform the bounding rectangle and the
destination point by a 2x3 matrix (the same matrix you used for tranforming
the pages with PdfContentByte#addTemplate(template,a,b,c,d,e,f)). These
PdfImportedLinks can later be converted to PdfAnnotation objects and added
to the PdfWriter (or discarded if the destination page is not in the new
PDF). Works fine here (tested with a bunch of PDF files) for external
links; internal links point to the correct relative position, but to the
wrong page (because I cannot get the page number).

TIA,

Michael
-- 
#!/usr/bin/perl -I' # tekscribble.pl - start in an xterm and scribble with mouse
$|=1;$g=\35;sub g{getc}sub [EMAIL PROTECTED]stty 
-icanon;p\233?38h;for(;;){
p$g\33\32;$_=g;$x=g;$X=g;$y=g;$Y=g;last if/q/;$k=$y.chr((ord$Y)+64).$x.chr((
ord$X)+32);p\33\14if/c/;p$g.(/ì/?$l:$k).$k;$l=$k;}p\33\3;systemstty icanon

keep-hyperlinks--unfinished.patch
Description: Attached file: keep-hyperlinks--unfinished.patch
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-07-05 Thread Michael Schierl
On Thu, 5 Jul 2007 21:45:03 +0200, Michael Schierl wrote:

 Anyway, my current patch is attached.

forgot to attach some sample code (will convert multiple pdfs to one pdf
with 4 pages per page):

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

public class HyperlinksSurvive {
public static void main(String[] args) throws IOException,
DocumentException {
preserveLinkSample(new String[] {withlinks.pdf, 
Diplomarbeit_Michael_Schierl.pdf,
hyperref.pdf}, output.pdf);
}

public static void preserveLinkSample(String[] files, String outputFile)
throws IOException, DocumentException {
int firstPage=1;
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(outputFile));
document.setPageSize(PageSize.A4);
float W = PageSize.A4.getWidth() / 2;
float H = PageSize.A4.getHeight() / 2;
document.open();
PdfContentByte cb = writer.getDirectContent();
for (int i = 0; i  files.length; i++) {
PdfReader currentReader = new PdfReader(files[i]);
currentReader.consolidateNamedDestinations();
for (int page = 1; page = 
currentReader.getNumberOfPages(); page++) {
PdfImportedPage importedPage = 
writer.getImportedPage(
currentReader, page);
float a = 0.5f;
float e = (page % 2 == 0) ? W : 0;
float f = (page % 4 == 1 || page % 4 == 2) ? H 
: 0;
PdfAnnotation.PdfImportedLink[] links = 
currentReader.getLinks(page);
cb.addTemplate(importedPage, a, 0, 0, a, e, f);
for (int j = 0; j  links.length; j++) {
if (links[j].isInternal()) {
int dPage = 
links[j].getDestinationPage();
int newDestPage = (dPage-1)/4 + 
firstPage;
float ee = (dPage % 2 == 0) ? W 
: 0;
float ff = (dPage % 4 == 1 || 
dPage % 4 == 2) ? H : 0;

links[j].setDestinationPage(newDestPage);

links[j].transformDestination(a, 0, 0, a, ee, ff);
}
links[j].transformRect(a, 0, 0, a, e, 
f);

writer.addAnnotation(links[j].createAnnotation(writer));
}
if (page % 4 == 0)
document.newPage();
}
if (i  files.length - 1)
document.newPage();
firstPage += (currentReader.getNumberOfPages()+3)/4;
}
document.close();
}
}

-- 
#!/usr/bin/perl -I' # tekscribble.pl - start in an xterm and scribble with mouse
$|=1;$g=\35;sub g{getc}sub [EMAIL PROTECTED]stty 
-icanon;p\233?38h;for(;;){
p$g\33\32;$_=g;$x=g;$X=g;$y=g;$Y=g;last if/q/;$k=$y.chr((ord$Y)+64).$x.chr((
ord$X)+32);p\33\14if/c/;p$g.(/ì/?$l:$k).$k;$l=$k;}p\33\3;systemstty icanon


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-07-05 Thread Michael Schierl
On Thu, 5 Jul 2007 21:45:03 +0200, Michael Schierl wrote:

 Anyway, my current patch is attached.

forgot to attach some sample code (will convert multiple pdfs to one pdf 
with 4 pages per page):

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

public class HyperlinksSurvive {
public static void main(String[] args) throws IOException,
DocumentException {
preserveLinkSample(new String[] {withlinks.pdf, 
Diplomarbeit_Michael_Schierl.pdf,
hyperref.pdf}, output.pdf);
}

public static void preserveLinkSample(String[] files, String outputFile)
throws IOException, DocumentException {
int firstPage=1;
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(outputFile));
document.setPageSize(PageSize.A4);
float W = PageSize.A4.getWidth() / 2;
float H = PageSize.A4.getHeight() / 2;
document.open();
PdfContentByte cb = writer.getDirectContent();
for (int i = 0; i  files.length; i++) {
PdfReader currentReader = new PdfReader(files[i]);
currentReader.consolidateNamedDestinations();
for (int page = 1; page = 
currentReader.getNumberOfPages(); page++) {
PdfImportedPage importedPage = 
writer.getImportedPage(
currentReader, page);
float a = 0.5f;
float e = (page % 2 == 0) ? W : 0;
float f = (page % 4 == 1 || page % 4 == 2) ? H 
: 0;
PdfAnnotation.PdfImportedLink[] links = 
currentReader.getLinks(page);
cb.addTemplate(importedPage, a, 0, 0, a, e, f);
for (int j = 0; j  links.length; j++) {
if (links[j].isInternal()) {
int dPage = 
links[j].getDestinationPage();
int newDestPage = (dPage-1)/4 + 
firstPage;
float ee = (dPage % 2 == 0) ? W 
: 0;
float ff = (dPage % 4 == 1 || 
dPage % 4 == 2) ? H : 0;

links[j].setDestinationPage(newDestPage);

links[j].transformDestination(a, 0, 0, a, ee, ff);
}
links[j].transformRect(a, 0, 0, a, e, 
f);

writer.addAnnotation(links[j].createAnnotation(writer));
}
if (page % 4 == 0)
document.newPage();
}
if (i  files.length - 1)
document.newPage();
firstPage += (currentReader.getNumberOfPages()+3)/4;
}
document.close();
}
}

-- 
#!/usr/bin/perl -I' # tekscribble.pl - start in an xterm and scribble with mouse
$|=1;$g=\35;sub g{getc}sub [EMAIL PROTECTED]stty 
-icanon;p\233?38h;for(;;){
p$g\33\32;$_=g;$x=g;$X=g;$y=g;$Y=g;last if/q/;$k=$y.chr((ord$Y)+64).$x.chr((
ord$X)+32);p\33\14if/c/;p$g.(/ì/?$l:$k).$k;$l=$k;}p\33\3;systemstty icanon


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-06-30 Thread Michael Schierl
On Mon, 25 Jun 2007 22:31:55 +0100, Paulo Soares wrote:

 The interactive features are annotations that exist at the page level in the 
 /Annots array. You'll have to go one by one, scale it and probably change 
 the target. It can be done but it requires some work and, mainly, it depends 
 on the application; if, for example, the target was also scaled page you'll 
 have to change the origin to point to somewhere else to match the new 
 position.

Thank you. This helped me to solve my problem in my case (a presentation 
from OpenOffice containing lots of links to http pages that should have 
been put onto a PDF with 4 pages each and the links still working).

I will have a look if I can make up a general patch for itext to do things 
like that - obviously links with their target in the same PDF will be 
harder.

Michael


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-06-25 Thread Michael Schierl
On Mon, 25 Jun 2007 11:32:23 +0100, Paulo Soares wrote:

 See http://itextdocs.lowagie.com/tutorial/general/copystamp/index.html.

Do you mean this here (hyperlinks are not mentioned there, but I guess they
are interactive features):


PdfWriter: generates a document from scratch, but also supports importing
pages from other PDF documents. There's one big downside: all interactive
features of the PdfImportedPage are lost in the process (annotations,
bookmarks, fields,...) if you use PdfWriter.


Then my question is what else I should use? PdfCopy seems to import
complete pages in 1:1 format, no way to scale two of them to one page. I
did not find any methods in PdfReader that give me hyperlinks (with their
positions) for adding them again afterwards (I will obviously have to scale
them as well as the page).

Michael
-- 
#!/usr/bin/perl -I' # tekscribble.pl - start in an xterm and scribble with mouse
$|=1;$g=\35;sub g{getc}sub [EMAIL PROTECTED]stty 
-icanon;p\233?38h;for(;;){
p$g\33\32;$_=g;$x=g;$X=g;$y=g;$Y=g;last if/q/;$k=$y.chr((ord$Y)+64).$x.chr((
ord$X)+32);p\33\14if/c/;p$g.(/ì/?$l:$k).$k;$l=$k;}p\33\3;systemstty icanon


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] How to preserve hyperlinks in PdfImportedPage?

2007-06-23 Thread Michael Schierl
Hello,

when I try to resize PDF pages to put more than one of them onto a page,
all hyperlinks on the original pages get lost.

Any ideas how I could preserve them?

Example code (resizes just first page):

--
package jpdftweak;

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

public class HyperlinkKiller {
public static void main(String[] args) throws IOException,
DocumentException {
PdfReader currentReader =
new PdfReader(withlinks.pdf);
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(scaled.pdf));
Rectangle currentSize =
currentReader.getPageSizeWithRotation(1);
document.setPageSize(currentSize);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfImportedPage page =
writer.getImportedPage(currentReader, 1);
cb.addTemplate(page, 0.5f, 0, 0, 0.5f,
0, currentSize.getHeight() / 2);
document.close();
}
}
--

Example pdf: http://home.arcor.de/mschierlm/test/withlinks.pdf

Michael

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] [patch] Allow reading page label structure to write out later

2007-06-22 Thread Michael Schierl
Hi,

just another patch (against current SVN). This time I want to allow
users to tweak page labels, so I need to be able to read the old page
labels from a PDF in a format suitable for tweaking (and getting a
String[] with all labels is not, in my opinion). Other solutions to
solve my problem are, of course, welcome as well.

By the way: What is the reason that this code here does not work?

FileOutputStream fos = new FileOutputStream(...);
PdfStamper stamper = new PdfStamper(currentReader, fos);
stamper.getWriter().setPageLabels(lbls);
stamper.close();

It copies the PDF, but does not set page labels.
I got it working by using a PdfCopy and importing every page separately.
Is there an easier solution?

TIA,

Michael

(not subscribed to mailing list any longer due to high traffic)
diff -Naur src-orig/com/lowagie/text/pdf/PdfPageLabelFormat.java 
src/com/lowagie/text/pdf/PdfPageLabelFormat.java
--- src-orig/com/lowagie/text/pdf/PdfPageLabelFormat.java   1970-01-01 
01:00:00.0 +0100
+++ src/com/lowagie/text/pdf/PdfPageLabelFormat.java2007-06-22 
23:24:32.0 +0200
@@ -0,0 +1,32 @@
+package com.lowagie.text.pdf;
+
+/**
+ * A specification how page labels for a range of pages
+ * should look like. Each page label format is valid for all subsequent
+ * pages that do not define a page label format themselves.
+ */
+public class PdfPageLabelFormat {
+   
+   private final int physicalPage;
+   private final int numberStyle;
+   private final String prefix;
+   private final int logicalPage;
+
+   /** Creates a page label format.
+ * @param physicalPage the real page to start the numbering. First page is 
1
+ * @param numberStyle the numbering style such as LOWERCASE_ROMAN_NUMERALS
+ * @param prefix the text to prefix the number. Can be CODEnull/CODE 
or empty
+ * @param logicalPage the first logical page number
+ */
+   public PdfPageLabelFormat(int physicalPage, int numberStyle, String 
prefix, int logicalPage) {
+   this.physicalPage = physicalPage;
+   this.numberStyle = numberStyle;
+   this.prefix = prefix;
+   this.logicalPage = logicalPage; 
+   }
+   
+   public int getPhysicalPage() { return physicalPage; }
+   public int getNumberStyle() { return numberStyle; }
+   public String getPrefix() { return prefix; }
+   public int getLogicalPage() {return logicalPage;}
+}
diff -Naur src-orig/com/lowagie/text/pdf/PdfPageLabels.java 
src/com/lowagie/text/pdf/PdfPageLabels.java
--- src-orig/com/lowagie/text/pdf/PdfPageLabels.java2007-06-22 
23:16:04.0 +0200
+++ src/com/lowagie/text/pdf/PdfPageLabels.java 2007-06-22 23:30:50.0 
+0200
@@ -52,6 +52,7 @@
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.TreeMap;
 
 import com.lowagie.text.factories.RomanAlphabetFactory;
@@ -100,6 +101,12 @@
 }
 
 /** Adds or replaces a page label.
+ */
+public void addPageLabel(PdfPageLabelFormat format) {
+   addPageLabel(format.getPhysicalPage(), format.getNumberStyle(), 
format.getPrefix(), format.getLogicalPage());
+}
+
+/** Adds or replaces a page label.
  * @param page the real page to start the numbering. First page is 1
  * @param numberStyle the numbering style such as LOWERCASE_ROMAN_NUMERALS
  * @param text the text to prefix the number. Can be CODEnull/CODE or 
empty
@@ -234,4 +241,60 @@
}
return labelstrings;
 }
+
+/**
+ * Retrieves the page labels from a PDF as an array of [EMAIL PROTECTED] 
PdfPageLabelFormat} objects.
+ * @param reader a PdfReader object that has the page labels you want to 
retrieve
+ * @return a PdfPageLabelEntry array, containing an entry for each format 
change
+ */
+public static PdfPageLabelFormat[] getPageLabelFormats(PdfReader reader) {
+   PdfDictionary dict = reader.getCatalog();
+   PdfDictionary labels = 
(PdfDictionary)PdfReader.getPdfObject((PdfObject)dict.get(PdfName.PAGELABELS));
+   if (labels == null) return new PdfPageLabelFormat[0];
+   PdfArray numbers = 
(PdfArray)PdfReader.getPdfObject((PdfObject)labels.get(PdfName.NUMS));
+   PdfNumber pageIndex;
+   PdfDictionary pageLabel;
+   TreeMap numberTree = new TreeMap();
+   for (Iterator i = numbers.listIterator(); i.hasNext(); ) {
+   pageIndex = (PdfNumber)i.next();
+   pageLabel = (PdfDictionary) 
PdfReader.getPdfObject((PdfObject)i.next());
+   numberTree.put(new Integer(pageIndex.intValue()), 
pageLabel);
+   }
+   PdfPageLabelFormat[] formats = new 
PdfPageLabelFormat[numberTree.size()];
+   String prefix;
+   int numberStyle;
+   int pagecount;
+   int i=0;
+   for (Iterator it = 

Re: [iText-questions] Reading a PDF via a ByteArrayOutputStream?

2007-04-13 Thread Michael Schierl
Mork Afur schrieb:
 So I guess I don't see the difference between just creating the PDF file in 
 the first place on the client machine vs. returning a baos that magically 
 creates a PDF file in the Temp folder.

Iliadis talks about server applications. You seem to talk about client
applications.

On the server there is a webserver that uses iText, creates a PDF and
stores it into a baos. This baos is then transferred to the client and
stored on disk there. If Iliadis used a FileOutputStream, the file would
be written to the disk of the server, then transferred to the client,
and then stored on the disk of the client again (and deleted from the
disk of the server after that).

If only one machine is involved and the PDF has to be viewed (and not
only zipped or written to a database, for example), using a baos for the
final PDF document does not make sense.

Michael

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] minor documentation fix (PdfViewerPreferences)

2007-04-09 Thread Michael Schierl
Fix two constant names in the comment:

- AREABOX should be ARTBOX
- PickTrayBySize should be PICKTRAYBYPDFSIZE

Michael

--- com/lowagie/text/pdf/interfaces/PdfViewerPreferences.java.orig  
2007-02-06 14:35:40.0 +0100
+++ com/lowagie/text/pdf/interfaces/PdfViewerPreferences.java   2007-04-09 
17:24:18.0 +0200
@@ -174,7 +174,7 @@ public interface PdfViewerPreferences { 
  * liPdfName.bCROPBOX/b
  * liPdfName.bBLEEDBOX/b
  * liPdfName.bTRIMBOX/b
- * liPdfName.bAREABOX/b
+ * liPdfName.bARTBOX/b
  * /ul
  * liIn case the key is PdfName.bPRINTSCALING/b, the value can be
  * ul
@@ -187,7 +187,7 @@ public interface PdfViewerPreferences { 
  * liPdfName.bDUPLEXFLIPSHORTEDGE/b
  * liPdfName.bDUPLEXFLIPLONGEDGE/b
  * /ul
- * liIn case the key is PdfName.bPickTrayBySize/b, the value must be 
of type PdfBoolean.
+ * liIn case the key is PdfName.bPICKTRAYBYPDFSIZE/b, the value must 
be of type PdfBoolean.
  * liIn case the key is PdfName.bPRINTPAGERANGE/b, the value must be 
of type PdfArray.
  * liIn case the key is PdfName.bNUMCOPIES/b, the value must be of 
type PdfNumber.
  * ul
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] [Announce] jPDF Tweak - Java GUI for tweaking PDF files (that uses iText)

2007-04-09 Thread Michael Schierl
Hi all,

as I wrote a few days ago, I am working on a GUI frontend for iText that
can do things like pdftk.

(As far as I know, it is the only non-commercial GUI program that can
make booklets from PDF files. But it can do much more...)

The current alpha version, which is quite usable, but will most likely
have lots of hidden bugs, and lacks some useful features, is available
for download at

http://jpdftweak.sourceforge.net/

In the next days, I'll put a page for it to the iText wiki, as Bruno
suggested.

Bug reports and feedback (both feature requests and hints how to solve a
task better with iText) are always welcome.

Michael

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Decrypting PDF using PDFStamper - problem to check whether user or system password was entered

2007-04-05 Thread Michael Schierl
Bruno Lowagie schrieb:

 You're also welcome to write a page about your GUI
 frontend in the Wiki: http://www.lowagie.com/itextwiki/

Thank you. I will do so when it is mature enough to release it.

 Maybe your tool could replace the iText toolbox.

Although both will have similar functionality, I don't think it will
replace the toolbox altogether. I try to make my tool more enduser
friendly, but people who want to have examples will more likely search
the toolbox, because that one contains lots of small snippets for simple
functions. My tool will most likely end up like pdftk - a small part for
the real stuff and most code for the corner cases to make the tool more
foolproof.

 I was planning to move the toolbox to a separate jar,
 but I wouldn't mind if somebody else takes over the work
 of building an end-user tool completely (as a separate
 project). I would be happy to link to it.

The name of the tool will be jPDF Tweak and it will be available at
sourceforge eventually (when my project request has been approved).

 I only wrote the toolbox in an attempt to demonstrate
 some of iText PDF manipulation possibilities, so that
 developers discover functionality they can build in
 into their (web)applications.

And for exactly this use, it is (in my opinion) still the best source
available.

New point: I'd like to add a function that allows my users to open a
password protected PDF (with the owner password) and use the same
encryption settings for the changed PDF file. However, I was not able to
determine all of the encryption parameters from the PdfReader. The
permissions are available, and the owner password has just been entered.
But user password and crypto mode (although computed internally) are not
made available.

The attached patch solves this problem for me.

Michael
diff -Naurp src-orig/com/lowagie/text/pdf/PdfEncryption.java 
src/com/lowagie/text/pdf/PdfEncryption.java
--- src-orig/com/lowagie/text/pdf/PdfEncryption.java2007-02-06 
14:10:38.0 +0100
+++ src/com/lowagie/text/pdf/PdfEncryption.java 2007-04-05 22:55:14.0 
+0200
@@ -520,4 +520,19 @@ public class PdfEncryption {
 documentID = createDocumentId();
 publicKeyHandler.addRecipient(new PdfPublicKeyRecipient(cert, 
permission));
 }
+
+public byte[] computeUserPassword(byte[] ownerPassword) {
+byte[] userPad = computeOwnerKey(ownerKey, padPassword(ownerPassword));
+outerLoop:
+for (int i = 0; i  userPad.length; i++) {
+for (int j = 0; j  userPad.length-i; j++) {
+if (userPad[i+j] != pad[j])
+continue outerLoop;
+}
+byte[] userPassword=new byte[i];
+System.arraycopy(userPad, 0, userPassword, 0, i);
+return userPassword;
+}
+return userPad;
+}
 }
\ No newline at end of file
diff -Naurp src-orig/com/lowagie/text/pdf/PdfReader.java 
src/com/lowagie/text/pdf/PdfReader.java
--- src-orig/com/lowagie/text/pdf/PdfReader.java2007-04-02 
21:55:38.0 +0200
+++ src/com/lowagie/text/pdf/PdfReader.java 2007-04-05 22:56:02.0 
+0200
@@ -3354,4 +3354,23 @@ public class PdfReader implements PdfVie
 public boolean isOpenedWithFullPermissions() {
 return !encrypted || ownerPasswordUsed;
 } 
+
+public int getCryptoMode() {
+if (decrypt == null) 
+return -1;
+else 
+return decrypt.getCryptoMode();
+}
+
+public boolean isMetadataEncrypted() {
+if (decrypt == null) 
+return false; 
+else 
+return decrypt.isMetadataEncrypted();
+}
+
+public byte[] computeUserPassword() {
+if (!encrypted || !ownerPasswordUsed) return null;
+return decrypt.computeUserPassword(password);
+}
 }
\ No newline at end of file
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] Decrypting PDF using PDFStamper - problem to check whether user or system password was entered

2007-03-31 Thread Michael Schierl
Hello,

I am trying to write a GUI frontend for itext-2.0.1 that allows to do
things like pdftk does (I use the pdftk source and the itext examples
for reference).

The first things I'm going to implement are encryption and decryption.
But there is a small problem. When decrypting, I pass the owner password
to the PdfReader and create a PdfStamper to write the decrypted PDF out.
Just like com.lowagie.tools.plugins.Decrypt does. The problem is that
this will work as well if a PDF has both a user and an owner password
and the user gives the user password only! Of course, this is nice for
the users, but as you quote in
http://www.lowagie.com/iText/faq.html#adobe, it is not how Adobe likes
tools to behave. (BTW this faq entry should be updated, shouldn't it?)

I could not find any way to get that information whether a user or an
owner password was used for decryption.

My suggestion is a patch like the one I attached and test the flag
before writing out the PDF. Did I miss anything?

TIA,

Michael
diff -Naurp src-orig/com/lowagie/text/pdf/PdfReader.java 
src/com/lowagie/text/pdf/PdfReader.java
--- src-orig/com/lowagie/text/pdf/PdfReader.java2007-03-06 
16:38:34.0 +0100
+++ src/com/lowagie/text/pdf/PdfReader.java 2007-03-31 20:03:08.0 
+0200
@@ -121,6 +121,7 @@ public class PdfReader implements PdfVie
 protected Key certificateKey = null; //added by Aiken Sam for certificate 
decryption
 protected Certificate certificate = null; //added by Aiken Sam for 
certificate decryption
 protected String certificateKeyProvider = null; //added by Aiken Sam for 
certificate decryption
+protected boolean ownerPasswordUsed = false;
 protected ArrayList strings = new ArrayList();
 protected boolean sharedStreams = true;
 protected boolean consolidateNamedDestinations = false;
@@ -747,15 +748,17 @@ public class PdfReader implements PdfVie
 
 if (filter.equals(PdfName.STANDARD))
 {
-//check by user password
-decrypt.setupByUserPassword(documentID, password, oValue, pValue);
-if (!equalsArray(uValue, decrypt.userKey, (rValue == 3 || rValue 
== 4) ? 16 : 32)) {
-//check by owner password
-decrypt.setupByOwnerPassword(documentID, password, uValue, 
oValue, pValue);
-if (!equalsArray(uValue, decrypt.userKey, (rValue == 3 || 
rValue == 4) ? 16 : 32)) {
-throw new IOException(Bad user password);
-}
-}
+//check by owner password
+   decrypt.setupByOwnerPassword(documentID, password, uValue, 
oValue, pValue);
+   if (!equalsArray(uValue, decrypt.userKey, (rValue == 3 || 
rValue == 4) ? 16 : 32)) {
+   //check by user password
+   decrypt.setupByUserPassword(documentID, password, 
oValue, pValue);
+   if (!equalsArray(uValue, decrypt.userKey, (rValue == 3 
|| rValue == 4) ? 16 : 32)) {
+   throw new IOException(Bad user password);
+   }
+   } else {
+   ownerPasswordUsed = true;
+   }
 } else if (filter.equals(PdfName.PUBSEC)) {   
 decrypt.setupByEncryptionKey(encryptionKey, lengthValue);  
 }
@@ -3339,5 +3342,9 @@ public class PdfReader implements PdfVie
 if (p == null)
 return PdfSignatureAppearance.NOT_CERTIFIED;
 return p.intValue();
-} 
+}
+
+   public boolean isOpenedWithFullPermissions() {
+   return !encrypted || ownerPasswordUsed;
+   } 
 }
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


Re: [iText-questions] Decrypting PDF using PDFStamper - problem to check whether user or system password was entered

2007-03-31 Thread Michael Schierl
Paulo Soares schrieb:
 You are right and your patch makes sense. The quote you mentioned 
 (http://www.lowagie.com/iText/faq.html#adobe) is still correct because iText 
 is a library that is used to build tools.

I wanted to refer to this part:

Because decrypting an encrypted PDF-file is not possible with iText
(and it will never be).

And if your answer refers to it as well, I think it needs some
clarification on the website (like the one you wrote in your mail). My
interpretation of that sentence is that iText does not support PDF
encryption at all.

 The library should give enough 
 information about the encryption status but it's up to the tool developer 
 using the library to enforce those restrictions as is doesn't make much 
 sense to do that in an open source library.

Full Ack.

Michael

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/