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


Java PdfReader.getPageRotation方法代碼示例

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


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

示例1: applyWatermarkOnAllPages

import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public static void applyWatermarkOnAllPages(
	PdfReader reader, PdfStamper stamper, String text, BaseColor color, float opacity
) throws DocumentException, IOException {
	
	int numberOfPages = reader.getNumberOfPages();
	
	PdfGState gs = new PdfGState();
	gs.setFillOpacity(opacity);

	for (int i = 1; i <= numberOfPages; i++) {
		Rectangle pageSize = reader.getPageSize(i);
		int pageRotation = reader.getPageRotation(i);
		
		boolean isLandscape = false;
		if(pageRotation > 0){
			isLandscape = true;
		}
		
		int pageDiagonalSize = getDiagonalSize(pageSize);
		int watermarkAngle = getDiagonalAngle(pageSize, pageDiagonalSize, isLandscape);
		
		LinkedHashSet<Integer> fontSizeSet = new LinkedHashSet<Integer>();
		float fontSize = determineFontSize(pageDiagonalSize, a4WatermarkFontSize, fontSizeSet);
		fontSize = fontSize - 1;
		
		int cornerPlacement = getCornerPlacementDiagonal(fontSize);
		
		PdfContentByte underContent = stamper.getUnderContent(i);
		underContent.setGState(gs);
		underContent.setFontAndSize(getWaterkmarkFont(), fontSize);
		underContent.setColorFill(color);
		underContent.beginText();
		underContent.showTextAligned(
			Element.ALIGN_BASELINE, text, 
			cornerPlacement/2,
			cornerPlacement/2,
			watermarkAngle
		);
		underContent.endText();
	}
}
 
開發者ID:MatheusArleson,項目名稱:PdfUtil,代碼行數:42,代碼來源:PdfWatermarker.java

示例2: cropMultipliedFile

import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
private static void cropMultipliedFile(File source, CropJob cropJob) throws FileNotFoundException, DocumentException,
		IOException {

	PdfReader reader = new PdfReader(source.getAbsolutePath());
	PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(cropJob.getDestinationFile()));
	stamper.setMoreInfo(cropJob.getSourceMetaInfo());

	PdfDictionary pageDict;
	int newPageNumber = 1;
	for (int origPageNumber = 1; origPageNumber <= cropJob.getSourcePageCount(); origPageNumber++) {
		SingleCluster cluster = cropJob.getClusterCollection().getSingleCluster(origPageNumber);

		// if no crop was selected do nothing
		if (cluster.getRatiosList().size() == 0) {
			newPageNumber++;
			continue;
		}

		for (Float[] ratios : cluster.getRatiosList()) {

			pageDict = reader.getPageN(newPageNumber);

			List<Rectangle> boxes = new ArrayList<Rectangle>();
			boxes.add(reader.getBoxSize(newPageNumber, "media"));
			boxes.add(reader.getBoxSize(newPageNumber, "crop"));
			int rotation = reader.getPageRotation(newPageNumber);

			Rectangle scaledBox = calculateScaledRectangle(boxes, ratios, rotation);

			PdfArray scaleBoxArray = new PdfArray();
			scaleBoxArray.add(new PdfNumber(scaledBox.getLeft()));
			scaleBoxArray.add(new PdfNumber(scaledBox.getBottom()));
			scaleBoxArray.add(new PdfNumber(scaledBox.getRight()));
			scaleBoxArray.add(new PdfNumber(scaledBox.getTop()));

			pageDict.put(PdfName.CROPBOX, scaleBoxArray);
			pageDict.put(PdfName.MEDIABOX, scaleBoxArray);
			// increment the pagenumber
			newPageNumber++;
		}
		int[] range = new int[2];
		range[0] = newPageNumber - 1;
		range[1] = cropJob.getSourcePageCount() + (newPageNumber - origPageNumber);
		SimpleBookmark.shiftPageNumbers(cropJob.getSourceBookmarks(), cluster.getRatiosList().size() - 1, range);
	}
	stamper.setOutlines(cropJob.getSourceBookmarks());
	stamper.close();
	reader.close();
}
 
開發者ID:mbaeuerle,項目名稱:Briss-2.0,代碼行數:50,代碼來源:CropManager.java

示例3: cropMultipliedFile

import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
private static void cropMultipliedFile(final CropDefinition cropDefinition, final File multipliedDocument,
		final PdfMetaInformation pdfMetaInformation) throws DocumentException, IOException {

	PdfReader reader = new PdfReader(multipliedDocument.getAbsolutePath());

	PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(cropDefinition.getDestinationFile()));
	stamper.setMoreInfo(pdfMetaInformation.getSourceMetaInfo());

	PdfDictionary pageDict;
	int newPageNumber = 1;

	for (int sourcePageNumber = 1; sourcePageNumber <= pdfMetaInformation.getSourcePageCount(); sourcePageNumber++) {

		List<Float[]> rectangleList = cropDefinition.getRectanglesForPage(sourcePageNumber);

		// if no crop was selected do nothing
		if (rectangleList.isEmpty()) {
			newPageNumber++;
			continue;
		}

		for (Float[] ratios : rectangleList) {

			pageDict = reader.getPageN(newPageNumber);

			List<Rectangle> boxes = new ArrayList<Rectangle>();
			boxes.add(reader.getBoxSize(newPageNumber, "media"));
			boxes.add(reader.getBoxSize(newPageNumber, "crop"));
			int rotation = reader.getPageRotation(newPageNumber);

			Rectangle scaledBox = RectangleHandler.calculateScaledRectangle(boxes, ratios, rotation);

			PdfArray scaleBoxArray = createScaledBoxArray(scaledBox);

			pageDict.put(PdfName.CROPBOX, scaleBoxArray);
			pageDict.put(PdfName.MEDIABOX, scaleBoxArray);
			// increment the pagenumber
			newPageNumber++;
		}
		int[] range = new int[2];
		range[0] = newPageNumber - 1;
		range[1] = pdfMetaInformation.getSourcePageCount() + (newPageNumber - sourcePageNumber);
		SimpleBookmark.shiftPageNumbers(pdfMetaInformation.getSourceBookmarks(), rectangleList.size() - 1, range);
	}
	stamper.setOutlines(pdfMetaInformation.getSourceBookmarks());
	stamper.close();
	reader.close();
}
 
開發者ID:mbaeuerle,項目名稱:Briss-2.0,代碼行數:49,代碼來源:DocumentCropper.java


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