Вы можете создать PDF-файл на лету, не записывая его на диск.Вместо использования FileStream используйте MemoryString:
'PDF Document'
Dim document As New Document(PageSize.LETTER)
'Use a memory string so we don't need to write to disk
Using outputStream As New MemoryStream()
'Associate the PDF with the stream
Dim w = PdfWriter.GetInstance(document, outputStream)
'Open the PDF for writing'
document.Open()
'Do PDF stuff Here'
'Close the PDF'
document.Close()
'Clear the response buffer'
Response.Clear()
'Set the output type as a PDF'
Response.ContentType = "application/pdf"
'Disable caching'
Response.AddHeader("Expires", "0")
Response.AddHeader("Cache-Control", "")
'Set the filename'
Response.AddHeader("Content-Disposition", "attachment; filename=" & OutputFileName)
'Set the length of the file so the browser can display an accurate progress bar'
Response.AddHeader("Content-length", outputStream.GetBuffer().Length.ToString())
'Write the contents of the memory stream'
Response.OutputStream.Write(outputStream.GetBuffer(), 0, outputStream.GetBuffer().Length)
'Close the response stream'
Response.End()
End Using
iTextSharp очень и очень быстр для меня.Я на общем хосте и могу создавать довольно сложные PDF-файлы из десятков страниц, не замечая никакой медлительности.
EDIT Вот код, преобразованный с использованием VB.Net в C # конвертер.Я не проверял это, и вам, возможно, придется очистить пару вещей, но это должно быть довольно просто.
Document document = new Document(PageSize.LETTER);
//Use a memory string so we don't need to write to disk
using (MemoryStream outputStream = new MemoryStream()) {
//Associate the PDF with the stream
dynamic w = PdfWriter.GetInstance(document, outputStream);
//Open the PDF for writing'
document.Open();
//Do PDF stuff Here'
//Close the PDF'
document.Close();
//Clear the response buffer'
Response.Clear();
//Set the output type as a PDF'
Response.ContentType = "application/pdf";
//Disable caching'
Response.AddHeader("Expires", "0");
Response.AddHeader("Cache-Control", "");
//Set the filename'
Response.AddHeader("Content-Disposition", "attachment; filename=" + OutputFileName);
//Set the length of the file so the browser can display an accurate progress bar'
Response.AddHeader("Content-length", outputStream.GetBuffer().Length.ToString());
//Write the contents of the memory stream'
Response.OutputStream.Write(outputStream.GetBuffer(), 0, outputStream.GetBuffer().Length);
//Close the response stream'
Response.End();
}
Чтобы открыть PDF в новом окне, сделайте так, чтобы ваша кнопка ссылки указывала на страницутакие как «CreatePDF.aspx».На этой странице должен быть этот код.