嗨我正在嘗試創建發票,其中公司徽標和地址彼此相鄰顯示。公司徽標顯示在左側,文本位於其下方。我試圖在FAR RIGHT旁邊顯示徽標旁邊的文字,但沒有出現。請幫助。如何在彼此旁邊顯示圖像和文字Itext
public class Test {
/** Path to the resulting PDF */
public static final String RESULT = "C:/ex/test.pdf";
/**
* Main method.
* @param args no arguments needed
* @throws DocumentException
* @throws IOException
*/
public static void main(String[] args) throws IOException, DocumentException {
new ComCrunchifyTutorials().createPdf(RESULT);
}
/**
* Creates a PDF with information about the movies
* @param filename the name of the PDF file that will be created.
* @throws DocumentException
* @throws IOException
*/
public void createPdf(String filename)
throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
Image image = Image.getInstance("C:/Users/user/Desktop/New folder (3)/shoes/shoes/web/images/abc.jpg");
image.scaleAbsolute(150f, 50f);//image width,height
Paragraph p = new Paragraph();
Phrase pp = new Phrase(200);
p.add(new Chunk(image, 0, 0));
pp.add(" a text after the image.");
p.add(pp);
document.add(p);
document.close();
}
}
你試過把html轉換成pdf嗎?只是使您的圖像和發票的HTML頁面,然後嘗試將HTML轉換爲PDF,這是行之有效的 – 2014-09-11 10:11:41