You can save the PDF on the server and then send the download URL back to client. To do so, you can update the code as follows:
1. Create a
FileStream
object with path where file is to be saved.
2. Create
Document
object and create your file.
3. Create a
PDFWriter
object to save it to disk.
4. Get the file location (you would already have it since you need to mention that while creating
FileStream
) and return that from your service.
Create -> FileStream
Create -> Document
Create -> PDFWriter using GetInstance method and objects created above
Open -> Document
Write -> Content to Document
Close -> Document
Close -> Writer
Close -> FileStream
Dispose -> All disposable objects
Return -> File URL
On client side, use this URL to download file.
Alternate approach: Use
MemoryStream
instead of
FileStream
and use that object to get byte array. Then, write this byte array to output.
Here[
^] is a link I just found to send PDF content as bytes.