Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Feb 28, 2024 4:43 pm

Hello

How can I set to enable "LTV" Offline Verification ?

The timestamp server was configured - see below:

Code: Select all
 ...
 signature.DistinguishedNameLabel = "DN: ";
 signature.DistinguishedName = signature.Certificate.IssuerName.Name;
               

 // configure a timestamp server url rfc3161
 string url = "http://timestamp.digicert.com";
 signature.ConfigureTimestamp(url);

...

kivgotha
 
Posts: 3
Joined: Tue Feb 13, 2024 2:14 pm

Thu Feb 29, 2024 7:05 am

Hello,

Thank you for your inquiry.
Based on your description, I have conducted preliminary testing on your code. However, I noticed that the signature fields in the resulting file have been enabled with "LTV," as depicted in the screenshot. I utilized the Spire.PDF Pack (Hot Fix) Version: 10.2.2 for my testing. Could you confirm if you are also using this version in your implementation? If not, I recommend upgrading to this version before conducting further tests. I have sent the testing code and resulting file to you via email for your review.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Sep 11, 2024 5:11 pm

I am using Spire.PDF 10.8.1 and adding the code above does not enable LTV on signatures for me. Below is the code I'm using to create a PdfSignature:

Code: Select all
       
        PdfCertificate cert = new PdfCertificate(certificatePath, certificatePassword);
        var signature = new PdfSignature(doc, doc.Pages[0], cert, Constants.DOCUMENT_SIGNING_CERTIFCATE_SIGNATURE_NAME);

        signature.DistinguishedNameLabel = "DN: ";
        signature.DistinguishedName = signature.Certificate.IssuerName.Name;

        string url = @"https://freetsa.org/tsr";
        signature.ConfigureTimestamp(url);

        signature.Certificated = true;
        signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;

jperkinsSC
 
Posts: 95
Joined: Thu Oct 30, 2014 10:01 pm

Thu Sep 12, 2024 6:21 am

Hello,jperkinsSC

Thanks for your inquiry.
I used your code to sign the PDF document, and the result shows that everything is normal (LTV is enabled). You can try adding 'signature.ConfigureHttpOCSP(null, null)' at the location marked in the screenshot below. Finally, if the problem still persists, you can provide us with your certificate (include password) that can reproduce your problem to help us investigate in detail. You can send it to us via email( [email protected] ). Thank you in advance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 306
Joined: Mon Jul 15, 2024 5:40 am

Thu Sep 12, 2024 4:52 pm

I'm still getting the same result after adding the line of code you suggested. I can't share the PFX file and password as they are being used in production. However, I can share a sample PDF that was created as a result of my code. I hope that helps. Also, do you have any specific documentation or tutorials other than this thread that describes enabling LTV? I haven't been successful in finding any other information than this.

jperkinsSC
 
Posts: 95
Joined: Thu Oct 30, 2014 10:01 pm

Fri Sep 13, 2024 10:07 am

Hello,

Thanks for your feedback.
It is true that LTV has not been enabled in your document. What is the situation after signing your certificate directly using the PDF reading tool, such as Adobe? Below is my complete test code, attached is my test result document. You can use this code to test your certificate and let me know your test results.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"test.pdf");
// Get the first page
PdfPageBase page = doc.Pages[0];
// Load a certificate .pfx file
String pfxPath = @"bbb.pfx";
PdfCertificate cer = new PdfCertificate(pfxPath, "****");
// Add a signature to the specified position
Spire.Pdf.Security.PdfSignature signature = new Spire.Pdf.Security.PdfSignature(doc, page, cer, "signature");
signature.Bounds = new RectangleF(new PointF(90, 550), new SizeF(180, 90));
// Set the signature content
signature.NameLabel = "Digitally signed by: Gary";
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "CN";
signature.ReasonLabel = "Reason: ";
signature.Reason = "Ensure authenticity";
signature.ContactInfoLabel = "Contact Number: ";
signature.ContactInfo = "028-81705109";
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
signature.Certificated = true;
signature.ConfigureTimestamp("https://freetsa.org/tsr");
signature.ConfigureHttpOCSP(null, null);
// Save the PDF file
string outputFile = @"result.pdf";
doc.SaveToFile(outputFile, Spire.Pdf.FileFormat.PDF);

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 306
Joined: Mon Jul 15, 2024 5:40 am

