本文整理匯總了Java中com.itextpdf.text.pdf.PdfReader.getCropBox方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfReader.getCropBox方法的具體用法?Java PdfReader.getCropBox怎麽用?Java PdfReader.getCropBox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.getCropBox方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSwitchOrientation
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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();
}
}
示例2: splitIntoHalfPages
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* This methods creates a copy of the source document containing each page twice,
* once with the cropbox limited to the left half page, once to the right one.
*/
void splitIntoHalfPages(InputStream source, File target) throws IOException, DocumentException
{
final PdfReader reader = new PdfReader(source);
try ( OutputStream targetStream = new FileOutputStream(target) )
{
Document document = new Document();
PdfCopy copy = new PdfCopy(document, targetStream);
document.open();
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
PdfDictionary pageN = reader.getPageN(page);
Rectangle cropBox = reader.getCropBox(page);
PdfArray leftBox = new PdfArray(new float[]{cropBox.getLeft(), cropBox.getBottom(), (cropBox.getLeft() + cropBox.getRight()) / 2.0f, cropBox.getTop()});
PdfArray rightBox = new PdfArray(new float[]{(cropBox.getLeft() + cropBox.getRight()) / 2.0f, cropBox.getBottom(), cropBox.getRight(), cropBox.getTop()});
PdfImportedPage importedPage = copy.getImportedPage(reader, page);
pageN.put(PdfName.CROPBOX, leftBox);
copy.addPage(importedPage);
pageN.put(PdfName.CROPBOX, rightBox);
copy.addPage(importedPage);
}
document.close();
}
finally
{
reader.close();
}
}
示例3: find
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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;
}
示例4: findExt
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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;
}
示例5: testAddAnnotationLikeJasonY
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/41949253/how-to-add-columntext-as-an-annotation-in-itext-pdf">
* How to add columnText as an annotation in itext pdf
* </a>
* <p>
* This test demonstrates how to use a columntext in combination with an annotation.
* </p>
*/
@Test
public void testAddAnnotationLikeJasonY() throws IOException, DocumentException
{
String html ="<html><h1>Header</h1><p>A paragraph</p><p>Another Paragraph</p></html>";
String css = "h1 {color: red;}";
ElementList elementsList = XMLWorkerHelper.parseToElementList(html, css);
try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "JasonY.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(reader, result);
Rectangle cropBox = reader.getCropBox(1);
PdfAnnotation annotation = stamper.getWriter().createAnnotation(cropBox, PdfName.FREETEXT);
PdfAppearance appearance = PdfAppearance.createAppearance(stamper.getWriter(), cropBox.getWidth(), cropBox.getHeight());
ColumnText ct = new ColumnText(appearance);
ct.setSimpleColumn(new Rectangle(cropBox.getWidth(), cropBox.getHeight()));
elementsList.forEach(element -> ct.addElement(element));
ct.go();
annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, appearance);
stamper.addAnnotation(annotation, 1);
stamper.close();
reader.close();
}
}
示例6: cleanUpContent
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/32448118/issue-in-removing-header-and-footer-in-pdf-using-itext-pdf">
* Issue in Removing Header and Footer in PDF using iText PDF
* </a>
* <br/>
* <a href="https://www.dropbox.com/s/xznwx4ogemsgd42/spec.pdf?dl=0">
* spec.pdf
* </a>
* <p>
* removes header and footer based on the configuration
* </p>
* <p>
* This is the original code by the OP whith minor changes to render it runnable
* in this testarea project.
* </p>
* <p>
* Issues observed on landscape pages of the test file can be prevented by using
* <code>stamper.setRotateContents(false)</code>, see below.
* </p>
*/
public static void cleanUpContent(PdfReader reader,String targetPDFFile, float upperY, float lowerY, boolean highLightColor) throws Exception
{
OutputStream outputStream = new FileOutputStream(targetPDFFile);
PdfStamper stamper = new PdfStamper(reader, outputStream);
//stamper.setRotateContents(false);
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
for (int i = 1; i <= reader.getNumberOfPages(); i++)
{
Rectangle pageRect = reader.getCropBox(i);
Rectangle headerRect= new Rectangle(pageRect);
headerRect.setBottom(headerRect.getTop()-upperY);
Rectangle footerRect= new Rectangle(pageRect);
footerRect.setTop(footerRect.getBottom()+lowerY);
if(highLightColor)
{
cleanUpLocations.add(new PdfCleanUpLocation(i, headerRect,BaseColor.GREEN));
cleanUpLocations.add(new PdfCleanUpLocation(i, footerRect,BaseColor.GREEN));
}
else
{
cleanUpLocations.add(new PdfCleanUpLocation(i, headerRect));
cleanUpLocations.add(new PdfCleanUpLocation(i, footerRect));
}
}
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
try
{
cleaner.cleanUp();
}
catch(Exception e)
{
e.printStackTrace();
}
stamper.close();
reader.close();
outputStream.flush();
outputStream.close();
}