當前位置: 首頁>>代碼示例>>Java>>正文


Java PdfWriter.setCropBoxSize方法代碼示例

本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.setCropBoxSize方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.setCropBoxSize方法的具體用法?Java PdfWriter.setCropBoxSize怎麽用?Java PdfWriter.setCropBoxSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.itextpdf.text.pdf.PdfWriter的用法示例。


在下文中一共展示了PdfWriter.setCropBoxSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPDFFile

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
private void createPDFFile(String filename) throws FileNotFoundException, DocumentException {
	PNEditorComponent editor = getEditor();
   	PNGraph pnGraph = editor.getGraphComponent().getGraph();

   	JFrame frm = new JFrame();
   	PNGraphComponent forPrint = new PNGraphComponent(pnGraph) {
   	};
   	mxRectangle size = forPrint.getGraph().getGraphBounds();
   	double space = 4;
   	float x = (float) (size.getRectangle().getWidth() + size.getRectangle().getX() + space);
   	float y = (float) (size.getRectangle().getHeight() + size.getRectangle().getY() + space);
   	Document document = new Document(new Rectangle(x, y));
   	PdfWriter writer = null;
   	writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

   	// set crop of pdf doc = ll=lowerleft; ur=upper right
   	float llx = (float) size.getX();
   	float lly = 0;
   	float urx = x;
   	float ury = (float) ((float) size.getRectangle().getHeight() + space*4);
   	com.itextpdf.text.Rectangle crop = new com.itextpdf.text.Rectangle(llx, lly, urx, ury);
   	writer.setCropBoxSize(crop);

   	document.open();

   	PdfContentByte canvas = writer.getDirectContent();

   	// make pdf-background transparent
   	PdfGState gState = new PdfGState();
   	gState.setFillOpacity(0.0f);
   	canvas.setGState(gState);
	
   	forPrint.setGridVisible(false);

   	PdfGraphics2D g2 = new PdfGraphics2D(canvas, x, y);

   	frm.getContentPane().add(forPrint);
   	frm.pack();
   	forPrint.paint(g2);
   	g2.dispose();

   	document.close();
}
 
開發者ID:iig-uni-freiburg,項目名稱:WOLFGANG,代碼行數:44,代碼來源:ExportPDFAction.java

示例2: doFancyStuff

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
@Override
	protected void doFancyStuff(ActionEvent e) throws Exception {
		setUpGui();
		fch.addChoosableFileFilter(new FileFilter() {
			public String getDescription() {
				return "Portable Network Graphics (*.png)";
			}
			public boolean accept(File f) {
				if (f.isDirectory()) {
					return true;
				} else {
					return f.getName().toLowerCase().endsWith(".png");
				}
			}
		});
		fch.setDialogTitle("Save PNG");
		int returnVal = fch.showDialog(getEditor().getGraphComponent(), "save PNG");
		
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			String filename = fch.getSelectedFile().getAbsolutePath();
			if (!filename.toLowerCase().endsWith(".png"))
				filename += ".png";

			PNEditorComponent editor = getEditor();
			PNGraph pnGraph = editor.getGraphComponent().getGraph();

			
				JFrame frm = new JFrame();
				PNGraphComponent forPrint = new PNGraphComponent(pnGraph) {
				};
				mxRectangle size = forPrint.getGraph().getGraphBounds();
				double space = 4;
				float x = (float) (size.getRectangle().getWidth() + size.getRectangle().getX() + space);
				float y = (float) (size.getRectangle().getHeight() + size.getRectangle().getY() + space);
				Document document = new Document(new Rectangle(x, y));
				PdfWriter writer = null;
				writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

				// set crop of pdf doc = ll=lowerleft; ur=upper right
				float llx = (float) size.getX();
				float lly = 0;
				float urx = x;
				float ury = (float) ((float) size.getRectangle().getHeight() + space);
				com.itextpdf.text.Rectangle crop = new com.itextpdf.text.Rectangle(llx, lly, urx, ury);
				writer.setCropBoxSize(crop);

				document.open();

				PdfContentByte canvas = writer.getDirectContent();

				// make pdf-background transparent
				PdfGState gState = new PdfGState();
				gState.setFillOpacity(0.0f);
				canvas.setGState(gState);
				
				forPrint.setGridVisible(false);

//				PdfGraphics2D g2 = new PdfGraphics2D(canvas, x, y);
				
				BufferedImage b = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB); /* change sizes of course */
				Graphics2D g2 = b.createGraphics();
//				component.print(g);
				
				
				
				frm.getContentPane().add(forPrint);
				frm.pack();
				forPrint.paint(g2);
				ImageIO.write(b,"png",new File(filename));
				g2.dispose();
				document.close();

		}		
	}
 
開發者ID:iig-uni-freiburg,項目名稱:WOLFGANG,代碼行數:75,代碼來源:ExportPNGAction.java


注:本文中的com.itextpdf.text.pdf.PdfWriter.setCropBoxSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。