我的应用程序是一个Domino X Pages应用程序,它正在使用itextpdf-5.5.9创建PDF。我的Domino服务器版本是9.01 FP 10。
在服务器上Windows的最新更新之前,该应用程序运行良好。我现在遇到的问题是我在以下代码行中遇到错误:
Font regular1 = new Font(FontFamily.HELVETICA, 11,Font.NORMAL);
Font regular2 = new Font(FontFamily.HELVETICA, 11,Font.ITALIC);
Font regular0 = new Font(FontFamily.HELVETICA, 10,Font.NORMAL);
Font bold1 = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
Font bold2 = new Font(FontFamily.HELVETICA, 10, Font.BOLD);
Font bold0 = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
在Windows Azure服务器上MS推出的最近更新之前,我没有遇到此问题。当我将鼠标悬停在这些错误行上时,会收到以下错误消息:
FontFamily.HELVETICA can not be resolved.
这些错误使我的PDF代码无法创建PDF。还有其他人看到过这个问题吗?
我有一些与导入文件等相关的东西,但是令我感到困惑的是,这段代码之前完全可以运行,而现在我已经死了。
任何帮助都将不胜感激。
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
import java.awt.font.*;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import lotus.domino.Database;
import lotus.domino.DateTime;
import lotus.domino.Document;
import lotus.domino.EmbeddedObject;
import lotus.domino.Item;
import lotus.domino.NotesException;
import lotus.domino.RichTextItem;
import lotus.domino.Session;
import sun.font.FontFamily;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.VerticalPositionMark;
public class InvoicePDF {
//public static final String DEST = "d://IBM//Domino//Data1//chu//BCAInvoiceFiles//";
//public static final String LOGOFILEPATH = "d://IBM//Domino//Data1//chu/BCAInvoiceFiles//logo//logo.jpg";
public static final String DEST = "e://IBM//Domino//Data1//chu//BCAInvoiceFiles//";
public static final String LOGOFILEPATH = "e://IBM//Domino//Data1//chu/BCAInvoiceFiles//logo//logo.png";
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Font regular1 = new Font(FontFamily.HELVETICA, 11,Font.NORMAL);
Font regular2 = new Font(FontFamily.HELVETICA, 11,Font.ITALIC);
Font regular0 = new Font(FontFamily.HELVETICA, 10,Font.NORMAL);
Font bold1 = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
Font bold2 = new Font(FontFamily.HELVETICA, 10, Font.BOLD);
Font bold0 = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
Date currentDate = new Date();
public class HeaderTable extends PdfPageEventHelper {
protected PdfPTable table;
protected float tableHeight;
public HeaderTable(Document InvDoc) throws MalformedURLException, IOException, DocumentException, NotesException {
table = new PdfPTable(2);
table.setWidths(new float[] { 1, 4 });
Item frmDt=null;
Item toDt=null;
frmDt=InvDoc.getFirstItem("InvFrmDate");
toDt=InvDoc.getFirstItem("InvToDate");
DateTime frmDt1=null;
DateTime toDt1=null;
if(frmDt!=null)
{
frmDt1 = frmDt.getDateTimeValue();
}
if(toDt!=null)
{
toDt1 = toDt.getDateTimeValue();
}
String strFrmDate= formatter.format(frmDt1.toJavaDate());
String strToDate= formatter.format(toDt1.toJavaDate());
Phrase headerPhrase = new Phrase();
headerPhrase.add(new Chunk("\n"+"State of Georgia - Department of Juvenile Justice"+"\n", bold1));
headerPhrase.add(new Chunk("Office of Human Resources - Criminal History Unit\n", regular1));
headerPhrase.add(new Chunk("(For Internal Use Only)\n", regular2));
headerPhrase.add(new Chunk("SERVICE INVOICE\n", bold0));
headerPhrase.add(new Chunk("For: ", bold2));
headerPhrase.add(new Chunk(strFrmDate+" - "+strToDate+"\n", regular0));
table.setTotalWidth(523);
String logoFile =LOGOFILEPATH ;
Image logoImg = Image.getInstance(logoFile);
logoImg.setWidthPercentage(100);
PdfPCell cell1 = new PdfPCell(logoImg);
cell1.setBorder(0);
cell1.setBorder(Rectangle.LEFT | Rectangle.TOP | Rectangle.BOTTOM );
cell1.setUseBorderPadding(true);
cell1.setBorderWidthLeft(1);
cell1.setBorderColorLeft(BaseColor.GRAY);
cell1.setBorderWidthTop(1);
cell1.setBorderColorTop(BaseColor.GRAY);
cell1.setBorderWidthBottom(1);
cell1.setBorderColorBottom(BaseColor.GRAY);
/* */
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell1);
PdfPCell cell2 = new PdfPCell(headerPhrase);
cell2.setBorder(0);
cell2.setBorder( Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT);
cell2.setUseBorderPadding(true);
cell2.setBorderWidthTop(1);
cell2.setBorderColorTop(BaseColor.GRAY);
cell2.setBorderWidthRight(1);
cell2.setBorderColorRight(BaseColor.GRAY);
cell2.setBorderWidthBottom(1);
cell2.setBorderColorBottom(BaseColor.GRAY);/**/
cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell2);
table.completeRow();
tableHeight = table.getTotalHeight();
}
public float getTableHeight() {
return tableHeight;
}
public void onEndPage(PdfWriter writer,com.itextpdf.text.Document document) {
table.writeSelectedRows(0, -1,
document.left(),
document.top() + ((document.topMargin() + tableHeight) / 2),
writer.getDirectContent());
}
}
@SuppressWarnings("unchecked")
public void createPDF(Document docInvoice,String CurUser) throws IOException, DocumentException
{
FacesContext facesContext = FacesContext.getCurrentInstance();
try {
ExternalContext extCon = facesContext.getExternalContext();
Session session = (Session) resolveVariable("session");
Database dbCurrent = (Database) resolveVariable("database");
Map sessionScope = extCon.getSessionMap();
File file = new File(DEST+docInvoice.getUniversalID()+".pdf");
file.getParentFile().mkdirs();
System.out.println(":::::::::::::::::::Inside HeaderTable::::::555555555555:::::::::::::");
new InvoicePDF().createPdf(DEST+docInvoice.getUniversalID()+".pdf",docInvoice,dbCurrent);
}
catch (Exception e) {
e.printStackTrace();
}
}
public void createPdf(String filename,Document docInvoice,Database dbCurrent) throws IOException, DocumentException, NotesException {
InvoicePDF.HeaderTable event1 = new InvoicePDF.HeaderTable(docInvoice);
// step 1
com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4, 36, 36, 20 + event1.getTableHeight(), 36);
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
try
{
writer.setPageEvent(event1);
}
catch(Exception e)
{
System.out.println("Exception :::::"+e);
}
// step 3
document.open();
// step 4
Vector lineDocID = new Vector();
Item InvLineItemsDocIDs = docInvoice.getFirstItem("InvLineItemsDocIDs");
if(InvLineItemsDocIDs==null)
{
lineDocID =null;
}
else
{
lineDocID = InvLineItemsDocIDs.getValues();//
//String lineDocIDs =docInvoice.getItemValueString("InvLineItemsDocIDs");
//lineDocID = lineDocIDs.split("~");
}
Double unitPice = docInvoice.getItemValueDouble("InvUnitPrice");
double roundOffUnitPice = Math.round(unitPice * 100.00) / 100.00;
// step 5
//create a paragraph
//special font sizes