cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
106 stars 62 forks source link

Inconsistent base64 return values #113

Closed michaelschneiderdaimler closed 4 years ago

michaelschneiderdaimler commented 4 years ago

Hi,

we're using your plugin in an iOS app. We observed that if pass the same input to the plugin several times, we get different result base64 strings. The generated PDF looks consistent, but we are wondering what the cause for this behaviour could be. We want to generate some critical packaging labels, so we need to be sure that the plugin behaves somewhat consistently - any idea what is going on? I didn't find anything by digging through the code... Input: pdf.fromData('<style type="text/css">.clara {color: blue; font-weight: lighter; font-family: Arial, Helvetica}</style><html><div class="clara">Hello from Stuttgart!</div><div>Hallo aus Deutschland ... </div></html>', { documentSize: 'A4', type: 'base64'}).then(function(res) { console.log(res) })

Result: pdf-result-1.txt pdf-result-2.txt

cesarvr commented 4 years ago

Hey @michaelschneiderdaimler ,

It's going to be difficult to achieve accuracy at byte level between the same PDF, because the PDF API (used by the browser behind the scenes) adds arbitrary metadata values (like dates, prefixes, etc) in the PDF script code that internally defines the final document. If you transform this base64 into a PDF script you will find that objects in the PDF script are not even (sometimes) defined in the same order, which explains the difference in Base64 results.

On the other hand the visual accuracy will be there because that's the purpose of PDF technology.

Example:

Block of text defined internally in different order with arbitrary prefixes:

Screenshot 2020-03-15 at 13 24 31

Visual representation of the files:

Screenshot 2020-03-15 at 13 26 59 Screenshot 2020-03-15 at 13 27 16

Hope it helps.

michaelschneiderdaimler commented 4 years ago

Hi Cesar, many thanks for the explanation! We were already suspecting that some dynamic stuff was inserted in the PDF, but since I found no such code neither in the plugin nor in the native code, I was wondering where that happened.

I'm closing the issue.

Best regards michael