Wed Jan 08, 2025 8:08 am

please help me to add LTV signature, Time Stamp and 2 signature in same page in my python code.
When the second signature is added, the first signature becomes invalid.


and please add the Lock PDF option to stop adding signature and show the black Certification badge






from cryptography.hazmat.primitives.serialization import pkcs12
from cryptography.hazmat.backends import default_backend
from cryptography.x509 import NameOID
from spire.pdf.common import *
from spire.pdf import *

# Create a PdfDocument object
doc = PdfDocument()

# Load a PDF file
doc.LoadFromFile("a.pdf")

# Specify the path of the pfx certificate
pfxCertificatePath = "DS.pfx"

# Specify the password of the pdf certificate
pfxPassword = "asd"


# Load PFX file and extract CN (Common Name)
with open(pfxCertificatePath, 'rb') as pfx_file:
pfx_data = pfx_file.read()

# Convert the password to bytes
pfx_password_bytes = pfxPassword.encode('utf-8')

# Load the key and certificates
private_key, certificate, additional_certificates = pkcs12.load_key_and_certificates(
pfx_data, pfx_password_bytes
)

# Extract the CN (Common Name) from the certificate
cn = certificate.subject.get_attributes_for_oid(
NameOID.COMMON_NAME)[0].value
print("Certificate CN:", cn)

# Create a signature maker
signatureMaker = PdfOrdinarySignatureMaker(doc, pfxCertificatePath , pfxPassword)

# Show validity symbol in signature
signatureMaker.SetAcro6Layers(False)

# Get the signature
signature = signatureMaker.Signature

# Configure the signature properties like the signer's name, contact information, location and sign reason
signature.Name = f"Digitally signed by: {cn}"
signature.ContactInfo = "555666"
signature.Location = "U.S."
signature.Reason = "This is the final version."


# Create a custom signature appearance
appearance = PdfSignatureAppearance(signature)

# Set labels for the signature
appearance.ContactInfoLabel = "Phone: "
appearance.LocationLabel = "Location: "
appearance.ReasonLabel = "Reason: "

# Load an image
image = PdfImage.FromFile("./Demos/Data/E-iceblueLogo.png")

# Set the image as the signature image
appearance.SignatureImage = image

# Set the graphic mode as SignImageAndSignDetail
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail

# Get the last page
page = doc.Pages[doc.Pages.Count - 1]

# Add the signature to a specified location of the page
signatureMaker.MakeSignature("Signature by Aniket", page, 54.0, page.Size.Height - 100.0, 240.0, 80.0, appearance)

# Save the signed document
doc.SaveToFile("DisplayValiditySymbol.pdf")

# Dispose resources
doc.Dispose()

Aniketc068
 
Posts: 2
Joined: Wed Jan 08, 2025 5:52 am

Wed Jan 08, 2025 10:26 am

Hello Aniketc068,

Thank you for your inquiry. Please confirm if the attachment is the final effect you want?

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Thu Jan 09, 2025 12:48 pm

Lisa.Li wrote:Hello Aniketc068,

Thank you for your inquiry. Please confirm if the attachment is the final effect you want?

Sincerely,
Lisa
E-iceblue support team




no i modify something in the code the only feature to add in the same code is LTV enable option like True and False and same for Time stamp

give me complete code according to my code

and 1 more thing when i create the small box so why the SignDetail is not auto adjust according to box size



from cryptography.hazmat.primitives.serialization import pkcs12
from cryptography.hazmat.backends import default_backend
from cryptography.x509 import NameOID, ExtensionOID
from cryptography.x509 import ocsp, AuthorityInformationAccessOID
from cryptography.hazmat import backends
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.hashes import SHA256
from cryptography.x509 import load_der_x509_crl
from spire.pdf import PdfFont, PdfFontFamily, PdfStringFormat
from cryptography import x509
from spire.pdf.common import *
from spire.pdf import *
import datetime
import pytz

# Create a PdfDocument object
doc = PdfDocument()

# Load a PDF file
doc.LoadFromFile("b.pdf")

# Specify the path of the pfx certificate
pfxCertificatePath = "DS.pfx"

# Specify the password of the pdf certificate
pfxPassword = "asd"

