Hi list,
I transform DocBook documents, using FOP. The resulting PDF is then
secured, using iText. This works fine, except that iText destroys the
links in the document and the bookmarks are no longer displayed in the
Acrobat reader.
I tried iText 0.94 and 0.96 and got the same result.
I have attached the method that is responsible for the securing of the
PDF.
Any suggestions?
Stephan
public void transform(byte[] pdfBytes,
java.io.OutputStream out) throws Exception
{
logger.info("Starting to transform " + pdfBytes.length + " bytes to " + out);
PdfReader reader = new PdfReader(pdfBytes);
com.lowagie.text.Document document = new com.lowagie.text.Document(
reader.getPageSizeWithRotation(1));
PdfWriter writer = PdfWriter.getInstance(document, out);
int allowances = 0;
if (allowCopying) { allowances += PdfWriter.AllowCopy; }
if (allowPrinting) { allowances += PdfWriter.AllowPrinting; }
int viewerPreferences = 0;
if (hideMenuebar) { viewerPreferences += PdfWriter.HideMenubar; }
if (hideToolbar) { viewerPreferences += PdfWriter.HideToolbar; }
logger.info("Allowances:" + allowances);
writer.setViewerPreferences(viewerPreferences);
writer.setEncryption(PdfWriter.STRENGTH128BITS, this.userPassword,
this.ownerPassword, allowances);
document.addCreator("digipub.fhnon.de");
document.addAuthor(authors.toString());
document.addKeywords(keywords.toString());
document.addTitle(title);
document.addSubject(subjects.toString());
if (this.watermarkFile != null)
{
if (!this.watermarkFile.equals(""))
{
Watermark watermark = new Watermark(
Image.getInstance(watermarkFile), 200, 420);
document.add(watermark);
}
}
document.open();
PdfContentByte cb = writer.getDirectContent();
// handling the pages
int rotation = 0;
int i = 0;
int n = reader.getNumberOfPages();
Rectangle rect = reader.getPageSizeWithRotation(1);
PdfImportedPage page = null;
while (i < n)
{
i++;
System.out.print("Processing page " + 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);
}
}
document.close();
out.close();
}