我正在使用PDFbox提取PDF文档中单词/字符串的坐标,并且到目前为止已成功确定单个字符的位置.这是迄今为止的代码,来自PDFbox doc:
package printtextlocations;
import java.io.*;
import org.apache.pdfbox.exceptions.InvalidPasswordException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDStream;
import org.apache.pdfbox.util.PDFTextStripper;
import org.apache.pdfbox.util.TextPosition;
import java.io.IOException;
import java.util.List;
public class PrintTextLocations extends PDFTextStripper {
public PrintTextLocations() throws IOException {
super.setSortByPosition(true);
}
public static void main(String[] args) throws Exception {
PDDocument document = null;
try {
File input = new File("C:\\path\\to\\PDF.pdf");
document = PDDocument.load(input);
if (document.isEncrypted()) {
try {
document.decrypt("");
} catch (InvalidPasswordException e) {
System.err.println("Error: Document is encrypted with a password.");
System.exit(1);
}
}
PrintTextLocations printer …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PHP,openssl和Zend框架(用于pdf redering/handling)构建一个简单的PDF文档签名例程.
我发现了这一点,但它根本不起作用,Zend无法打开任何pdf,甚至Zend自己的测试pdf,Zend也不会报告原因,只是它"不能".
我很确定我能够有效地创建密钥/证书,因为这有很好的文档,但有没有一种可靠的方法将生成的证书附加到PDF,因为上面的Zend扩展建议曾经这样做过?
function DigiSignPDF ($pdf_sign_request) {
if (get_magic_quotes_gpc()) {
$new_pdf = stripslashes($pdf_sign_request['raw_pdf']);
} else {
$new_pdf = $pdf_sign_request['raw_pdf'];
}
$test_pdf = stripslashes(file_get_contents('path/Some.pdf'));
$test_pdf2 = ('path/Some.pdf');
$pdf = Zend_Pdf::load($new_pdf2);
//below is the signing code, from another library, it works as long as Zend_Pdf works
$certificate = file_get_contents('path/certificate.p12');
$certificatePassword = 'test123';
if (empty($certificate)) {
throw new Zend_Pdf_Exception('Cannot retrieve/generate the certificate.');
}
$pdf->attachDigitalCertificate($certificate,$certificatePassword);
$eSig_pdf = $pdf->render();
file_put_contents('path/signed_pdf.pdf', $eSig_pdf);
}
Run Code Online (Sandbox Code Playgroud)
编辑,添加代码:以上只有在我使用'test_pdf2'作为Zend_Pdf的输入时才有效.它将证书识别为二进制文件没有任何问题,但我需要能够传递PDF而无需将其写入磁盘.
是否可以将 TCPPDF 或 FPDI PDF 作为字符串提供?我有一个传入的 PDF 数组作为字符串,但我无法写入磁盘。我无法在文档中找到任何关于此的内容。
如果没有,是否有一种有效的方法可以从内存或对象中存储/读取这些 PDF?把它们喂给 FPDI?