本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.getDirectContentUnder方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.getDirectContentUnder方法的具體用法?Java PdfWriter.getDirectContentUnder怎麽用?Java PdfWriter.getDirectContentUnder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfWriter
的用法示例。
在下文中一共展示了PdfWriter.getDirectContentUnder方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onStartPage
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
*/
public void onStartPage(PdfWriter writer, Document document) {
if (writer.getPageNumber() < 3) {
PdfContentByte cb = writer.getDirectContentUnder();
cb.saveState();
cb.setColorFill(BaseColor.PINK);
cb.beginText();
cb.setFontAndSize(helv, 48);
cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
cb.endText();
cb.restoreState();
}
}
示例2: onEndPage
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
@Override
public void onEndPage(PdfWriter writer, Document document)
{
if (active)
{
PdfContentByte cb = writer.getDirectContentUnder();
cb.saveState();
cb.setColorFill(color);
cb.rectangle(document.left(), document.bottom() - offset,
document.right() - document.left(), startPosition - document.bottom());
cb.fill();
cb.restoreState();
}
}
示例3: onParagraphEnd
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
@Override
public void onParagraphEnd(PdfWriter writer, Document document, float paragraphPosition)
{
if (active)
{
PdfContentByte cb = writer.getDirectContentUnder();
cb.saveState();
cb.setColorFill(color);
cb.rectangle(document.left(), paragraphPosition - offset,
document.right() - document.left(), startPosition - paragraphPosition);
cb.fill();
cb.restoreState();
}
}
示例4: testCreateTableLikeUser7968180
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/43807931/creating-table-in-pdf-on-last-page-bottom-wrong-official-solution">
* Creating table in pdf on last page bottom (wrong official solution)
* </a>
* <p>
* Indeed, there is an error in the official sample which effectively
* applies the margins twice.
* </p>
*/
@Test
public void testCreateTableLikeUser7968180() throws FileNotFoundException, DocumentException
{
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(new File(RESULT_FOLDER, "calendarUser7968180.pdf")));
document.open();
PdfPTable datatable = null;//createHeaderTable();
//document.add(datatable);
datatable = createFooterTable();
drawTableAtTheEndOfPage(document, writer, datatable);
// Marking the border
PdfContentByte canvas = writer.getDirectContentUnder();
canvas.setColorStroke(BaseColor.RED);
canvas.setColorFill(BaseColor.PINK);
canvas.rectangle(document.left(), document.bottom(), document.right() - document.left(), document.top() - document.bottom());
Rectangle pageSize = document.getPageSize();
canvas.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight());
canvas.eoFillStroke();
document.close();
System.out.println("done");
}
示例5: addBackground
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
private static void addBackground(PdfWriter writer)
throws BadElementException, MalformedURLException, IOException, DocumentException {
PdfContentByte canvas = writer.getDirectContentUnder();
canvas.saveState();
canvas.addImage(bkgnd);
canvas.restoreState();
}
示例6: generatePDF
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public void generatePDF(File file) throws IOException, DocumentException {
Image image = Image.getInstance(getClass().getClassLoader().getResource("blank.png"));
image.scaleAbsolute(PageSize.A4.getWidth(), PageSize.A4.getHeight());
image.setAbsolutePosition(0, 0);
if (logoFile != null) {
logoImage = Image.getInstance(logoFile.toURI().toURL());
logoImage.scaleAbsolute((float) (logoImage.getWidth() * 0.35), (float) (logoImage.getHeight() * 0.35));
float logoWidth = logoImage.getWidth();
float logoHeight = logoImage.getHeight();
float ratioH = logoHeight / logoWidth;
float ratioW = logoWidth / logoHeight;
if (logoHeight >= logoWidth) {
logoHeight = 150f;
logoWidth = 150.0f * ratioW;
logoImage.scaleAbsolute(logoWidth, logoHeight);
} else {
logoHeight = 150f * ratioH;
logoWidth = 150.0f;
logoImage.scaleAbsolute(logoWidth, logoHeight);
}
logoImage.setAbsolutePosition(130f - (0.5f * logoWidth), 725f - (0.5f * logoHeight));
}
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
OutputStream outputStream = new FileOutputStream(file);
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
BaseFont baseBold = BaseFont.createFont(getClass().getClassLoader().getResource("font/AbhayaLibre-Bold.ttf").toString(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
BaseFont baseRegular = BaseFont.createFont(getClass().getClassLoader().getResource("font/AbhayaLibre-Regular.ttf").toString(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
BaseFont baseExtraBold = BaseFont.createFont(getClass().getClassLoader().getResource("font/AbhayaLibre-ExtraBold.ttf").toString(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font fontBold = new Font(baseBold, 22);
Font fontExtraBold = new Font(baseExtraBold, 40);
Font fontRegular = new Font(baseRegular, 12);
document.open();
PdfContentByte pdfContentByte = writer.getDirectContent();
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("PODPIS WYSTAWCY", fontRegular), 100, 100, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("PODPIS ODBIORCY ", fontRegular), 390, 100, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("Termin płatności: " + invoiceData.getString("paymentDate"), fontRegular), 35, 170, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("Słownie: " + invoiceData.getString("inWordsValue"), fontRegular), 35, 195, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("RAZEM", fontBold), 35, 245, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(invoiceData.getString("value") + " PLN", fontBold), 565, 245, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(invoiceData.getString("service"), fontBold), 35, 380, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(invoiceData.getString("value") + " PLN", fontBold), 565, 380, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("Nazwa usługi", fontBold), 35, 400, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase("Wartość", fontBold), 565, 400, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(senderData.getString("accountNumber"), fontRegular), 35, 435, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("Numer konta bankowego:", fontRegular), 35, 450, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("NIP: " + senderData.getString("NIP"), fontRegular), 35, 485, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase("NIP: " + receiverData.getString("NIP"), fontRegular), 565, 485, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(senderData.getString("postalCode") + " " + senderData.getString("street"), fontRegular), 35, 510, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(receiverData.getString("postalCode") + " " + receiverData.getString("street"), fontRegular), 565, 510, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("ul. " + senderData.getString("street") + " " + senderData.getString("building") + (senderData.getString("apartment").isEmpty() ? "" : "/") + senderData.getString("apartment"), fontRegular), 35, 535, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase("ul. " + receiverData.getString("street") + " " + receiverData.getString("building") + (receiverData.getString("apartment").isEmpty() ? "" : "/") + receiverData.getString("apartment"), fontRegular), 565, 535, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(senderData.getString("nameMore"), fontRegular), 35, 560, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(receiverData.getString("nameMore"), fontRegular), 565, 560, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(senderData.getString("name"), fontRegular), 35, 585, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(receiverData.getString("name"), fontRegular), 565, 585, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("WYSTAWCA", fontRegular), 35, 605, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase("ODBIORCA", fontRegular), 565, 605, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("NR: " + invoiceData.getString("ID"), new Font(baseBold, 36)), 265, 690, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase("RACHUNEK", fontExtraBold), 265, 733, 0);
ColumnText.showTextAligned(pdfContentByte, Element.ALIGN_RIGHT, new Phrase(invoiceData.getString("city") + ", " + invoiceData.getString("date"), fontRegular), 565, 795, 0);
//pdfContentByte = writer.getDirectContent();
if (logoImage != null) {
pdfContentByte.addImage(logoImage);
}
pdfContentByte = writer.getDirectContentUnder();
pdfContentByte.addImage(image);
document.close();
outputStream.close();
}