As I received no replies and others have expressed interest in this, I'll share what I did.
1. Get the iTextSharp.dll from
http://sourceforge.net/projects/itextsharp/ I'd rather do it all with PDFSharp (if there were a way), but this works.
2. Add a reference to this DLL to your C# project and add these using statements:
// iTextSharp is used to add attachment to PDF
using iTextSharp.text;
using iTextSharp.text.pdf;
3. Add this method where needed:
/// <summary>
/// Attach a file to an existing PDF document.
/// </summary>
/// <param name="existingFileName">Full name of existing file.</param>
/// <param name="newFileName">Full name of new PDF file that will be created.</param>
/// <param name="attachmentFileName">Full name of attachment file.</param>
/// <returns>True on success, false otherwise.</returns>
bool addAttachmentToPdf(string existingFileName, string newFileName, string attachmentFileName)
{
bool ok = false;
try
{
PdfReader reader = new PdfReader(existingFileName);
FileStream outputstream = new FileStream(newFileName, FileMode.Create);
PdfStamper stamp = new PdfStamper(reader, outputstream);
PdfWriter writer = stamp.Writer;
PdfFileSpecification pdfAttch = PdfFileSpecification.FileEmbedded(writer, attachmentFileName, attachmentFileName, null);
stamp.AddFileAttachment(attachmentFileName, pdfAttch);
stamp.Close();
ok = true;
}
catch
{
// ignore
}
return ok;
}
4. Call the above. You can then delete the original PDF and attached file if necessary.