If we add a line to the pdf, where we will pass the contents to a text Input when generate the pdf, we can open it without problems . But if you send it as an email attachment, abode reader gives us an error:
"Adobe Reader can not open pdfFile.pdf because it is not a supported type or damaged (eg sent as email attachment and was not correctly decoded) file"
private funcion generatePdf():void
{
import org.purepdf.elements.Paragraph;
import org.purepdf.pdf.PageSize;
import org.purepdf.pdf.PdfDocument;
import org.purepdf.pdf.PdfWriter;
import org.purepdf.pdf.fonts.BaseFont;
import org.purepdf.pdf.fonts.FontsResourceFactory;
import org.purepdf.resources.BuiltinFonts;
FontsResourceFactory.getInstance().registerFont(BaseFont.HELVETICA, new BuiltinFonts.HELVETICA());
var bytes:ByteArray = new ByteArray();
var writer:PdfWriter = PdfWriter.create(bytes, PageSize.A4);
var document:PdfDocument = writer.pdfDocument;
document.open();
var problematicLine:String = "Hello this line, dont work " + nameIn.text; /* textInput */
document.add(new Paragraph("HELLO THIS WORK OK"));
document.add(new Paragraph(problematicLine)); /* if quit this line, everything works fine */
document.close();
/* Save */
var fileStream:FileStream = new FileStream();
var file:File = File.createTempDirectory();
file = File.applicationStorageDirectory.resolvePath(namePdf.Pdf);
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(bytes);
fileStream.close();
sendPdf();
} /* end function generatePdf */
private function sendPdf():void
{
var encoder:Base64Encoder;
var bytes:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
file = File.applicationStorageDirectory.resolvePath(namePdf.Pdf);
stream.open(file, FileMode.READ);
stream.readBytes(bytes,0,stream.bytesAvailable);
stream.close();
encoder = new Base64Encoder();
encoder.encodeBytes(bytes, 0, bytes.length);
myMailer.authenticate(userSmtp, passSmtp);
myMailer.sendAttachedMail("
a...@aaa.es", "
b...@bbb.es", "upssss", "<b>HELLO ATT pdf</b>", bytes, namePdf.Pdf);
}