这是我的页眉和页脚部分
@Override
public void onStartPage(PdfWriter writer, Document document) {
Log.d("Vijay","onStart 1");
String phone = "Phone - 9850030179";
String qualification = "MBBS";
PdfContentByte cb = writer.getDirectContent();
Phrase dr_name = new Phrase("Raghani Doctor ("+qualification
+")",header_font);
Phrase clinic_name = new Phrase("Ridhhi Clinic",setFontWeight(10));
Phrase reg_no = new Phrase("Registration no. -
572017",setFontWeight(10));
Phrase phone_no = new Phrase(phone,setFontWeight(10));
//Phrase qualify = new Phrase(qualification,setFontWeight(10));
Phrase address = new Phrase("Crescent Business Park, Riddhi Clinic,
SakiNaka, Mumbai, Pin - 400072",setFontWeight(10));
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,dr_name,
(document.right()+document.left())/2,document.top()-11,0);
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,clinic_name,
(document.right()+document.left())/2,document.top()-21,0);
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,reg_no,
(document.right()+document.left())/2,document.top()-30,0);
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,address,
(document.right()+document.left())/2,document.top()-42,0);
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,phone_no,
(document.right()+document.left())/2,document.top()-52,0);
String separator =
"__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________";
ColumnText.showTextAligned(cb,Element.ALIGN_CENTER,new
Phrase(separator),
(document.right()+document.left())/2,document.top()-60,0);
PdfPTable table = new PdfPTable(1);
}
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte cb = writer.getDirectContent();
Phrase medoc = new Phrase("Medoc", ffont);
Phrase kspl = new Phrase("Kanishka Software", ffont);
Phrase dash_left = new Phrase("- - - - - - - - - - - ", ffont);
Phrase dash_right = new Phrase("- - - - - - - - - - - - - - - - - - - - -
- - - - ", ffont);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, medoc,
document.left(), document.bottom(), 0);
ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, kspl,
document.right(), document.bottom(), 0);
ColumnText.showTextAligned(cb,Element.ALIGN_LEFT,dash_left,document.left(),docume nt.bottom()+10,0);
ColumnText.showTextAligned(cb,Element.ALIGN_RIGHT,dash_right,document.right(),document.bottom()+10,0);
}
}
在另一个活动中,我创建了文档。我还尝试使用另一个参数化的文档构造函数,但仍然存在重叠。
document = new Document();
try {
PdfWriter pdfWriter = PdfWriter.getInstance(document,new FileOutputStream(file));
HeaderFooter headerFooter = new HeaderFooter();
pdfWriter.setPageEvent(headerFooter);
Log.d("Vijay","Inside Pdf: "+arrayList);
document.open();
document.add(new Paragraph("\n \n \n \n Patient name - "+ patient_name));
document.add(new Paragraph("Patient DOB - "+pat_dob));
document.add(new Paragraph("Title: "+title.getText().toString()));
document.setMarginMirroring(false);
// ColumnText.showTextAligned(pdfWriter.getDirectContent(),Element.ALIGN_CENTER,new Phrase(""+other_details),(document.right()+document.left())/2,document.top()-72,0);
//document.add(new Paragraph(title.getText().toString()));
Log.d("Vijay","Page no. "+pdfWriter.getPageNumber());
for(int m = 0;m<descriptionList.size();m++){
Log.d("Vijay","desc"+descriptionList.get(m).toString()+" "+m);
NewApplication newApplication = descriptionList.get(m);
if(newApplication.getFlag()==0){
document.add(new Paragraph("Content Description"));
// Paragraph content = new Paragraph(descriptionList.get(m).getAddDescription());
document.add(new Paragraph(descriptionList.get(m).getAddDescription()));
//content.setAlignment(Element.ALIGN_CENTER);
// document.add(content);
Log.d("Vijay","path : "+descriptionList.get(m).getAddDescription());
}
else{
Log.d("Vijay"," "+m);
Image image = Image.getInstance(arrayList_Path.get(m));
image.scaleAbsolute(200,250);
image.setAlignment(Image.ALIGN_CENTER);
Paragraph para = new Paragraph(descriptionList.get(m).getType());
para.setAlignment(Element.ALIGN_CENTER);
document.add(para);
document.add(image);
}
}
Log.d("Vijay","Array list "+ arrayList);
document.add(new Paragraph("Medicine Name - "+medicine_name));
document.add(new Paragraph("Medicine Time : "));
Log.d("Vijay","Page no.ssac "+pdfWriter.getPageNumber());
for (int l=0;l<timeArray.size();l++){
Paragraph paragraph = new Paragraph(timeArray.get(l)+"\n");
document.add(paragraph);
}
Image image_sign = Image.getInstance(sign);
image_sign.scaleAbsolute(200,250);
image_sign.setAlignment(Image.ALIGN_RIGHT);
Paragraph signing = new Paragraph("\n \n \n \n \n Signature");
signing.setAlignment(Element.ALIGN_RIGHT);
document.add(signing);
Paragraph sign_dash = new Paragraph("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
sign_dash.setAlignment(Element.ALIGN_RIGHT);
document.add(sign_dash);
document.add(image_sign);
Log.d("Vijay","here pdf");
document.close();`[enter code here][1]`