我正在尝试在 android 中创建一个 pdf 文档,以便使用 android 中的 Intent 通过电子邮件发送。请任何人都可以帮助解决这个问题。我相信我的问题领域是意图,但我不完全确定。以下是我到目前为止的代码,谢谢:
private String cmail = "myselftest123@gmail.com";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apply);
firstnameTV = (TextView)findViewById(R.id.texViewFName);
firstnameET = (EditText)findViewById(R.id.editTextFName);
lastnameET = (EditText)findViewById(R.id.editTextLName);
lastnameTV = (TextView)findViewById(R.id.texViewLName);
address1TV = (TextView)findViewById(R.id.texViewAddress1);
address1ET = (EditText)findViewById(R.id.editTextAddress1);
address2TV = (TextView)findViewById(R.id.texViewAddress2);
address2ET = (EditText)findViewById(R.id.editTextAddress2);
address3TV = (TextView)findViewById(R.id.texViewAddress3);
address3ET = (EditText)findViewById(R.id.editTextAddress3);
address4TV = (TextView)findViewById(R.id.texViewAddress4);
address4ET = (EditText)findViewById(R.id.editTextAddress4);
emailTV = (TextView)findViewById(R.id.texViewEmail);
emailET = (EditText)findViewById(R.id.editTextEmail);
dobTV = (TextView)findViewById(R.id.texViewDOB);
dobET = (EditText)findViewById(R.id.editTextDOB);
submitBtn = (Button)findViewById(R.id.btnSubmit);
submitBtn.setOnClickListener(this);
entries();
addSaveData(document);
try {
addPage(document);
} catch (DocumentException e) {
e.printStackTrace();
}
}
public void entries()
{
fName = firstnameET.getText().toString();
lName = lastnameET.getText().toString();
Dob = dobET.getText().toString();
address1 = address1ET.getText().toString();
address2 = address2ET.getText().toString();
address3 = address3ET.getText().toString();
address4 = address4ET.getText().toString();
uEmail = emailET.getText().toString();
}
public void addSaveData(Document document)
{
document.addTitle("Application Form");
document.addSubject("Using iText");
document.addKeywords("App, Form");
document.addAuthor("Myself");
document.addCreator("Myself");
}
private void addLineSpace(Paragraph paragraph, int number)
{
for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" "));
}
}
private void addPage(Document document) throws DocumentException
{
Paragraph preface = new Paragraph();
addLineSpace(preface, 1);
preface.add(new Paragraph("Application Form", titleFont));
addLineSpace(preface, 1);
preface.add(new Paragraph("Form" , subTitleFont));
addLineSpace(preface, 2);
preface.add(new Paragraph("First name: " + fName, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Last name: " + lName, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Date of Birth: " + Dob, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Email " + uEmail, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Address 1 " + address1, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Address 2 " + address2, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Address 3 " + address3, normalFont) );
addLineSpace(preface, 1);
preface.add(new Paragraph("Address 4 " + address4, normalFont) );
document.add(preface);
// For new page
//document.newPage();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.apply, menu);
return true;
}
@Override //problem!!!
public void onClick(View v) {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("document/pdf");
email.putExtra(Intent.EXTRA_EMAIL, cmail);
email.putExtra(Intent.EXTRA_STREAM, document);
startActivity(email);
}