简体   繁体   English

iText - 阅读使用未知随机所有者密码创建的PDF

[英]iText - read PDFs created with an unknown random owner password

I'm getting the following exception when excecuting this code: 在执行此代码时,我收到以下异常:

public byte[] watermarking(byte[] orig) throws IOException {
        PdfReader pdfReader = new PdfReader(orig);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfStamper pdfStamper = null;

        try {
            pdfStamper = new PdfStamper(pdfReader, baos); //exc here
            ...
            }
            ...
        } catch (DocumentException var8) {
            ...
        }
    }

Exception: 例外:

11:43:11,094 ERROR [de.mlp.xbg.pa.rest.SessionRR] (http-/127.0.0.1:8081-6) PdfReader not opened with owner password: java.lang.IllegalArgumentException: PdfReader not opened with owner password

I checked other threads regarding this topic and it seems that the easiest solution is to add PdfReader.unethicalreading = true; 我检查了关于这个主题的其他线程,似乎最简单的解决方案是添加PdfReader.unethicalreading = true;

However, I'm forced to use iText 2.1.7 or older ( com.lowagie iText) and not iText 5.0.0 or newer ( com.itextpdf iText) . 但是,我被迫使用iText 2.1.7或更早版本com.lowagie iText)而不是iText 5.0.0或更新版本com.itextpdf iText) PdfReader.unethicalreading does not exist in the old version of the library. 旧版本的库中不存在PdfReader.unethicalreading

Here there seems to be a workaround to make iText to ignore password with a disclaimer : 这里似乎有一个解决方法,使iText忽略密码与免责声明

I leave legal issues up to you by executing the code below. 通过执行以下代码将法律问题留给您

public static PdfReader unlockPdf(PdfReader reader) {
    if (reader == null) {
        return reader;
    }
    try {
        java.lang.reflect.Field f = reader.getClass().getDeclaredField("encrypted");
        f.setAccessible(true);
        f.set(reader, false);
    } catch (Exception e) { /* ignore */ }
    return reader;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM