PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Add attachment to PDF
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1528
Page 1 of 1

Author:  dcowan [ Sat Feb 05, 2011 3:50 pm ]
Post subject:  Add attachment to PDF

I want to attach a .csv file to the PDF file I'm generating so that the recipient can view it using the paper clip of Adobe Reader.
I've seen a number of others ask this question or something similar - but there was never a reply to any of them.
Presume this means it can't be done?

Dick

Author:  dcowan [ Wed Feb 09, 2011 6:35 pm ]
Post subject:  Re: Add attachment to PDF

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.

Author:  dominiclouis [ Tue Jun 21, 2011 10:40 am ]
Post subject:  How to use pdfsharp in my project

hi
I'm in new in PDFSharp. Now I downloaded PDFSharp . But I cannot understand how to use that in my project.
For using that in project,i want the dlls .but I can;t find any dlls in that downloaded zip file. Can you please help me
Thanks in Advance

Dominic Louis
Bangalore

Author:  Thomas Hoevel [ Tue Jun 21, 2011 12:56 pm ]
Post subject:  Re: How to use pdfsharp in my project

dominiclouis wrote:
For using that in project,i want the dlls .but I can;t find any dlls in that downloaded zip file.

Solution: download the correct file.

viewtopic.php?p=913#p913

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/