2012-06-16 2 views
1

아래 코드는 제 코드입니다. 내 목표는 최종 사용자가 텍스트 복사 (텍스트 선택 및 메모장에 복사 제외)를 원하는 모든 작업을 수행 할 수있는 PDF를 작성하는 것입니다. 18 번째 줄에 어떤 코드가 올지 설명 할 수 있습니까? 나는 인쇄를 허용하지만 ALLOW_COPY는 허용하지 않음)PDF (iText)를 보호하려고 시도하고 사용자가 PDF의 내용을 복사하지 못하게하려고합니다.

나는 아래의 코드가 사용자를 제한하기에 충분하지만 '사실상'선택된 텍스트를 복사하여 메모장에 붙여 넣을 수 있다는 인상을 받았다.

감사합니다.

package com.itext; 

import java.io.FileOutputStream; 
import com.itextpdf.text.Document; 
import com.itextpdf.text.Paragraph; 
import com.itextpdf.text.pdf.PdfWriter; 
import java.io.IOException; 
import com.itextpdf.text.DocumentException; 

public class ProtectMePdf 
{ 
public static void main(String[] args) throws IOException, DocumentException 
{ 
    Document document = new Document(); 
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/Users/adhg/protectMe.pdf")); 

    //LINE 18: what's wrong with this line? - if you run the code you will be able to copy the selected text. 
    writer.setEncryption(null, null, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128); 


    writer.createXmpMetadata(); 
    document.open(); 
    document.add(new Paragraph("Protect me! if you can do copy-paste of this message to a notepad = NO GOOD :-(")); 
    document.close(); 
} 
} 
+0

확인, 난 그냥 (ALLOW_DEGRADED_PRINTING로 대체) 인쇄를 제거하고 그것을 듣고 다행 트릭 – adhg

+0

, GL의 HF를 수행합니다 : 그것은 매우 간단합니다, 당신은 권한을 부정해야한다. – rlegendi

+0

감사합니다. 당신은 당신의 대답을 게시 할 수 있고 당신에게 신용을 줄 것입니다! 다시 감사드립니다! – adhg

답변

2

나는 iText를하고 PDF 사양의 전문가는 아니지만 동시에 인쇄 및 비활성화 사본 & 붙여 넣기를 허용하지 수 있다고 생각합니다. additional info here을 찾을 수 있습니다.

대체 옵션은 PDF에 이미지를 넣는 것이지만 OCR은이를 회피하기 위해 다소 개선되었습니다.

3

허용되는 대답이 잘못되었습니다. 사실 복사를 비활성화하고 인쇄를 허용 할 수 있습니다.

writer.setEncryption(null, null, ~(PdfWriter.ALLOW_COPY), PdfWriter.STANDARD_ENCRYPTION_128);