本文整理匯總了Java中com.itextpdf.text.pdf.PdfReader.getNumberOfPages方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfReader.getNumberOfPages方法的具體用法?Java PdfReader.getNumberOfPages怎麽用?Java PdfReader.getNumberOfPages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.getNumberOfPages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPdfContent
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
private String getPdfContent(String pdfFile) {
try {
PdfReader reader = new PdfReader(pdfFile);
StringBuffer sb = new StringBuffer();
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
TextExtractionStrategy strategy;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
sb.append(strategy.getResultantText());
}
reader.close();
return sb.toString();
} catch (IOException e) {
throw new IllegalArgumentException("Not able to read file " + pdfFile, e);
}
}
示例2: createCropJob
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public static CropJob createCropJob(ClusterJob curClusterJob) throws IOException {
File source = curClusterJob.getSource();
if (source != null && source.exists()) {
PdfReader reader = new PdfReader(source.getAbsolutePath());
CropJob result = new CropJob(source, reader.getNumberOfPages(), reader.getInfo(),
SimpleBookmark.getBookmark(reader));
reader.close();
result.setClusterCollection(curClusterJob.getClusterCollection());
return result;
}
return null;
}
示例3: testRemoveTransparentGraphicsTransparency
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
@Test
public void testRemoveTransparentGraphicsTransparency() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("transparency.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "transparency-noTransparency.pdf")))
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result);
PdfContentStreamEditor editor = new TransparentGraphicsRemover();
for (int i = 1; i <= pdfReader.getNumberOfPages(); i++)
{
editor.editPage(pdfStamper, i);
}
pdfStamper.close();
}
}
示例4: testHideContenUnderRectangle
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/43870545/filling-a-pdf-with-itextsharp-and-then-hiding-the-base-layer">
* Filling a PDF with iTextsharp and then hiding the base layer
* </a>
* <p>
* This test shows how to cover all content using a white rectangle.
* </p>
*/
@Test
public void testHideContenUnderRectangle() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("document.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "document-hiddenContent.pdf")))
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result);
for (int page = 1; page <= pdfReader.getNumberOfPages(); page++)
{
Rectangle pageSize = pdfReader.getPageSize(page);
PdfContentByte canvas = pdfStamper.getOverContent(page);
canvas.setColorFill(BaseColor.WHITE);
canvas.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight());
canvas.fill();
}
pdfStamper.close();
}
}
示例5: testCertifiedSchoolList_9_16_2015
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
@Test
public void testCertifiedSchoolList_9_16_2015() throws IOException
{
try ( Writer data = new OutputStreamWriter(new FileOutputStream(new File(RESULT_FOLDER, "data.txt")), "UTF-8");
Writer nonData = new OutputStreamWriter(new FileOutputStream(new File(RESULT_FOLDER, "non-data.txt")), "UTF-8");
InputStream resource = getClass().getResourceAsStream("certified-school-list-9-16-2015.pdf") )
{
CertifiedSchoolListExtractionStrategy strategy = new CertifiedSchoolListExtractionStrategy(data, nonData);
PdfReader reader = new PdfReader(resource);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
for (int page = 1; page <= reader.getNumberOfPages(); page++)
parser.processContent(page, strategy);
// parser.processContent(28, strategy);
strategy.close();
}
}
示例6: extractAndStoreSimple
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
String extractAndStoreSimple(PdfReader reader, String format) throws IOException
{
StringBuilder builder = new StringBuilder();
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
String pageText = extractSimple(reader, page);
Files.write(Paths.get(String.format(format, page)), pageText.getBytes("UTF8"));
if (page > 1)
builder.append("\n\n");
builder.append(pageText);
}
return builder.toString();
}
示例7: ExtractPages
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public static byte[] ExtractPages(String pdfDocument, int startPage, int endPage) throws IOException, DocumentException
{
try (InputStream pdfDocumentStream = SmartMerging.class.getResourceAsStream(pdfDocument))
{
PdfReader reader = new PdfReader(pdfDocumentStream);
int numberOfPages = reader.getNumberOfPages();
int endPageResolved = endPage > 0 ? endPage : numberOfPages;
if (startPage > numberOfPages || endPageResolved > numberOfPages)
System.err.printf("Error: page indices (%s, %s) out of bounds. Document has {2} pages.", startPage, endPageResolved, numberOfPages);
byte[] outputDocument;
try (ByteArrayOutputStream msOut = new ByteArrayOutputStream())
{
Document doc = new Document();
PdfCopy pdfCopyProvider = new PdfCopy(doc, msOut);
doc.open();
for (int i = startPage; i <= endPageResolved; i++)
{
PdfImportedPage page = pdfCopyProvider.getImportedPage(reader, i);
pdfCopyProvider.addPage(page);
}
doc.close();
reader.close();
outputDocument = msOut.toByteArray();
}
return outputDocument;
}
}
示例8: clusterPages
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的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;
}
示例9: testIdentity20150211600
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
@Test
public void testIdentity20150211600() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/20150211600.PDF");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "20150211600-identity.pdf")))
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result);
PdfContentStreamEditor identityEditor = new PdfContentStreamEditor();
for (int i = 1; i <= pdfReader.getNumberOfPages(); i++)
{
identityEditor.editPage(pdfStamper, i);
}
pdfStamper.close();
}
}
示例10: testRemoveTransparentGraphicsTest3
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
@Test
public void testRemoveTransparentGraphicsTest3() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("test3.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test3-noTransparency.pdf")))
{
PdfReader pdfReader = new PdfReader(resource);
PdfStamper pdfStamper = new PdfStamper(pdfReader, result);
PdfContentStreamEditor editor = new TransparentGraphicsRemover();
for (int i = 1; i <= pdfReader.getNumberOfPages(); i++)
{
editor.editPage(pdfStamper, i);
}
pdfStamper.close();
}
}
示例11: testExtractDoc1
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/40549977/reading-legacy-word-forms-checkboxes-converted-to-pdf">
* Reading legacy Word forms checkboxes converted to PDF
* </a>
* <br>
* <a href="https://www.dropbox.com/s/4z7ky3yy2yaj53i/Doc1.pdf?dl=0">
* Doc1.pdf
* </a>
* <p>
* This test shows how one can extract the sample drawn "checkboxes" from the
* sample PDF provided by the OP.
* </p>
*/
@Test
public void testExtractDoc1() throws IOException
{
try ( InputStream resource = getClass().getResourceAsStream("Doc1.pdf"))
{
PdfReader pdfReader = new PdfReader(resource);
for (int page = 1; page <= pdfReader.getNumberOfPages(); page++)
{
System.out.printf("\nPage %s\n====\n", page);
CheckBoxExtractionStrategy strategy = new CheckBoxExtractionStrategy();
PdfReaderContentParser parser = new PdfReaderContentParser(pdfReader);
parser.processContent(page, strategy);
for (Box box : strategy.getBoxes())
{
Vector basePoint = box.getDiagonal().getStartPoint();
System.out.printf("at %s, %s - %s\n", basePoint.get(Vector.I1), basePoint.get(Vector.I2),
box.isChecked() ? "checked" : "unchecked");
}
}
}
}
示例12: PDFManager
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public PDFManager(byte[] pdfData, X509Certificate cert) throws Exception {
reader = new PdfReader(pdfData);
bout = new ByteArrayOutputStream();
PdfStamper stp = PdfStamper.createSignature(reader, bout, '\0', null, true);
numPages = reader.getNumberOfPages();
x509Certificate = cert;
sap = stp.getSignatureAppearance();
}
示例13: parsePdf
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public void parsePdf(String filename) throws IOException {
PdfReader reader = new PdfReader(filename);
LOGGER.trace("Reading file " + filename);
pdfData = new HashMap<Integer, String>();
int numberOfPages = reader.getNumberOfPages();
for (int page = 1; page <= numberOfPages; page++) {
LOGGER.trace("Reading page " + page);
String textFromPage = PdfTextExtractor.getTextFromPage(reader, page);
pdfData.put(page, textFromPage);
}
}
示例14: TextExtractor
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public TextExtractor(InputStream is) throws IOException {
PdfReader pdfReader = new PdfReader(is);
PdfReaderContentParser parser = new PdfReaderContentParser(pdfReader);
int pages = pdfReader.getNumberOfPages();
for (int i = 1; i <= pages; i++) {
ImportRenderListener renderListener = new ImportRenderListener();
parser.processContent(i, renderListener);
pageText.add(renderListener.text);
}
}
示例15: getKeyWords
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public static float[] getKeyWords(String filePath) {
try {
PdfReader pdfReader = new PdfReader(filePath);
int pageNum = pdfReader.getNumberOfPages();
PdfReaderContentParser pdfReaderContentParser = new PdfReaderContentParser(pdfReader);
// 下標從1開始
for (i = 1; i <= pageNum; i++) {
pdfReaderContentParser.processContent(i, new RenderListener() {
public void renderText(TextRenderInfo textRenderInfo) {
String text = textRenderInfo.getText();
System.out.println(i + ":" +text);
if (null != text && text.contains(KEY_WORD)) {
Float boundingRectange = textRenderInfo.getBaseline().getBoundingRectange();
resu = new float[3];
resu[0] = boundingRectange.x;
resu[1] = boundingRectange.y;
resu[2] = i;
}
}
public void renderImage(ImageRenderInfo arg0) {
}
public void endTextBlock() {
}
public void beginTextBlock() {
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
return resu;
}