-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error encoding UTF-8 characters #2
Comments
I was able to confirm the issue with this test case: func TestSignPDFFileUTF8(t *testing.T) {
certificate_data_block, _ := pem.Decode([]byte(signCertPem))
if certificate_data_block == nil {
t.Errorf("failed to parse PEM block containing the certificate")
return
}
cert, err := x509.ParseCertificate(certificate_data_block.Bytes)
if err != nil {
t.Errorf("%s", err.Error())
return
}
key_data_block, _ := pem.Decode([]byte(signKeyPem))
if key_data_block == nil {
t.Errorf("failed to parse PEM block containing the private key")
return
}
pkey, err := x509.ParsePKCS1PrivateKey(key_data_block.Bytes)
if err != nil {
t.Errorf("%s", err.Error())
return
}
tmpfile, err := os.CreateTemp("", "pdfsign_test")
if err != nil {
t.Errorf("%s", err.Error())
return
}
signerName := "姓名"
signerLocation := "位置"
err = SignFile("../testfiles/testfile20.pdf", tmpfile.Name(), SignData{
Signature: SignDataSignature{
Info: SignDataSignatureInfo{
Name: signerName,
Location: signerLocation,
Reason: "Test with UTF-8",
ContactInfo: "None",
Date: time.Now().Local(),
},
CertType: CertificationSignature,
DocMDPPerm: AllowFillingExistingFormFieldsAndSignaturesPerms,
},
DigestAlgorithm: crypto.SHA512,
Signer: pkey,
Certificate: cert,
})
if err != nil {
os.Remove(tmpfile.Name())
t.Errorf("%s: %s", "testfile20.pdf", err.Error())
return
}
info, err := verify.File(tmpfile)
if err != nil {
t.Errorf("%s: %s", tmpfile.Name(), err.Error())
err2 := os.Rename(tmpfile.Name(), "../testfiles/failed/testfile20.pdf")
if err2 != nil {
t.Error(err2)
}
} else {
if info.Signers[0].Name != signerName {
t.Errorf("expected %q, got %q", signerName, info.Signers[0].Name)
}
if info.Signers[0].Location != signerLocation {
t.Errorf("expected %q, got %q", signerLocation, info.Signers[0].Location)
}
os.Remove(tmpfile.Name())
}
} Result:
I do need to dive deeper to find what might be causing this. |
I found a way that should resolve this, but without success, although the test file from the document below doesn't seem to work in my versions of Acrobat eighter. Can you try to download this test file and check if the document properties are shown correctly for you? |
It might actually better to use UTF-16 encoding, I will do some testing with that. |
Text is now encoded with UTF-16BE encoding when required, this resolved the issue on my side, please check if your issue has been resolved for you as well. |
When adding a String with UTF-8 Symbols (for example in Location), it is shown as above.
The text was updated successfully, but these errors were encountered: