I have create Rest Service and I am trying to Generate Zip file. This Zip file created from muliple PDF files which are downloaded using method
InputStream inpuStream = new URL(url).openStream(). I am able to Generate Zip file Which included PDF files but PDF files are broken.
Even If i try to Generate it from String its coming as broken PDF and i am getting Error message "Not a supported File Type or file is broken or damaged"
I have given my code below for your reference. Could you please Guide me where I am making the mistake. Do I need to return ResponsEntity or void controller is fine.
Even If i try to Generate it from String its coming as broken PDF
PDFs are binary files, if you ever treat them as character data, they'll be broken.
new ByteArrayInputStream( "this is test to generarte pdf test file this is test tdfsfs this is test to generarte pdf test file this is test tdfsfs"
That's not a PDF, that's character data. It doesn't become a PDF by storing it in a file and giving it a .pdf file extension. You'll need to create a proper PDF somehow, and then treat it as binary data.
The proper MIME type (ContentType) for ZIP files is application/zip. The client will probably not handle a ZIP file properly otherwise. Note also that MIME types are conventionally given in lower-case, not upper-case.
While it's not immediately obvious to me, others here are of the impression that you're attempting also to create PDF files on the fly as though PDF was straight text. PDF is a rigorously-defined file format containing encapsulated PostScript commands and metadata and unless you're a REAL glutton for punishment, you need a good PDF-creation library if you want to build PDFs yourself.
If you're simply trying to package a set of uploaded PDF files into a ZIP, then you don't need a PDF library, but you do need to make sure that if there's an option for the file in the ZIP utilities that you select "binary" and not "text". PDF in its original form was indeed text. but it's not intended to be treated as text, and in particular it isn't likely to take kindly to how some utilities translate end-of-line characters when they process "text" files.
Loudly announcing something is true and finding out you're wrong makes you feel foolish.
Finding out you're wrong and refusing to admit it makes you LOOK foolish.