You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to add a comment to PDF with cyrillic letters.
How did you attempt to do it?
constcommentAnnotRef=this.pdfDocument.context.register(this.pdfDocument.context.obj({Type: 'Annot',Subtype: 'Text',Open: true,Name: 'Comment',// Determines the icon to place in the documentT: PDFString.of('abc абві äüöß'),// Comment titleContents: PDFString.of('abc абві äüöß'),// Comment main text// The position of the annotationRect: [xCoordinate,pageHeight-yCoordinate,xCoordinate,pageHeight-yCoordinate,],}))
What actually happened?
It turned out that one-byte per characters is used under the hood (see the result on the screenshot)
What did you expect to happen?
I expected UTF-8 characters to work correctly.
How can we reproduce the issue?
Try to add the comment to PDF file using the code I've provided
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
My report includes a Short, Self Contained, Correct (Compilable) Example.
I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response
The text was updated successfully, but these errors were encountered:
I've tried to come up with the custom PDFUnicodeString class but it didn't worked out:
exportclassPDFUnicodeStringextendsPDFObject{// The PDF spec allows newlines and parens to appear directly within a literal// string. These character _may_ be escaped. But they do not _have_ to be. So// for simplicity, we will not bother escaping them.staticof=(value: string)=>newPDFUnicodeString(value);privatereadonlyvalue: string;privateconstructor(value: string){super();this.value=value;}asBytes(): Uint8Array{returnnewTextEncoder().encode(this.value)}asString(): string{returnthis.value;}clone(): PDFUnicodeString{returnPDFUnicodeString.of(this.value);}toString(): string{return`(${this.value})`;}sizeInBytes(): number{returnnewTextEncoder().encode(this.value).length+2;}copyBytesInto(buffer: Uint8Array,offset: number): number{buffer[offset++]=40;constencodedValue=newTextEncoder().encode(this.value);buffer.set(encodedValue,offset);offset+=encodedValue.length;buffer[offset++]=41;returnencodedValue.length+2;}}
What were you trying to do?
I was trying to add a comment to PDF with cyrillic letters.
How did you attempt to do it?
What actually happened?
It turned out that one-byte per characters is used under the hood (see the result on the screenshot)
What did you expect to happen?
I expected UTF-8 characters to work correctly.
How can we reproduce the issue?
Try to add the comment to PDF file using the code I've provided
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
Additional Notes
No response
The text was updated successfully, but these errors were encountered: