本文整理匯總了Java中com.itextpdf.kernel.geom.PageSize類的典型用法代碼示例。如果您正苦於以下問題:Java PageSize類的具體用法?Java PageSize怎麽用?Java PageSize使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PageSize類屬於com.itextpdf.kernel.geom包,在下文中一共展示了PageSize類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PDFRenderer
import com.itextpdf.kernel.geom.PageSize; //導入依賴的package包/類
public PDFRenderer(Composite rootComponent, PageSize pageSize){
super(rootComponent);
this.pageSize = pageSize;
this.outputStream = new ByteArrayOutputStream();
this.pdfWriter = new PdfWriter(outputStream);
this.pdfDocument = new PdfDocument(pdfWriter);
this.document = new Document(pdfDocument, pageSize);
this.document.setMargins(0, 0, 0, 0);
this.renderStrategies = new LinkedHashMap<Class, Class>(){{
put(Component.class, DefaultComponentRenderStrategy.class);
put(PLImageBlock.class, ImageRenderStrategy.class);
put(PLTextBlock.class, TextRenderStrategy.class);
put(PLTableBlock.class, TableRenderStrategy.class);
put(PLLineChartBlock.class, LineChartRenderStrategy.class);
put(PLPieChartBlock.class, PieChartRenderStrategy.class);
put(PLBarPlotBlock.class, BarPlotRenderStrategy.class);
}};
this.newPage();
}
示例2: generatePDFFromImage
import com.itextpdf.kernel.geom.PageSize; //導入依賴的package包/類
/**
* 將圖片合成為一個PDF
* @param inputImage 圖片,格式為圖片格式
* @param outputPDF 輸出文件
* @throws FileNotFoundException
* @throws MalformedURLException
*/
public static void generatePDFFromImage(File[] inputImage,File outputPDF) throws FileNotFoundException, MalformedURLException {
List<Image>images=new LinkedList<>();
for(File file:inputImage){
images.add(new Image(ImageDataFactory.create(file.getPath())));
}
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outputPDF.getPath()));
images.forEach(image -> pdfDoc.addNewPage(new PageSize(new Rectangle(image.getImageScaledWidth(), image.getImageScaledHeight()))));
BackgroundEventHandler handler = new BackgroundEventHandler(images);
pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, handler);
pdfDoc.close();
}