2015-12-03 8 views
8

現在、Apache FOPライブラリを使用してPDFを生成しています。私はこれらのPDFをコピー&ペーストから保護したいので、人々は実際のOCRライブラリ(または手入力)を使ってPDFに関する情報を入手しなければなりません。PDFを保護する

FOPは明らかに印刷やコピーなどのことから保護するためにmeta-dataとして追加されていますが、正しく動作しないようです(印刷時にコピー貼り付けを無効にできません)。有効にするなど)。

私にとってまっすぐに見える可能性は、基本的にPDFのすべてのテキストをイメージに変換していますが、その問題に関する情報は見つけられません。

明らかに、PDFが検索可能かどうかは気にしません。私はちょうど彼らがまだそれを印刷することができるべきである間、人々がコピー貼り付けることを防ぎたいです。

私の現在のFOPコード:以下

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); 
} 

は私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> 
+0

についてバックしばらく前に書いたチュートリアル?また、FopFactoryのインスタンシング中に設定ファイルを渡しているときに、設定を上書きするfop.confファイルがありますか? –

+0

追加情報Anidaが追加されました。 – Kristof

+0

画像コンテンツへの変換は、フォップ変換の際に行わなければならないか、または後処理ステップである。 apache pdfboxもOKですか? – mkl

答えて

関連する問題