Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

Save string to to PDF: Charset encoding issue?

I'm trying to save a string as a file (pdf), but it seems the encoding isn't what it seems.

I'm wondering if anyone knows what char encoding or converting is required for the following snippet?

%PDF-1.3
%????
1 0 obj
<</Title (Faktura 0)/Producer (ComponentOne C1Pdf)/CreationDate (D:20210122122339+01'00')/ModDate (D:20210122122339+01'00')>>
endobj
2 0 obj
<</Length 1789/Filter /FlateDecode>>stream
x??w6PH/??2P0? w=S?r ????LM|?c??^.css=K##3V(J??
...more pdf code.
question from:https://stackoverflow.com/questions/65844634/save-string-to-to-pdf-charset-encoding-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

PDF is a binary format, and reading binary data into a string depending on the encoding assumed in that reading can damage the binary data.

Thus, if possible, don't retrieve the data as a string but instead as a byte array or byte buffer and store these bytes as they are.

As you confirmed in a comment,

I just received a array buffer and then wrote to file. It's working now!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...