Ich verwende derzeit die Apache FOP
Bibliothek, um PDFs zu erzeugen. Ich möchte, dass diese PDFs vor dem Kopieren und Einfügen geschützt sind, so dass die Benutzer echte OCR
Bibliotheken (oder manuelle Typisierung) verwenden müssen, um die Informationen über das PDF zu erhalten.Schützen von PDFs
FOP bietet anscheinend einige Sicherheit, die dann als meta-data
auf der PDF hinzugefügt wird, um vor Dingen wie Drucken oder Kopieren zu schützen, aber das scheint nicht richtig zu funktionieren (kann das Kopieren-Einfügen beim Drucken nicht deaktivieren aktiviert, usw.).
Eine Möglichkeit, die mir direkt erschien, ist im Grunde irgendwie den gesamten Text auf den PDFs in Bilder zu verwandeln, aber ich kann keine Informationen zu diesem Thema finden.
Offensichtlich ist mir egal, ob die PDF durchsuchbar ist oder nicht. Ich möchte nur verhindern, dass Leute kopieren und einfügen, solange sie es noch drucken können.
Mein aktueller FOP Code:
private static FopFactory fopFactory;
private static FopFactory initializeFactory() throws IOException,
SAXException {
if (fopFactory == null) {
File f = new File(SettingUtil.getSetting(LetterGeneratorSettings.FOP_CONFIG_LOCATION));
fopFactory = FopFactory.newInstance(f);
}
return fopFactory;
}
public static File generatePDFFromXML(File fopTemplate, File xmlSource,
File resultFileLocation) throws IOException {
try {
initializeFactory();
URL url = fopTemplate.toURI().toURL();
// creation of transform source
StreamSource transformSource = new StreamSource(url.openStream());
// create an instance of fop factory
// a user agent is needed for transformation
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.getRendererOptions().put("encryption-params",
getEncryptionParams());
// to store output
ByteArrayOutputStream pdfoutStream = new ByteArrayOutputStream();
StreamSource source = new StreamSource(new ByteArrayInputStream(IOUtils.toByteArray(new FileInputStream(xmlSource))));
Transformer xslfoTransformer;
try {
TransformerFactory transfact = TransformerFactory.newInstance();
xslfoTransformer = transfact.newTransformer(transformSource);
// Construct fop with desired output format
Fop fop;
try {
fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, pdfoutStream);
// Resulting SAX events (the generated FO)
// must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
try {
// everything will happen here..
xslfoTransformer.transform(source, res);
// if you want to save PDF file use the following code
OutputStream out = new java.io.FileOutputStream(resultFileLocation);
out = new java.io.BufferedOutputStream(out);
FileOutputStream str = new FileOutputStream(resultFileLocation);
str.write(pdfoutStream.toByteArray());
str.close();
out.close();
} catch (TransformerException e) {
e.printStackTrace();
}
} catch (FOPException e) {
e.printStackTrace();
}
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
e.printStackTrace();
}
return resultFileLocation;
} catch (Exception ex) {
throw new IOException(ex);
}
}
private static PDFEncryptionParams getEncryptionParams() {
return new PDFEncryptionParams(null,
SettingUtil.getSetting(LetterGeneratorSettings.PDF_PASSWORD),
true, false, false, false, false);
}
Hier finden Sie die Inhalte meiner fopconfig.xml
<fop version="1.0">
<!-- Strict user configuration -->
<strict-configuration>false</strict-configuration>
<!-- Strict FO validation -->
<strict-validation>false</strict-validation>
<!-- Base URL for resolving relative URLs -->
<base>./</base>
<!-- Font Base URL for resolving relative font URLs -->
<font-base>./</font-base>
<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
<source-resolution>72</source-resolution>
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
<target-resolution>72</target-resolution>
<!-- default page-height and page-width, in case
value is specified as auto -->
<default-page-settings height="11in" width="8.26in"/>
<!-- etc. etc..... -->
</fop>
Was ist die Version Sie verwenden? Und haben Sie irgendeine fop.conf-Datei, in der Sie alle Einstellungen überschreiben, während Sie eine Einstellungsdatei übergeben, während Sie die FopFactory sofort starten? –
Hinzugefügt die zusätzliche Information, Anida. – Kristof
Muss die Transformation zum Bildinhalt während der FOP-Transformation erfolgen oder ist ein Nachverarbeitungsschritt, z. mit apache pdfbox ok, auch? – mkl