Unable to show Json contents inside pre tag properly using jsPDF library


But I need json content in PDF look like the json content in Webpage.
Currently I am using jsPDF library to do it.

Can anybody suggest how to get this done (using jsPDF or some other package).


How are you adding your JSON to your PDF - are you using something like JSON.stringify? If so maybe try leveraging its pretty-print capabilities like:

JSON.stringify(someObject, null, 2); // Pretty-print with 2 spaces

Otherwise the jsPDF library might have an issue with maintaining line breaks within pre tags, but I don’t see any open issues relating to this.


Firstly I added Json as string in column in mongodb in given format [\r\n {\r\n “_id” : “QcyoBnkFKhXMpssJB”, \r\n “number” : “006”, \r\n “address” : “GTB nagar metro station”, \r\n “city” : “New Delhi”, \r\n “postalCode” : “110009”, \r\n “photoId” : “Lz4b84zp7KPFEBt4z”, \r\n “geocode” : {\r\n “formatted_address” : “GTB nagar metro station, OutramLines, MukherjeeNagar,NewDelhi, Delhi110009,India”, \r\n “lat” : 28.6984428, \r\n “lng” : 77.20739400000002, \r\n “place_id” : “ChIJhWJrFe79DDkRu8KpIpOIIZ8”\r\n }\r\n }\r\n ]",

then I used

 to show on html