- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在单个压模上的pdf中添加多个签名。我可以添加多个压模。就我而言,我遇到了错误
至少一个签名无效。
我想在单个PDF中添加多个有效符号。请帮我。
在图片中,只有一个符号有效,其他符号无效,所以让我做错了
我的代码快照如下
public void getSignOnPdf(Map<Integer, byte[]> PdfSigneture1, List<Long> documentIds, List<String> calTimeStamp,
String originalPdfReadServerPath, String tickImagePath, int serverTime, int pageNumberToInsertStamp,
String name, String location, String reasonForSign, int xCo_ordinates, int yCo_ordinates,
int signatureWidth, int signatureHeight, String pdfPassword, String internal_outputFinalPdfPath)
throws Exception {
String pdfReadServerPath = null;
String l_slash = new String();
String originalPDFPath = new String(originalPdfReadServerPath.trim());
boolean isCorrectPDFOutputPath = false;
String aspOutputPdfServerPath = null;
synchronized (this) {
if ((internal_outputFinalPdfPath != null) && (!internal_outputFinalPdfPath.trim().isEmpty())) {
System.out.println("[" + EsignCommonFuntion.generateTimeStampForLog()
+ "] :1--> outputFinalPdfPath is: " + internal_outputFinalPdfPath);
if (!(new File(internal_outputFinalPdfPath)).isFile()) {
isCorrectPDFOutputPath = true;
aspOutputPdfServerPath = internal_outputFinalPdfPath;
} else {
System.out.println("1--> Please provide directory path for outputFinalPdfPath: "
.concat(String.valueOf(internal_outputFinalPdfPath)));
}
} else {
System.out.println(" 1--> outputFinalPdfPath is empty or null: "
.concat(String.valueOf(internal_outputFinalPdfPath)));
}
}
boolean isPasswordPresent = false;
String pdfPasswordForEncryption;
synchronized (this) {
if ((pdfPassword != null) && (!pdfPassword.trim().isEmpty())) {
pdfPasswordForEncryption = pdfPassword.trim();
isPasswordPresent = true;
} else {
pdfPasswordForEncryption = null;
}
String pdfOriginalName = (new File(originalPDFPath)).getName();
String pdfAbsolutePath = originalPDFPath.substring(0, originalPDFPath.lastIndexOf(l_slash));
if (isPasswordPresent) {
pdfAbsolutePath = getEncryptedPdfName(originalPDFPath, pdfAbsolutePath + l_slash,
pdfPasswordForEncryption, pdfOriginalName);
pdfReadServerPath = new String(pdfAbsolutePath);
} else {
pdfReadServerPath = originalPDFPath;
}
}
ArrayList<String> unSignedFilesList = new ArrayList<String>();
Map<Integer, byte[]> l_PdfSigneture = PdfSigneture1;
int actual_pageNumForStamp = 1;
String pdfFileName = (new File(pdfReadServerPath)).getName();
FileOutputStream fos = null;
String nameToShowInSignature = name;
String locationToShowInSignature = location;
String reasonForSignatureSign = reasonForSign;
PDDocument documentFinal = null;
try {
pdfReadServerPath = pdfReadServerPath.substring(0, pdfReadServerPath.lastIndexOf(l_slash));
System.out.println("inside getSignOnMethod pdfAbsolutePath:".concat(String.valueOf(pdfReadServerPath)));
unSignedFilesList.add(pdfFileName);
System.out.println("inside getSignOnMethod pdfFileName:".concat(String.valueOf(pdfFileName)));
String PDFpath = pdfReadServerPath + l_slash + (String) (unSignedFilesList).get(0);
System.out.println("Inside for PDFpath: ".concat(String.valueOf(PDFpath)));
String finalOutputPdfName = ((String) (unSignedFilesList).get(0)).substring(0,
((String) (unSignedFilesList).get(0)).lastIndexOf(".")) + "_signedFinal.pdf";
File outFile2 = null;
if (isCorrectPDFOutputPath) {
System.out.println("if condition Final signed PDF ouptut Path: " + aspOutputPdfServerPath + l_slash
+ finalOutputPdfName);
outFile2 = new File(aspOutputPdfServerPath + l_slash + finalOutputPdfName);
fos = new FileOutputStream(outFile2);
} else {
outFile2 = new File(pdfReadServerPath + l_slash + outFile2);
fos = new FileOutputStream(outFile2);
}
documentFinal = PDDocument.load(new File(PDFpath));
for (int i = 1; i < 4; i++) {
FileInputStream image2 = new FileInputStream(tickImagePath);
PDSignature pdsignature = new PDSignature();
pdsignature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
pdsignature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
Calendar cal = GregorianCalendar.getInstance();
SimpleDateFormat l_simpleDateFormater = new SimpleDateFormat("yyyyMMdd_HHmmss");
String timeStamp = (String) calTimeStamp.get(i - 1);
try {
cal.setTime(l_simpleDateFormater.parse(timeStamp));
} catch (ParseException ex) {
ex.printStackTrace();
}
cal.add(12, serverTime);
pdsignature.setSignDate(cal);
documentFinal.setDocumentId((Long) documentIds.get(i - 1));
String dateToShowInSignature = cal.getTime().toString();
Float saveIncrementalObj1 = null;
saveIncrementalObj1 = new Float((float) xCo_ordinates, (float) yCo_ordinates, (float) signatureWidth,
(float) signatureHeight);
PDRectangle rect = getPDRectangle(documentFinal, saveIncrementalObj1, i);
PDVisibleSignDesigner visibleSig;
(visibleSig = new PDVisibleSignDesigner(documentFinal, image2, i)).xAxis(xCo_ordinates)
.yAxis(yCo_ordinates).zoom(-95.0F).signatureFieldName("signature");
PDVisibleSigProperties visibleSignatureProp = new PDVisibleSigProperties();
visibleSignatureProp.signerName("name").signerLocation("location").signatureReason("Security")
.preferredSize(0).page(i - 1).visualSignEnabled(true).setPdVisibleSignature(visibleSig)
.buildSignature();
try {
PdfSigneture = new TreeMap<>();
// PdfSigneture.clear();
PdfSigneture = l_PdfSigneture;
if (visibleSignatureProp.isVisualSignEnabled()) {
this.options = new SignatureOptions();
this.options.setVisualSignature(visibleSignatureProp);
this.options.setPage(visibleSignatureProp.getPage());
this.options.setVisualSignature(
getInputStream(documentFinal, i, rect, tickImagePath, nameToShowInSignature,
locationToShowInSignature, dateToShowInSignature, reasonForSignatureSign));
documentFinal.addSignature(pdsignature, this, this.options);
} else {
documentFinal.addSignature(pdsignature, this);
}
} catch (Exception e) {
e.printStackTrace();
}
}
synchronized (this) {
SaveIncrementalSignObject saveIncrementalSignObject;
(saveIncrementalSignObject = new SaveIncrementalSignObject()).setFos(fos);
saveIncrementalSignObject.setPDDocumentFromFile(documentFinal);
saveIncrementalForSign(saveIncrementalSignObject);
}
} catch (Exception localException2) {
System.out.println("Insidemethod -- Exception block" + localException2.getMessage());
return;
} finally {
fos.flush();
if (fos != null) {
fos.close();
}
documentFinal.close();
}
}
public static synchronized void saveIncrementalForSign(SaveIncrementalSignObject p_SaveIncrementalObj) {
PDDocument documentFinal = null;
try {
(documentFinal = p_SaveIncrementalObj.getPDDocumentFromFile())
.saveIncremental(p_SaveIncrementalObj.getFos());
} catch (Exception e) {
e.printStackTrace();
try {
// documentFinal.close();
return;
} catch (Exception eX) {
eX.printStackTrace();
return;
}
}
}
最佳答案
在评论中,您阐明了要实现的目标:
我试图将一个签名应用于多个地方。
正如下面第一节中所讨论的,这不是您的代码所要做的:您的代码尝试将多个签名应用于单个修订版本中的每个签名,这在此处是不可能的。
另一方面,PDF规范团队不希望在单个修订版中的多个位置上应用单个签名,并且规范已使实现该签名的某些方法无效,但是有可能如下面第二部分所述。
您的方法,以及为什么它不起作用
您似乎试图一次通过多个签名:
if (isPasswordPresent) {
documentFinal = PDDocument.load(new File(PDFpath), pdfPasswordForEncryption);
} else {
documentFinal = PDDocument.load(new File(PDFpath));
}
for (int i = 1; i < 4; i++) {
FileInputStream image2 = new FileInputStream(tickImagePath);
PDSignature pdsignature = new PDSignature();
[...]
try {
[...]
if (visibleSignatureProp.isVisualSignEnabled()) {
[...]
documentFinal.addSignature(pdsignature, this, this.options);
} else {
documentFinal.addSignature(pdsignature, this);
}
} catch (Exception e) {
System.out.println("Inside getSignOnPdf sub exception block at addSignature:" + e + "error :" + e.getMessage());
e.printStackTrace();
}
}
synchronized (this) {
[...]
saveIncrementalForSign(saveIncrementalSignObject);
}
for (int i = 1; i < 4; i++) {
load current version of the PDF;
apply the i'th signature;
save and sign as new current version of the PDF;
}
PDDocument.addSignature
可能会引起误解,因为它可能暗示要添加多个签名。不是这种情况;所有签名将与它们的小部件一起创建为签名字段,但只有最后添加的
PDSignature
字段将实际签名,因此只有最后添加的签名字段实际上具有合理的值。
PDDocument.addSignature
中进行测试以引发异常。
PDSignature
对象并正常地使用它生成一个签名(使用
PDDocument.addSignature
),然后根据需要添加任意多个其他签名字段,并将这些字段的签名值属性设置为单个< cc>对象在开始时创建。
void addSignatureField(PDDocument pdDocument, PDPage pdPage, PDRectangle rectangle, PDSignature signature) throws IOException {
PDAcroForm acroForm = pdDocument.getDocumentCatalog().getAcroForm();
List<PDField> acroFormFields = acroForm.getFields();
PDSignatureField signatureField = new PDSignatureField(acroForm);
signatureField.setSignature(signature);
PDAnnotationWidget widget = signatureField.getWidgets().get(0);
acroFormFields.add(signatureField);
widget.setRectangle(rectangle);
widget.setPage(pdPage);
// from PDVisualSigBuilder.createHolderForm()
PDStream stream = new PDStream(pdDocument);
PDFormXObject form = new PDFormXObject(stream);
PDResources res = new PDResources();
form.setResources(res);
form.setFormType(1);
PDRectangle bbox = new PDRectangle(rectangle.getWidth(), rectangle.getHeight());
float height = bbox.getHeight();
form.setBBox(bbox);
PDFont font = PDType1Font.HELVETICA_BOLD;
// from PDVisualSigBuilder.createAppearanceDictionary()
PDAppearanceDictionary appearance = new PDAppearanceDictionary();
appearance.getCOSObject().setDirect(true);
PDAppearanceStream appearanceStream = new PDAppearanceStream(form.getCOSObject());
appearance.setNormalAppearance(appearanceStream);
widget.setAppearance(appearance);
try (PDPageContentStream cs = new PDPageContentStream(pdDocument, appearanceStream))
{
// show background (just for debugging, to see the rect size + position)
cs.setNonStrokingColor(Color.yellow);
cs.addRect(-5000, -5000, 10000, 10000);
cs.fill();
float fontSize = 10;
float leading = fontSize * 1.5f;
cs.beginText();
cs.setFont(font, fontSize);
cs.setNonStrokingColor(Color.black);
cs.newLineAtOffset(fontSize, height - leading);
cs.setLeading(leading);
cs.showText("Signature text");
cs.newLine();
cs.showText("some additional Information");
cs.newLine();
cs.showText("let's keep talking");
cs.endText();
}
pdPage.getAnnotations().add(widget);
COSDictionary pageTreeObject = pdPage.getCOSObject();
while (pageTreeObject != null) {
pageTreeObject.setNeedToBeUpdated(true);
pageTreeObject = (COSDictionary) pageTreeObject.getDictionaryObject(COSName.PARENT);
}
}
PDSignature
方法,但是经过了严重简化,现在用于创建实际的签名字段,而不仅仅是从中复制模板。)
try ( InputStream resource = PDF_SOURCE_STREAM;
OutputStream result = PDF_TARGET_STREAM;
PDDocument pdDocument = PDDocument.load(resource) )
{
PDAcroForm acroForm = pdDocument.getDocumentCatalog().getAcroForm();
if (acroForm == null) {
pdDocument.getDocumentCatalog().setAcroForm(acroForm = new PDAcroForm(pdDocument));
}
acroForm.setSignaturesExist(true);
acroForm.setAppendOnly(true);
acroForm.getCOSObject().setDirect(true);
PDRectangle rectangle = new PDRectangle(100, 600, 300, 100);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("Example User");
signature.setLocation("Los Angeles, CA");
signature.setReason("Testing");
signature.setSignDate(Calendar.getInstance());
pdDocument.addSignature(signature, this);
for (PDPage pdPage : pdDocument.getPages()) {
addSignatureField(pdDocument, pdPage, rectangle, signature);
}
pdDocument.saveIncremental(result);
}
CreateVisibleSignature2.createVisualSignatureTemplate
)
testCreateSignatureWithMultipleVisualizations
使用
this
实现
SignatureInterface
方法)。
byte[] sign(InputStream)
方法
PDSignatureField
在PDFBox 3.0.0-SNAPSHOT中已被弃用。您最终可能必须使用更多低级技术来注入
setSignature
对象。
关于java - 使用pdfbox 2.0.12 java的多个设计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52829507/
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
.NET 框架:4.5.1 我在 Blend for visual studio 2015 中遇到一个奇怪的错误,我找不到它的来源。 如果我在 VS 中打开我的 WPF 解决方案,它会加载并运行良好。
我经常遇到这样的问题,与 Hierarchical RESTful URL design 非常相似 假设该服务仅提供用户上传文档。 POST, GET /accounts PUT, DELETE /a
在 Rails 应用程序中,我使用 devise 来管理我的用户,而我用来销毁 session 的链接不再有效。它正在工作,现在我添加了事件管理员,但没有。 我的链接是 :delete, :clas
我已经坚持了超过 24 小时,试图按照此处发布的其他解决方案进行操作,但我无法使其正常工作。我是 Rails 新手,需要帮助! 我想让我的/users/edit 页面正常工作,以便我可以简单地更改用户
Devise 在以下情况下不会使用户超时: 用户登录,关闭选项卡,然后在超时 + X 分钟内重新访问该 URL。用户仍处于登录状态。 如果选项卡已打开并且稍后刷新/单击,则超时可以正常工作。这意味着
我想使用这样的 slider 我希望该 slider 根据提供给它的值进行相应调整。到目前为止,我只能应用具有渐变效果的背景,但无法获得这种效果。请通过提供样式代码来帮助我。
您应该为每种方法创建一个请求/响应对象,还是应该为每个服务创建一个? 如果我在所有方法中使用它,我的服务请求对象中将只有 5 个不同的东西,因为我对几乎所有方法使用相同的输入。 响应对象将只有一个字典
我正在尝试在 REST 中对实体的附件进行建模。假设一个缺陷实体可以附加多个附件。每个附件都有描述和一些其他属性(上次修改时间、文件大小...)。附件本身是任何格式的文件(jpeg、doc ...)
我有以下表格: Blogs { BlogName } BlogPosts { BlogName, PostTitle } 博客文章同时建模一个实体和一个关系,根据 6nf(根据第三个宣言)这是无效的。
如果 A 类与 B、C 和 D 类中的每一个都有唯一的交互,那么交互的代码应该在 A 中还是在 B、C 和 D 中? 我正在编写一个小游戏,其中许多对象可以与其他对象进行独特的交互。例如,EMP点击
关于如何记住我与 Omniauth 一起工作似乎有些困惑。 根据这个wiki ,您需要在 OmniauthCallbacksController 中包含以下内容: remember_me(user)
设计问题: 使用 非线程安全 组件(集合,API,...)在/带有 多线程成分 ... 例子 : 组件 1 :多线程套接字服务器谁向消息处理程序发送消息... 组件 2 :非线程安全 消息处理程序 谁
我们目前正在设计一个 RESTful 应用程序。我们决定使用 XML 作为我们的基本表示。 我有以下关于在 XML 中设计/建模应用程序数据的问题。 在 XML 中进行数据建模的方法有哪些?从头开始然
我正在设计一个新的 XSD 来从业务合作伙伴那里获取积分信息。对于每笔交易,合作伙伴必须提供至少一种积分类型的积分值。我有以下几点:
设计支持多个版本的 API 的最佳方法是什么。我如何确保即使我的数据架构发生更改(微小更改),我的 api 的使用者也不会受到影响?任何引用架构、指南都非常有用。 最佳答案 Mark Nottingh
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
我想用 php 创建一个网站,其工作方式与 https://www.bitcoins.lc/ 相同。确实,就每个页面上具有相同布局但内容会随着您更改链接/页面而改变而言,我如何在 php 中使用lay
我有一个关于编写 Swing UI 的问题。如果我想制作一个带有某些选项的软件,例如在第一个框架上,我有三个按钮(新建、选项、退出)。 现在,如果用户单击新按钮,我想将框架中的整个内容更改为其他内容。
我正在尝试找出并学习将应用程序拥有的一堆Docker容器移至Kubernetes的模式和最佳实践。诸如Pod设计,服务,部署之类的东西。例如,我可以创建一个其中包含单个Web和应用程序容器的Pod,但
我是一名优秀的程序员,十分优秀!