com.ironsoftware.ironpdf.internal.staticapi.Signature_Api Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ironpdf Show documentation
Show all versions of ironpdf Show documentation
IronPDF Java library offers an extensive compatibility range, making it a go-to solution for a wide array of developers. It fully supports JVM languages like Java, Scala, and Kotlin, making it incredibly versatile. This Java PDF library is also compatible with Java 8 and above, providing optimum performance across multiple platforms. It's been designed with a wide range of users in mind Here's a look at what it supports: JVM Languages: Java, Scala, Kotlin.Platforms: Java 8 and above.Operating Systems: Microsoft Windows, Linux, Docker, Azure, AWS.IDEs: Jetbrains IntelliJ IDEA, Eclipse. You can deploy IronPDF Java across various platforms, including Microsoft Windows, Linux, Docker, Azure, and AWS. It is also fully compatible with popular IDEs like Jetbrains IntelliJ IDEA and Eclipse, facilitating smooth project development and management. Your pom.xml file is essentially the backbone of your project when you're using Maven. It's here where you introduce new dependencies that you wish to include. To make IronPDF Java package a part of your Maven project, you simply need to add the following snippets to your pom.xml: Remember to replace '20xx.xx.xxxx' with the latest version of IronPDF. IronPDF Java simplifies the process of creating PDF files. Convert HTML files, HTML strings, or URLs directly to new PDF documents in a few lines of code. The variety of file formats it handles is vast, as it can even transform images into PDF documents and vice versa. Need to use base 64 encoding, base URLs, or custom file paths? No problem! IronPDF Java has got you coveredFor more detail about installing and using IronPDF Java. When you run your project for the first time post-integration, IronPDF's engine binaries will automatically be downloaded. The engine starts its journey when you call any IronPDF function for the first time and takes a breather when your application is either closed or enters an idle state. It is not an open source java PDF library but here's the best part - IronPDF Java is offering a 30-day free trial. So, why wait? Give it a go and boost your PDF operations today.
package com.ironsoftware.ironpdf.internal.staticapi;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import com.ironsoftware.ironpdf.internal.proto.*;
import com.ironsoftware.ironpdf.signature.Signature;
import com.ironsoftware.ironpdf.signature.SignaturePermissions;
import com.ironsoftware.ironpdf.signature.VerifiedSignature;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public final class Signature_Api {
public static List getVerifiedSignatures(InternalPdfDocument internalPdfDocument) {
RpcClient client = Access.ensureConnection();
final CountDownLatch finishLatch = new CountDownLatch(1);
ArrayList resultChunks = new ArrayList<>();
PdfiumGetVerifiedSignatureRequestStreamP.InfoP.Builder infoP = PdfiumGetVerifiedSignatureRequestStreamP.InfoP.newBuilder();
infoP.setDocument(internalPdfDocument.remoteDocument);
StreamObserver requestStream = client.stub.pdfiumSignatureGetVerifiedSignature(new Utils_ReceivingCustomStreamObserver<>(finishLatch, resultChunks));
requestStream.onNext(PdfiumGetVerifiedSignatureRequestStreamP.newBuilder().setInfo(infoP).build());
//don't send DataChunk (pdf byte[]) and let Server get the pdf byte[] inside the server to prevent too much grpc call
requestStream.onCompleted();
Utils_Util.waitAndCheck(finishLatch, resultChunks);
if (resultChunks.size() == 0) {
throw new RuntimeException("No response from IronPdf.");
}
PdfiumGetVerifySignatureResultP res = resultChunks.stream().findFirst().get();
return Signature_Converter.fromProto(res);
}
public static int signPdfWithSignatureFile(InternalPdfDocument internalPdfDocument, Signature signature, SignaturePermissions permissions) {
RpcClient client = Access.ensureConnection();
PdfiumSignRequestStreamP.InfoP.Builder info = PdfiumSignRequestStreamP.InfoP.newBuilder();
info.setDocument(internalPdfDocument.remoteDocument);
if (signature.getSigningContact() != null) {
info.setSigningContact(signature.getSigningContact());
}
if (signature.getPassword() != null) {
info.setPassword(signature.getPassword());
}
if (signature.getSigningLocation() != null) {
info.setSigningLocation(signature.getSigningLocation());
}
if (signature.getSigningReason() != null) {
info.setSigningReason(signature.getSigningReason());
}
if (signature.getSignatureDate() != null) {
info.setSignatureDate(Timestamp.newBuilder().setSeconds(signature.getSignatureDate().getEpochSecond())
.setNanos(signature.getSignatureDate().getNano()));
}
info.setSignaturePermission(Signature_Converter.toProto(permissions));
if (signature.getTimeStampUrl() != null) {
info.setTimeStampUrl(signature.getTimeStampUrl());
}
final CountDownLatch finishLatch = new CountDownLatch(1);
ArrayList resultChunks = new ArrayList<>();
io.grpc.stub.StreamObserver requestStream =
client.stub.pdfiumSignatureSign(
new Utils_ReceivingCustomStreamObserver<>(finishLatch, resultChunks));
PdfiumSignRequestStreamP.Builder infoMsg =
PdfiumSignRequestStreamP.newBuilder();
infoMsg.setInfo(info);
requestStream.onNext(infoMsg.build());
for (Iterator it = Utils_Util.chunk(signature.getCertificateRawData()); it.hasNext(); ) {
byte[] bytes = it.next();
PdfiumSignRequestStreamP.Builder msg = PdfiumSignRequestStreamP.newBuilder();
msg.setCertificateFileBytesChunk(ByteString.copyFrom(bytes));
requestStream.onNext(msg.build());
}
if(signature.getSignatureImage() != null){
for (Iterator it = Utils_Util.chunk(signature.getSignatureImage()); it.hasNext(); ) {
byte[] bytes = it.next();
PdfiumSignRequestStreamP.Builder msg = PdfiumSignRequestStreamP.newBuilder();
msg.setSignatureImageChunk(ByteString.copyFrom(bytes));
requestStream.onNext(msg.build());
}
}
requestStream.onCompleted();
Utils_Util.waitAndCheck(finishLatch, resultChunks);
if (resultChunks.size() == 0) {
throw new RuntimeException("No response from IronPdf.");
}
PdfiumSignResultP res = resultChunks.stream().findFirst().get();
if (res.getResultOrExceptionCase() == PdfiumSignResultP.ResultOrExceptionCase.EXCEPTION) {
throw Exception_Converter.fromProto(res.getException());
}
return res.getResult();
}
public static boolean verifyPdfSignatures(InternalPdfDocument internalPdfDocument){
List sig = getVerifiedSignatures(internalPdfDocument);
boolean result = sig.stream().allMatch(VerifiedSignature::isValid);
return result;
}
public static void removeSignature(InternalPdfDocument internalPdfDocument){
RpcClient client = Access.ensureConnection();
PdfiumRemoveSignaturesRequestP.Builder req = PdfiumRemoveSignaturesRequestP.newBuilder();
req.setDocument(internalPdfDocument.remoteDocument);
final CountDownLatch finishLatch = new CountDownLatch(1);
ArrayList resultChunks = new ArrayList<>();
client.stub.pdfiumSignatureRemoveSignatures(req.build(), new Utils_ReceivingCustomStreamObserver<>(finishLatch, resultChunks));
Utils_Util.waitAndCheck(finishLatch, resultChunks);
if (resultChunks.size() == 0) {
throw new RuntimeException("No response from IronPdf.");
}
EmptyResultP res = resultChunks.stream().findFirst().get();
Utils_Util.handleEmptyResultChunks(resultChunks);
}
}