The PDF Document Hex String generated by postgres is like:

%PDF-1.5\015\012%\265\265\265\265\015\0121 0 obj\015\012<</Type/Catalog/Pages 2 0 R/Lang(en-IN) /StructTreeRoot 32 0 R/MarkInfo<</Marked true>>>>\015\012endobj\015\0122 0 obj\015\012<</Type/Pages/Count 4/Kids[ 3 0 R 15 0 R 22 0 R 29 0 R] >>\015\012endobj\015\0123 0 obj\015\012<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R/F2 7 0 R/F3 9 0 R/F4 13 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 11 0 R 12 0 R] /MediaBox[ 0 0 595.32 841.92] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>\015\012endobj\015\0124 0 obj\015\012<</Filter/FlateDecode/Length 2984>>\015\012stream\015\012x\234\225Z\333\216\3436\022}o`\376A\217\322\242\315\026\305\213$ \010v\347\026\314b\263\023$\363\026\354\203\332\226\335F\273eG\266{\322\177\277UER"eK\326`\320\036\233\227b\261Xu\352\024\245\350\341\267\350\247\237\036~\375\360\345c\224\376\374s\364\376\343\207\350\375\267ww\017\237y\304\263\350\333\372\335\035\217R\370\307\243L\244L\252(/%S\320\363\362\356.\2156\370\361\313\273\273?\343\317\211\212\177O\026\322||\215\336\343\177\377Jd\374\337_\222\205\246o\377I\362\370+t\347\361\247\344\177\321\267\177\277\273\373\004+\341jn\011!3\246s\177\211?\343\310\033\033}\372\365C\024y*sOe'\244P,Oe\224\347%+\2129B\262+Btn\204h\305\204\266B\370\210\3269\214)\006c\331`\354\303\347lhO\320\357b\211\350b\332\3051\270\355\371\323\276%\013\021\357\223E\026GU"\342W\374\330\202\305w\360\027\235\260\363\011Zj\374r\271\202\030\256\300u\312T\021\256\260\256\226\333\035\212$io\021|j\263\342\032\277\253\370\320b\307v\337\232E\026"\217\217\260\346\262E?8\237\266\015\316\2212\256\232\025\366\026\324{\250\3217j\020\273z3s\214\030\022\274\254\321Up\030\376m\233\204\313xs\333>\022\317]\207\332\337\243\035\022\236\305\317\370\261EI\015\310\\%\\\200\215\340\327\333\320,Ck\253\224\345V\330\261nV\011\355\221\027y\\\321\377:~\251`\215m\262P\306\350\246\363\004_\315\261\300\357\322\374\266'\301;\011hU#\360\302G\3778TM\347\246\342\212\233fY\301R\345\251g\232\333\215\373\366;\005gu@\305\016\211 \345\232\221\275f\2323\236\007{]\214\016\325L\205C

How to convert it to byte array?

share|improve this question

36% accept rate
feedback

1 Answer

up vote 0 down vote accepted

It isn't HEX it is escaped raw bytea. Details about this encoding here.

If you want to get HEX from bytea field use encode(bytea_field, 'HEX'). Details here.

UPD It could be better to encode(bytea_field, 'base64') and then convert base64 string into file. Details here.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.