jomolungma,
Not sure how much help this will be but I did a lot of hunting before I finally figured out how to get my pdf combiner to work.
Now the way I do it is to start with a complete PDF that contains every possible page that could be included and have a check-box selector field to let users pick from a menu of pages to include. In this code behind I force all documents to use pages 1 through 3 as cover pages and page 4 (of "Main.pdf") is always the last page. After that, the pages are determined by which check-boxes are checked on the aspx page.
Not clear on how this relates to your project but I hope you might find something you can use.
Code:
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//////////////////////////// #//////////
//////////////////////////// PDFmill By #//////////
//////////////////////////// #//////////
//////////////////////////// - masodo - #//////////
//////////////////////////// #//////////
//////////////////////////// All Rights Reserved #//////////
//////////////////////////// #//////////
//////////////////////////////########################################//////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Drawing;
using PdfSharp.Pdf.Advanced;
using PdfSharp.Pdf.Security;
namespace PDFmill
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack)
{
Variant1();
}
}
string[] GetSets()
{
ArrayList list = new ArrayList();
{
// cover pages set <$$$>
list.Add("1,3");
for (int i = 0; i < Check1.Items.Count; i++)
{
if (Check1.Items[i].Selected)
{
String s = Check1.Items[i].Value;
list.Add(s);
}
}
// back pages set <$$$>
list.Add("4,4");
}
return (string[])list.ToArray(typeof(string));
}
protected void Variant1()
{
string filename = Server.MapPath("Main.pdf");
string[] files = GetSets();
PdfDocument outputDocument = new PdfDocument();
outputDocument.Info.Title = "My Custom Document";
outputDocument.Info.Author = "WhoDunnit";
foreach (string file in files)
{
string[] rNumb = file.Split(',');
string x = rNumb[0];
string y = rNumb[1];
int s = Convert.ToInt16(x);
int e = Convert.ToInt16(y);
PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Import);
for (int idx = s - 1; idx < e; idx++)
{
PdfPage page = inputDocument.Pages[idx];
outputDocument.AddPage(page);
}
}
string savefilename = "GenericFilename";
MemoryStream stream = new MemoryStream();
outputDocument.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", stream.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment;filename=" + savefilename + ".pdf");
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.End();
stream.Close();
}
}
}