I try to use the code I found here
http://web.archive.org/web/20111012184438/http://alex.buayacorp.com/merge-pdf-files-with-itext-and-net.html to merge 2 or more PDF files into one.
I want to achieve that the output is returned as a stream and saved on client side. I tried to modify the code but without success. The code tries to save the output on the server which then causes an Unauthorized Access Exception.
Anyone has the right clue?
private void MergePDFs()
{
DataSourceSelectArguments args = new DataSourceSelectArguments();
DataView view = (DataView)SqlDataSource1.Select(args);
DataTable table = view.ToTable();
List<PdfReader> readerList = new List<PdfReader>();
foreach (DataRow myRow in table.Rows)
{
PdfReader pdfReader = new PdfReader(Convert.ToString(myRow[0]));
readerList.Add(pdfReader);
}
Document document = new Document();
PdfCopy copy = new PdfCopy(document, Response.OutputStream);
document.Open();
foreach (PdfReader reader in readerList)
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
copy.AddPage(copy.GetImportedPage(reader, i));
}
}
document.Close();
Response.AppendHeader("content-disposition", "inline; filename=OutPut.pdf");
Response.ContentType = "application/pdf";
}