本文整理匯總了Java中com.itextpdf.text.Rectangle.getHeight方法的典型用法代碼示例。如果您正苦於以下問題:Java Rectangle.getHeight方法的具體用法?Java Rectangle.getHeight怎麽用?Java Rectangle.getHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.Rectangle
的用法示例。
在下文中一共展示了Rectangle.getHeight方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSplitDocumentA6
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
/**
* <a href="https://stackoverflow.com/questions/46466747/how-to-split-a-pdf-page-in-java">
* How to split a PDF page in java?
* </a>
* <p>
* This test shows how to split the pages of a document into tiles of A6
* size using the {@link Abstract2DPdfPageSplittingTool}.
* </p>
*/
@Test
public void testSplitDocumentA6() throws IOException, DocumentException {
try (InputStream resource = getClass().getResourceAsStream("document.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "document-A6.pdf"))) {
Abstract2DPdfPageSplittingTool tool = new Abstract2DPdfPageSplittingTool() {
@Override
protected Iterable<Rectangle> determineSplitRectangles(PdfReader reader, int page) {
Rectangle targetSize = PageSize.A6;
List<Rectangle> rectangles = new ArrayList<>();
Rectangle pageSize = reader.getPageSize(page);
for (float y = pageSize.getTop(); y > pageSize.getBottom() + 5; y-=targetSize.getHeight()) {
for (float x = pageSize.getLeft(); x < pageSize.getRight() - 5; x+=targetSize.getWidth()) {
rectangles.add(new Rectangle(x, y - targetSize.getHeight(), x + targetSize.getWidth(), y));
}
}
return rectangles;
}
};
tool.split(result, new PdfReader(resource));
}
}
示例2: clusterPages
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
public static ClusterDefinition clusterPages(final File source, final PageExcludes pageExcludes) throws IOException {
PdfReader reader = new PdfReader(source.getAbsolutePath());
ClusterDefinition clusters = new ClusterDefinition();
for (int page = 1; page <= reader.getNumberOfPages(); page++) {
Rectangle layoutBox = getLayoutBox(reader, page);
// create Cluster
// if the pagenumber should be excluded then use it as a
// discriminating parameter, else use default value
boolean excluded = checkExclusionAndGetPageNumber(pageExcludes, page);
PageCluster tmpCluster = new PageCluster(page % 2 == 0, (int) layoutBox.getWidth(), (int) layoutBox.getHeight(),
excluded, page);
clusters.addOrMergeCluster(tmpCluster);
}
reader.close();
clusters.selectAndSetPagesForMerging();
return clusters;
}
示例3: centerIn
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
Rectangle centerIn(Rectangle source, int rotation, float width, float height)
{
if (rotation % 180 != 0)
{
float temp = height;
height = width;
width = temp;
}
float halfWidthToRemove = (source.getWidth() - width) / 2.0f;
float halfHeightToRemove = (source.getHeight() - height) / 2.0f;
return new Rectangle(source.getLeft(halfWidthToRemove), source.getBottom(halfHeightToRemove),
source.getRight(halfWidthToRemove), source.getTop(halfHeightToRemove));
}
示例4: find
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
public Collection<Rectangle2D> find(PdfReader reader, float minWidth, float minHeight, int page) throws IOException
{
Rectangle cropBox = reader.getCropBox(page);
Rectangle2D crop = new Rectangle2D.Float(cropBox.getLeft(), cropBox.getBottom(), cropBox.getWidth(), cropBox.getHeight());
FreeSpaceFinder finder = new FreeSpaceFinder(crop, minWidth, minHeight);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
parser.processContent(page, finder);
return finder.freeSpaces;
}
示例5: findExt
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
public Collection<Rectangle2D> findExt(PdfReader reader, float minWidth, float minHeight, int page) throws IOException
{
Rectangle cropBox = reader.getCropBox(page);
Rectangle2D crop = new Rectangle2D.Float(cropBox.getLeft(), cropBox.getBottom(), cropBox.getWidth(), cropBox.getHeight());
FreeSpaceFinder finder = new FreeSpaceFinderExt(crop, minWidth, minHeight);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
parser.processContent(page, finder);
return finder.freeSpaces;
}
示例6: calculateScaledRectangle
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
private static Rectangle calculateScaledRectangle(List<Rectangle> boxes, Float[] ratios, int rotation) {
if (ratios == null || boxes.size() == 0)
return null;
Rectangle smallestBox = null;
// find smallest box
float smallestSquare = Float.MAX_VALUE;
for (Rectangle box : boxes) {
if (box != null) {
if (smallestBox == null) {
smallestBox = box;
}
if (smallestSquare > box.getWidth() * box.getHeight()) {
// set new smallest box
smallestSquare = box.getWidth() * box.getHeight();
smallestBox = box;
}
}
}
if (smallestBox == null)
return null; // no useable box was found
// rotate the ratios according to the rotation of the page
float[] rotRatios = rotateRatios(ratios, rotation);
// use smallest box as basis for calculation
Rectangle scaledBox = new Rectangle(smallestBox);
scaledBox.setLeft(smallestBox.getLeft() + (smallestBox.getWidth() * rotRatios[0]));
scaledBox.setBottom(smallestBox.getBottom() + (smallestBox.getHeight() * rotRatios[1]));
scaledBox.setRight(smallestBox.getLeft() + (smallestBox.getWidth() * (1 - rotRatios[2])));
scaledBox.setTop(smallestBox.getBottom() + (smallestBox.getHeight() * (1 - rotRatios[3])));
return scaledBox;
}
示例7: calculateScaledRectangle
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
public static Rectangle calculateScaledRectangle(final List<Rectangle> boxes, final Float[] ratios, final int rotation) {
if (ratios == null || boxes.size() == 0)
return null;
Rectangle smallestBox = null;
// find smallest box
float smallestSquare = Float.MAX_VALUE;
for (Rectangle box : boxes) {
if (box != null) {
if (smallestBox == null) {
smallestBox = box;
}
if (smallestSquare > box.getWidth() * box.getHeight()) {
// set new smallest box
smallestSquare = box.getWidth() * box.getHeight();
smallestBox = box;
}
}
}
if (smallestBox == null)
return null; // no useable box was found
// rotate the ratios according to the rotation of the page
float[] rotRatios = rotateRatios(ratios, rotation);
// use smallest box as basis for calculation
Rectangle scaledBox = new Rectangle(smallestBox);
scaledBox.setLeft(smallestBox.getLeft() + (smallestBox.getWidth() * rotRatios[0]));
scaledBox.setBottom(smallestBox.getBottom() + (smallestBox.getHeight() * rotRatios[1]));
scaledBox.setRight(smallestBox.getLeft() + (smallestBox.getWidth() * (1 - rotRatios[2])));
scaledBox.setTop(smallestBox.getBottom() + (smallestBox.getHeight() * (1 - rotRatios[3])));
return scaledBox;
}
示例8: clusterPages
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
public static void clusterPages(ClusterJob clusterJob) throws IOException {
PdfReader reader = new PdfReader(clusterJob.getSource().getAbsolutePath());
ClusterCollection clusters = clusterJob.getClusterCollection();
for (int page = 1; page <= reader.getNumberOfPages(); page++) {
Rectangle layoutBox = reader.getBoxSize(page, "crop");
if (layoutBox == null) {
layoutBox = reader.getBoxSize(page, "media");
}
// create Cluster
// if the pagenumber should be excluded then use it as a
// discriminating parameter, else use default value
int pageNumber = -1;
if (clusterJob.getExcludedPageSet() != null && clusterJob.getExcludedPageSet().contains(page)) {
pageNumber = page;
}
SingleCluster tmpCluster = new SingleCluster(page % 2 == 0, (int) layoutBox.getWidth(),
(int) layoutBox.getHeight(), pageNumber);
clusters.addPageToCluster(tmpCluster, page);
}
// for every cluster create a set of pages on which the preview will
// be based
for (SingleCluster cluster : clusters.getClusterToPagesMapping().keySet()) {
cluster.choosePagesToMerge(clusters.getClusterToPagesMapping().get(cluster));
}
reader.close();
}
示例9: doInBackground
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
@Override
protected Exception doInBackground(String... photos) {
try {
// Get output Directory
// Create the PDF and set some metadata
Document document = new Document(PageSize.A4, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN, DOCUMENT_MARGIN);
Resources resources = mContext.getResources();
document.addTitle(mFilename);
document.addAuthor(resources.getString(R.string.app_name));
document.addSubject(resources.getString(R.string.file_subject));
// Open the file that we will write the pdf to.
java.io.File fileContent = new java.io.File(ImageUtils.getAlbumStorageDir(MainActivity.ALBUM_NAME) + mFilename);
OutputStream outputStream = new FileOutputStream(fileContent);
PdfWriter.getInstance(document, outputStream);
document.open();
// Get the document's size
Rectangle pageSize = document.getPageSize();
float pageWidth = pageSize.getWidth() - (document.leftMargin() + document.rightMargin());
float pageHeight = pageSize.getHeight();
//Loop through images and add them to the document
for (String path : photos) {
Image image = Image.getInstance(path);
image.scaleToFit(pageWidth, pageHeight);
document.add(image);
document.newPage();
}
// Cleanup
document.close();
outputStream.close();
// Upload time!
FileContent mediaContent = new FileContent("application/pdf", fileContent);
File body = new File();
if (mFolder != null)
body.setParents(Arrays.asList(new ParentReference().setId(mFolder.getId())));
body.setTitle(mFilename);
body.setDescription(resources.getString(R.string.file_subject));
body.setMimeType("application/pdf");
Drive.Files.Insert insert = mService.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
uploader.setProgressListener(new FileProgressListener());
File file = insert.execute();
Log.d("C2P", "File Id: " + file.getId());
/* Database Code */
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
//file.getFileSize().toString()
String parentFolder = mFolder != null ? mFolder.getId() : "root";
Long size = file.getFileSize();
String fileSizeString = humanReadableByteCount(size);
Upload upload = new Upload(-1, mFilename, mFolderPath, fileSizeString, parentFolder, format.format(date), mService.about().get().execute().getUser().getEmailAddress());
UploadDataAdapter mUploadDataAdapter = new UploadDataAdapter(mContext);
mUploadDataAdapter.open();
mUploadDataAdapter.addUpload(upload);
mUploadDataAdapter.close();
} catch (Exception e) {
Log.d("C2P", "ERROR", e);
return e;
}
return null;
}
示例10: getCenterY
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
/**
* Gets the Y value for centering the watermark image
*
* @param r
* @param img
* @return
*/
protected float getCenterY(Rectangle r, Image img)
{
float y = 0;
float pdfheight = r.getHeight();
float imgheight = img.getHeight();
y = (pdfheight - imgheight) / 2;
return y;
}
示例11: signWithCustomLayer2
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
/**
* <a href="https://stackoverflow.com/questions/45062602/itext-pdfappearence-issue">
* Text - PDFAppearence issue
* </a>
* <p>
* This test shows how one can create a custom signature layer 2.
* As the OP of the question at hand mainly wants to generate a
* pure DESCRIPTION appearance that uses the whole area, we here
* essentially copy the PdfSignatureAppearance.getAppearance code
* for generating layer 2 in pure DESCRIPTION mode and apply it
* to a plain pre-fetched layer 2.
* </p>
*/
@Test
public void signWithCustomLayer2() throws IOException, DocumentException, GeneralSecurityException
{
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf") )
{
PdfReader reader = new PdfReader(resource);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "test-customLayer2.pdf"));
PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// This essentially is the PdfSignatureAppearance.getAppearance code
// for generating layer 2 in pure DESCRIPTION mode applied to a plain
// pre-fetched layer 2.
// vvvvv
PdfTemplate layer2 = appearance.getLayer(2);
String text = "We're using iText to put a text inside a signature placeholder in a PDF. "
+ "We use a code snippet similar to this to define the Signature Appearence.\n"
+ "Everything works fine, but the signature text does not fill all the signature "
+ "placeholder area as expected by us, but the area filled seems to have an height "
+ "that is approximately the 70% of the available space.\n"
+ "As a result, sometimes especially if the length of the signature text is quite "
+ "big, the signature text does not fit in the placeholder and the text is striped "
+ "away.";
Font font = new Font();
float size = font.getSize();
final float MARGIN = 2;
Rectangle dataRect = new Rectangle(
MARGIN,
MARGIN,
appearance.getRect().getWidth() - MARGIN,
appearance.getRect().getHeight() - MARGIN);
if (size <= 0) {
Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight());
size = ColumnText.fitText(font, text, sr, 12, appearance.getRunDirection());
}
ColumnText ct = new ColumnText(layer2);
ct.setRunDirection(appearance.getRunDirection());
ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT);
ct.go();
// ^^^^^
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain, null, null, null, 0, subfilter);
}
}
示例12: Format
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
private Format(final Rectangle rectangle) {
width = rectangle.getWidth();
height = rectangle.getHeight();
}
示例13: writeAlignedText
import com.itextpdf.text.Rectangle; //導入方法依賴的package包/類
/**
* Writes text watermark to one of the 5 preconfigured locations
*
* @param pcb
* @param r
* @param tokens
* @param size
* @param position
*/
private void writeAlignedText(PdfContentByte pcb, Rectangle r, Vector<String> tokens, float size, String position)
{
// get the dimensions of our 'rectangle' for text
float height = size * tokens.size();
float width = 0;
float centerX = 0, startY = 0;
for (int i = 0; i < tokens.size(); i++)
{
if (pcb.getEffectiveStringWidth(tokens.get(i), false) > width)
{
width = pcb.getEffectiveStringWidth(tokens.get(i), false);
}
}
// now that we have the width and height, we can calculate the center
// position for
// the rectangle that will contain our text.
if (position.equals(POSITION_BOTTOMLEFT))
{
centerX = width / 2 + PAD;
startY = 0 + PAD + height;
}
else if (position.equals(POSITION_BOTTOMRIGHT))
{
centerX = r.getWidth() - (width / 2) - PAD;
startY = 0 + PAD + height;
}
else if (position.equals(POSITION_TOPLEFT))
{
centerX = width / 2 + PAD;
startY = r.getHeight() - (PAD * 2);
}
else if (position.equals(POSITION_TOPRIGHT))
{
centerX = r.getWidth() - (width / 2) - PAD;
startY = r.getHeight() - (PAD * 2);
}
else if (position.equals(POSITION_CENTER))
{
centerX = r.getWidth() / 2;
startY = (r.getHeight() / 2) + (height / 2);
}
// apply text to PDF
pcb.beginText();
for (int t = 0; t < tokens.size(); t++)
{
pcb.showTextAligned(PdfContentByte.ALIGN_CENTER, tokens.get(t), centerX, startY - (size * t), 0);
}
pcb.endText();
}