Hi,

I've been doing this successfully with JavaMail and iText. Just create a
MimeBodyPart containing the data. Some example code:

// You have a ByteArrayOutputStream containing the PDF called pdf. You have
called iText's document.close() to finish the PDF generation.

String applicationType = "application/pdf";
MimeBodyPart bp = new MimeBodyPart();
bp.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf.toByteArray(),
applicationType)));
bp.setFileName("My PDF File.pdf");

MimeMultipart wholeEmail = new MimeMultipart();
// Add your other MimeBodyParts (covering email etc)
wholeEmail.addBodyPart(bp);

// Actual JavaMail setup stuff skipped
Session session = Session.getDefaultInstance();
MimeMessage msg = new MimeMessage(session);
msg.setContent(wholeEmail);
// Set your other to/froms etc etc and send it.

Regards,

John.
http://www.winbolo.com/



----- Original Message -----
From: "Paul Black" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, August 27, 2002 1:15 AM
Subject: [iText-questions] Output a PDF directly to a email attachment with
a correct MIME type


I've been on the javasoft web site and searched yahoo! but no-one seems to
know how to over come this.... loads of folk want to find a solution !-)

Very simply, I want to create a PDF and attach it to an email using JavaMail
(mail.jar, activation.jar etc).

I can create the PDF to a file then attach that without a problem; but when
trying to attach the PDF directly from a ByteArrayOutputStream (ie. in
memory - from another Class that creates the PDF to an OutputStream) to a
BodyPart using the setDataHandler(...) etc it fails with exceptions relating
to unsupported DCH. I can convert the output to a StringBuffer the
.toString(), then set the type as text/plain and the email is sent - only
the PDF is corrupt (it has bytes 0a 0d in place of 0a for newlines?).
There's a file in the activation.jar - mimetypes.default that has some mime
types listed but not application/pdf.... I don't know why there are so few
types in there.

I know this isn't really related to the iText library, but it is useful to
be able to attach a PDF and send it via email.
Thanks for any help (especially code snippets!).

Paul

Paul Black
B.Eng (Hons) Software Engineering

Advocates Library - IT Department, Parliament House, EDINBURGH, EH1 1RF


**********************************************************************
Visit our website at http://www.advocates.org.uk

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.  [EMAIL PROTECTED]

This footnote also confirms that this email message has been
swept for the presence of computer viruses.
**********************************************************************




-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to