1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
// step 0 : Nom du fichier pdf en sortie
string OutputFileName= "FicheAgent" + strMatriculeAgent + strNomAgent +".pdf";
// step 1 : Création du document
Document document = new Document();
using (MemoryStream outputStream = new MemoryStream())
{
try
{
//récupération du template et effacement du contenu (FileMode.Create)
PdfWriter writer = PdfWriter.GetInstance(document, outputStream);
// step 2: Métadonnées
// step 3: Ouverture du document
document.Open();
// step 4: Création du contenu du document
catch (DocumentException de)
{
throw (de);
//
}
// step 5: fermeture du document
document.Close();
//step 6 : Création du fichier pdf
//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();
}
} |
Partager