PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 09, 2024 6:29 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Add attachment to PDF
PostPosted: Sat Feb 05, 2011 3:50 pm 
Offline

Joined: Thu Jan 06, 2011 11:47 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 09, 2011 6:35 pm 
Offline

Joined: Thu Jan 06, 2011 11:47 pm
Posts: 4
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 21, 2011 10:40 am 
Offline

Joined: Tue Jun 21, 2011 10:36 am
Posts: 1
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 21, 2011 12:56 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group