# Load PFX file and extract CN (Common Name)
with open(pfxCertificatePath, 'rb') as pfx_file:
pfx_data = pfx_file.read()

# Convert the password to bytes
pfx_password_bytes = pfxPassword.encode('utf-8')

# Load the key and certificates
private_key, certificate, additional_certificates = pkcs12.load_key_and_certificates(
pfx_data, pfx_password_bytes
)

# Extract the CN (Common Name) from the certificate
cn = certificate.subject.get_attributes_for_oid(
NameOID.COMMON_NAME)[0].value


# Create a signature maker
signatureMaker = PdfOrdinarySignatureMaker(doc, pfxCertificatePath, pfxPassword)

# Show validity symbol in signature
signatureMaker.SetAcro6Layers(False)



# Extract the current date in the desired format (dd-MMM-yyyy)
current_date = datetime.datetime.now().strftime("%d-%b-%Y")

# Configure the signature properties like the signer's name, contact information, location, and sign reason
signature = signatureMaker.Signature
signature_text = f"Digitally signed by: {cn}\nDate: {current_date}\nLocation: Delhi\nReason: Sign\nCustom Text: for testing by aniket chaturvedi"


signature.Name = signature_text

# Create a custom signature appearance
appearance = PdfSignatureAppearance(signature)



# Set the graphic mode as SignImageAndSignDetail
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail



# Define which pages to sign
# You can define the page numbers or ranges as follows:
#Example: "1,6,7", "1-3", "all", "first", "last"

txn_id = "xdgfvsfd654dfsdf"

sigpage = "all"

pages_to_sign = str(sigpage) # Define the pages here. Example: "1,6,7", "1-3", "All"

pages_to_sign = pages_to_sign.lower()

# Convert page ranges into a list of page numbers
page_numbers = []
if pages_to_sign == "all":
page_numbers = list(range(1, doc.Pages.Count + 1)) # Sign all pages
elif pages_to_sign == "first":
page_numbers = [1] # Sign the first page
elif pages_to_sign == "last":
page_numbers = [doc.Pages.Count] # Sign the last page
else:
# Handle page numbers and ranges
ranges = pages_to_sign.split(",") # Split by commas
for item in ranges:
if "-" in item: # Check if it's a range (e.g., "1-3")
start, end = item.split("-")
page_numbers.extend(range(int(start), int(end) + 1))
else:
try:
page_numbers.append(int(item)) # Single page number
except ValueError:
print(f"Warning: Invalid page number or range '{item}' skipped.")



# Add the signature to all specified pages (regardless of signature field existence)
for page_num in page_numbers:
if 1 <= page_num <= doc.Pages.Count: # Ensure page number is valid
page = doc.Pages[page_num - 1] # Adjust for zero-based index

# Create a unique signature field name for each page (this won't add a new field if Signature_Fields is blank)
signatureFieldName = f"MX Signer Server {txn_id}_Page{page_num}"

# Apply the signature to the page (without creating a new signature field)
signatureMaker.MakeSignature(signatureFieldName, page, 54.0, page.Size.Height - 100.0, 240.0, 80.0, appearance)

# Save the signed document with signature fields on the selected pages
doc.SaveToFile("aniket.pdf")

# Dispose resources
doc.Dispose()

Aniketc068
 
Posts: 2
Joined: Wed Jan 08, 2025 5:52 am

Fri Jan 10, 2025 6:20 am

Hello,

Thank you for your feedback. Please use the attached code to add Timestamp, the "output.pdf" is my test result, the LTV is also enabled. You can test it with your certificate.
And, currently SignDetail does not automatically adjust based on box size,I have logged this requirement into our tracking system with SPIREPDF-7319, our Dev team will further investigate. Once it is implemented in the future, we will notify you of the corresponding version.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Tue Jul 21, 2026 1:54 am

Hello,

We are pleased to inform you that our latest version(Spire.PDF for Python Version:12.7.0) includes optimizations for the SPIREPDF-7319 issue. You can refer to the settings below to make the signature SignDetail adapt automatically based on the box size.
Code: Select all
appearance.SignImageLayout = SignImageLayout.Stretch
appearance.AutoFontSize=True


If you have any further questions, please do not hesitate to contact.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF