In the same performance assessment mentioned in Watching your network traffic, no
data was sent back to the client browser until the entire PDF report had
been generated. This was also observed by watching network traffic. When using PDFLib,
you can generate PDF data directly in memory (instead of in a
temporary file. Then, you can send each page of the report to the client as it is
generated. The benefits of this method include:
- Network performance is better, especially for larger reports or over
slower network connections. The first page can be sent before the entire
report has been generated. As soon as the
first page is ready, it is sent back to the client.
- Memory requirements on the server are reduced.
- The need for temporary files is avoided.
By making a few small changes to the application, you can
implement this streaming of the reports as they are generated.
Ideally, the first page of the report is displayed as soon as it
is received by the client browser. Limitations of the PDF
format in use make this impossible. Adobe Acrobat Reader does support a
Web-optimized PDF format that is more suitable in this instance.
As of this assessment, PDFLib does not support output in this
Tip: Be careful not to send content back in blocks
that are too small. You don't want to generate a large amount of extra
network traffic. In the application mentioned above, sending back one PDF
page at a time was a reasonable compromise between frequency of
data sent back to the client and size of the data returned.