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


Java Rectangle類代碼示例

本文整理匯總了Java中com.itextpdf.text.Rectangle的典型用法代碼示例。如果您正苦於以下問題:Java Rectangle類的具體用法?Java Rectangle怎麽用?Java Rectangle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: buildPdfPCell

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){
	PdfPCell cell=new PdfPCell();
	cell.setPadding(0);
	cell.setBorder(Rectangle.NO_BORDER);
	Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline());
	String fontColor=phf.getForecolor();
	if(StringUtils.isNotEmpty(fontColor)){
		String[] color=fontColor.split(",");
		font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));			
	}
	Paragraph graph=new Paragraph(text,font);
	cell.setPhrase(graph);
	switch(type){
	case 1:
		cell.setHorizontalAlignment(Element.ALIGN_LEFT);
		break;
	case 2:
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		break;
	case 3:
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
		break;
	}
	cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	return cell;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:27,代碼來源:PageHeaderFooterEvent.java

示例2: testSwitchOrientation

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/34394199/i-cant-rotate-my-page-from-existing-pdf">
 * I can't rotate my page from existing PDF
 * </a>
 * <p>
 * Switching between portrait and landscape like this obviously will cut off some parts of the page.
 * </p>
 */
@Test
public void testSwitchOrientation() throws DocumentException, IOException
{
    try (InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/n2013.00849449.pdf"))
    {
        PdfReader reader = new PdfReader(resourceStream);
        int n = reader.getNumberOfPages();
        PdfDictionary pageDict;
        for (int i = 1; i <= n; i++) {
            Rectangle rect = reader.getPageSize(i);
            Rectangle crop = reader.getCropBox(i);
            pageDict = reader.getPageN(i);
            pageDict.put(PdfName.MEDIABOX, new PdfArray(new float[] {rect.getBottom(), rect.getLeft(), rect.getTop(), rect.getRight()}));
            pageDict.put(PdfName.CROPBOX, new PdfArray(new float[] {crop.getBottom(), crop.getLeft(), crop.getTop(), crop.getRight()}));
        }
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(new File(RESULT_FOLDER, "n2013.00849449-switch.pdf")));
        stamper.close();
        reader.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:29,代碼來源:SwitchPageCanvas.java

示例3: createPDF

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
public void createPDF(String outputFile, ArrayList<Question> qlist, boolean showCorrectAnswer,
        PageCounter pagecounter, int maximumPageNumber, String inputFolder) throws DocumentException, IOException
{
    _inputFolder = inputFolder;
    Document document = new Document(PageSize.A4, 50, 50, 70, 50);
    PdfWriter pdfwriter = PdfWriter.getInstance(document, new FileOutputStream(outputFile));

    pdfwriter.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    pdfwriter.setPageEvent(new HeaderFooter(maximumPageNumber));

    if (pagecounter != null)
    {
        pdfwriter.setPageEvent(pagecounter);
    }

    document.open();

    Paragraph p = new Paragraph();
    // p.setSpacingBefore(SPACING);
    p.setSpacingAfter(SPACING);
    p.setIndentationLeft(INDENTATION);

    writeQuestions(p, document, showCorrectAnswer, qlist);

    document.close();

}
 
開發者ID:wolfposd,項目名稱:IMSQTI2PDF,代碼行數:29,代碼來源:PDFCreator.java

示例4: print

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
public void print(String plot_pdf) {
	try {
		float width = jframe.getSize().width,
				height = jframe.getSize().height;
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
		document.open();
		PdfContentByte canvas = writer.getDirectContent();
		PdfTemplate template = canvas.createTemplate(width, height);
		Graphics2D g2d = new PdfGraphics2D(template, width, height);
		jframe.paint(g2d);
		g2d.dispose();
		canvas.addTemplate(template, 0, 0);
		document.close();
	} catch (FileNotFoundException | DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:c-zhou,項目名稱:polyGembler,代碼行數:20,代碼來源:JfreeChart.java

示例5: putSignature

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
private void putSignature(PdfPTable table, Context context) throws Exception {
	String uploadOid = (String)context.get("uploadSignatureOid");
	if ( StringUtils.isBlank(uploadOid) ) {
		return;
	}
	byte[] imageBytes = UploadSupportUtils.getDataBytes( uploadOid );
	if ( null == imageBytes ) {
		return;
	}
	Image signatureImgObj = Image.getInstance( imageBytes );
	signatureImgObj.setWidthPercentage(40f);
	PdfPCell cell = new PdfPCell();
	cell.setBorder( Rectangle.NO_BORDER );
	cell.addElement(signatureImgObj);
	table.addCell(cell);		
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:17,代碼來源:PersonalReportPdfCommand.java

示例6: testRotateAndZoomUpperHalfPage

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/35374110/how-do-i-use-itext-to-have-a-landscaped-pdf-on-half-of-a-a4-back-to-portrait-and">
 * How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
 * </a>
 * <p>
 * This sample shows how to rotate and enlarge the upper half of an A4 page to fit into a new A4 page.
 * </p>
 */
@Test
public void testRotateAndZoomUpperHalfPage() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-upperHalf.pdf"))   )
    {
        PdfReader reader = new PdfReader(resource);
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, result);
        document.open();

        double sqrt2 = Math.sqrt(2);
        Rectangle pageSize = reader.getPageSize(1);
        PdfImportedPage importedPage = writer.getImportedPage(reader, 1);
        writer.getDirectContent().addTemplate(importedPage, 0, sqrt2, -sqrt2, 0, pageSize.getTop() * sqrt2, -pageSize.getLeft() * sqrt2);
        
        document.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:28,代碼來源:EnlargePagePart.java

示例7: sign50MBrunoAppend

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
@Test
public void sign50MBrunoAppend() throws IOException, DocumentException, GeneralSecurityException
{
    String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
    String digestAlgorithm = "SHA512";
    CryptoStandard subfilter = CryptoStandard.CMS;

    // Creating the reader and the stamper
    PdfReader reader = new PdfReader(filepath);
    FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedBrunoAppend.pdf"));
    PdfStamper stamper =
        PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
    // Creating the appearance
    PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
    appearance.setReason("reason");
    appearance.setLocation("location");
    appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
    // Creating the signature
    ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
    ExternalDigest digest = new BouncyCastleDigest();
    MakeSignature.signDetached(appearance, digest, pks, chain,
        null, null, null, 0, subfilter);
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:CreateSignature.java

示例8: onEndPage

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 頁   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("頁",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:35,代碼來源:PdfReportPageNumber.java

示例9: createDocument

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
public Document createDocument(File pdfFile) throws DocumentException, IOException{
		Document document = new Document(new Rectangle(pageWidth, pageHeight));
		document.setPageSize(PageSize.A4);
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
		//寫入頁尾
		this.setFooter(writer); 
		writer.setFullCompression();
		writer.setPdfVersion(PdfWriter.VERSION_1_4);
		document.open();	
//		//加入二維碼圖片
//		Image image = Image.getInstance(System.getProperty(appConfig.getValue("app.root"))+"/images/logoqrcode.png");
//        image.scaleAbsolute(40,40);//控製圖片大小
//        image.setAlignment(Image.LEFT);
//        document.add(image);
        return document;
	}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:17,代碼來源:PdfBuilder.java

示例10: onStartPage

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
/**
      * Increase the page number.
      * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
      *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
      */
     @Override
public void onStartPage(PdfWriter writer, Document document) {
         pagenumber++;
         System.out.println("ON Start Page PDF");
Rectangle rect = writer.getBoxSize("art");
         
         /* header     
         ColumnText.showTextAligned(writer.getDirectContent(),                		
             		com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
                     rect.getRight(), rect.getTop(), 0);
          */  
		  Font font = new Font();
		  font.setSize(8);
         if (G.licensePDF) {
          ColumnText.showTextAligned(writer.getDirectContent(),
          		com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")),font),
                  (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
          ColumnText.showTextAligned(writer.getDirectContent(),
	          		com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")),font),
	                  (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
         }
         
         
     }
 
開發者ID:ProgettoRadis,項目名稱:ArasuiteIta,代碼行數:30,代碼來源:HeaderFooter.java

示例11: split

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);

    Rectangle pageSizeToImport = reader.getPageSize(page);
    Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page);

    for (Rectangle rectangle : rectangles) {
        newPage(rectangle);
        PdfContentByte directContent = writer.getDirectContent();
        directContent.saveState();
        directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight());
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom());

        directContent.restoreState();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:21,代碼來源:Abstract2DPdfPageSplittingTool.java

示例12: cellLayout

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
@Override
    public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
        PdfContentByte canvas = canvases[PdfPTable.BACKGROUNDCANVAS];

        float xTransition = position.getLeft() + (position.getRight() - position.getLeft()) * (percent/100.0f);
        float yTransition = (position.getTop() + position.getBottom()) / 2f;
        float radius = (position.getRight() - position.getLeft()) * 0.025f;
        PdfShading axial = PdfShading.simpleAxial(canvas.getPdfWriter(),
                xTransition - radius, yTransition, xTransition + radius, yTransition, leftColor, rightColor);
        PdfShadingPattern shading = new PdfShadingPattern(axial);

        canvas.saveState();
        canvas.setShadingFill(shading);
        canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
//        canvas.clip();
        canvas.fill();
        canvas.restoreState();
    }
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:19,代碼來源:PercentileCellBackground.java

示例13: merge

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
void merge(PdfReader reader, PdfReaderContentParser parser, int page) throws IOException
{
    TextMarginFinder finder = parser.processContent(page, new TextMarginFinder());
    Rectangle pageSizeToImport = reader.getPageSize(page);
    float heightToImport = finder.getHeight();
    float maxHeight = pageSize.getHeight() - topMargin - bottomMargin;
    if (heightToImport > maxHeight)
    {
        throw new IllegalArgumentException(String.format("Page %s content too large; height: %s, limit: %s.", page, heightToImport, maxHeight));
    }

    if (heightToImport > yPosition - pageSize.getBottom(bottomMargin))
    {
        newPage();
    }
    else if (!writer.isPageEmpty())
    {
        heightToImport += gap;
    }
    yPosition -= heightToImport;

    PdfImportedPage importedPage = writer.getImportedPage(reader, page);
    writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (finder.getLly() - pageSizeToImport.getBottom()));
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:25,代碼來源:PdfDenseMergeTool.java

示例14: processImage

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
private byte[] processImage(byte[] imageBytes, List<Rectangle> areasToBeCleaned) {
    if (areasToBeCleaned.isEmpty()) {
        return imageBytes;
    }

    try {
        BufferedImage image = Imaging.getBufferedImage(imageBytes);
        ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
        cleanImage(image, areasToBeCleaned);

        // Apache can only read JPEG, so we should use awt for writing in this format
        if (imageInfo.getFormat() == ImageFormats.JPEG) {
            return getJPGBytes(image);
        } else {
            Map<String, Object> params = new HashMap<String, Object>();

            if (imageInfo.getFormat() == ImageFormats.TIFF) {
                params.put(ImagingConstants.PARAM_KEY_COMPRESSION, TiffConstants.TIFF_COMPRESSION_LZW);
            }

            return Imaging.writeImageToBytes(image, imageInfo.getFormat(), params);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:27,代碼來源:PdfCleanUpRenderListener.java

示例15: cleanImage

import com.itextpdf.text.Rectangle; //導入依賴的package包/類
private void cleanImage(BufferedImage image, List<Rectangle> areasToBeCleaned) {
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(CLEANED_AREA_FILL_COLOR);

    // A rectangle in the areasToBeCleaned list is treated to be in standard [0, 1]x[0,1] image space
    // (y varies from bottom to top and x from left to right), so we should scale the rectangle and also
    // invert and shear the y axe
    for (Rectangle rect : areasToBeCleaned) {
        int scaledBottomY = (int) Math.ceil(rect.getBottom() * image.getHeight());
        int scaledTopY = (int) Math.floor(rect.getTop() * image.getHeight());

        int x = (int) Math.ceil(rect.getLeft() * image.getWidth());
        int y = scaledTopY * -1 + image.getHeight();
        int width = (int) Math.floor(rect.getRight() * image.getWidth()) - x;
        int height = scaledTopY - scaledBottomY;

        graphics.fillRect(x, y, width, height);
    }

    graphics.dispose();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:22,代碼來源:PdfCleanUpRenderListener.java


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