本文整理匯總了Java中com.itextpdf.text.pdf.PdfReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfReader.close方法的具體用法?Java PdfReader.close怎麽用?Java PdfReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.close方法的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: testMergeGrandizerFiles
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/28991291/how-to-remove-whitespace-on-merge">
* How To Remove Whitespace on Merge
* </a>
* <p>
* Testing {@link PdfDenseMergeTool} using the OP's files.
* </p>
*/
@Test
public void testMergeGrandizerFiles() throws DocumentException, IOException
{
try ( InputStream docA = getClass().getResourceAsStream("Header.pdf");
InputStream docB = getClass().getResourceAsStream("Body.pdf");
InputStream docC = getClass().getResourceAsStream("Footer.pdf"); )
{
PdfDenseMergeTool tool = new PdfDenseMergeTool(PageSize.A4, 18, 18, 5);
PdfReader readerA = new PdfReader(docA);
PdfReader readerB = new PdfReader(docB);
PdfReader readerC = new PdfReader(docC);
try (FileOutputStream fos = new FileOutputStream(new File(RESULT_FOLDER, "GrandizerMerge.pdf")))
{
List<PdfReader> inputs = Arrays.asList(readerA, readerB, readerC);
tool.merge(fos, inputs);
}
finally
{
readerA.close();
readerB.close();
readerC.close();
}
}
}
示例3: closePassedStream
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* The <code>closePassedStream</code> method closes the stream passed.
*
* @param reader {@link PdfReader}
* @param document {@link Document}
* @param contentByte {@link PdfContentByte}
* @param writer {@link PdfWriter}
* @param fileInputStream {@link FileInputStream}
* @param fileOutputStream {@link FileOutputStream}
* @throws IOException {@link} if unable to close input or output stream
*/
private static void closePassedStream(final PdfReader reader, final Document document,
final PdfContentByte contentByte, final PdfWriter writer,
final FileInputStream fileInputStream, final FileOutputStream fileOutputStream) throws IOException {
if (null != reader) {
reader.close();
}
if (null != document) {
document.close();
}
if (null != contentByte) {
contentByte.closePath();
}
if (null != writer) {
writer.close();
}
if (null != fileInputStream) {
fileInputStream.close();
}
if (null != fileOutputStream) {
fileOutputStream.flush();
fileOutputStream.close();
}
}
示例4: testRedactLikeTieco
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="https://stackoverflow.com/questions/44304695/itext-5-5-11-bold-text-looks-blurry-after-using-pdfcleanupprocessor">
* iText 5.5.11 - bold text looks blurry after using PdfCleanUpProcessor
* </a>
* <br/>
* <a href="http://s000.tinyupload.com/index.php?file_id=52420782334200922303">
* before.pdf
* </a>
* <p>
* Indeed, the observation by the OP can be reproduced. The issue has been introduced
* into iText in commits d5abd23 and 9967627, both dated May 4th, 2015.
* </p>
*/
@Test
public void testRedactLikeTieco() throws DocumentException, IOException
{
try ( InputStream resource = getClass().getResourceAsStream("before.pdf");
OutputStream result = new FileOutputStream(new File(OUTPUTDIR, "before-redacted.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(reader, result);
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
cleanUpLocations.add(new PdfCleanUpLocation(1, new Rectangle(0f, 0f, 595f, 680f)));
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
cleaner.cleanUp();
stamper.close();
reader.close();
}
}
示例5: stampTextChanged
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* The OP's code transformed into Java changed with the work-around.
*/
void stampTextChanged(InputStream source, OutputStream target) throws DocumentException, IOException
{
Date today = new Date();
PdfReader reader = new PdfReader(source);
PdfStamper stamper = new PdfStamper(reader, target);
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
int tSize = 24;
String mark = "DRAFT " + today;
int angle = 45;
float height = reader.getPageSizeWithRotation(1).getHeight()/2;
float width = reader.getPageSizeWithRotation(1).getWidth()/2;
PdfContentByte cb = stamper.getOverContent(1);
cb.setFontAndSize(bf, tSize);
cb.beginText();
cb.setColorFill(new BaseColor(255,200,200));
cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
cb.endText();
stamper.close();
reader.close();
}
示例6: testDecryptAbc
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="https://stackoverflow.com/questions/45351357/how-to-decrypt-128bit-rc4-pdf-file-in-java-with-user-password-if-it-is-encrpted">
* How to decrypt 128bit RC4 pdf file in java with user password if it is encrpted with user as well as owner password
* </a>
* <br/>
* <a href="https://www.dropbox.com/s/pc74oox4y19awin/abc.pdf?dl=0">
* abc.pdf
* </a>
* <p>
* This code shows how to decrypt an encrypted PDF for which you have the
* user password, not the owner password. The procedure is closely related
* to <a href="https://stackoverflow.com/a/27876840/1729265">Bruno's answer
* here</a>.
* </p>
*/
@Test
public void testDecryptAbc() throws IOException, DocumentException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
try ( InputStream inputStream = getClass().getResourceAsStream("abc.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "abc-decrypted.pdf")) )
{
PdfReader.unethicalreading = true;
PdfReader reader = new PdfReader(inputStream, "abc123".getBytes());
Field encryptedField = PdfReader.class.getDeclaredField("encrypted");
encryptedField.setAccessible(true);
encryptedField.set(reader, false);
PdfStamper stamper = new PdfStamper(reader, outputStream);
stamper.close();
reader.close();
}
}
示例7: testRedactLikeShiranSEkanayake
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/38278816/remove-header-of-a-pdf-using-itext-pdfcleanupprocessor-does-not-work">
* Remove header of a pdf using iText PdfCleanUpProcessor does not work
* </a>
* <br/>
* <a href="https://www.dropbox.com/s/4u8vupjqc4st3ib/love.pdf?dl=0">
* love.pdf
* </a>
* <p>
* Cannot reproduce, I get a <code>org.apache.commons.imaging.ImageReadException: Invalid marker found in entropy data</code>.
* </p>
*/
@Test
public void testRedactLikeShiranSEkanayake() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("love.pdf");
OutputStream result = new FileOutputStream(new File(OUTPUTDIR, "love-redacted.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(reader, result);
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
for(int i=1; i<=reader.getNumberOfPages(); i++)
{
//System.out.println(i);
Rectangle mediabox = reader.getPageSize(i);
cleanUpLocations.add(new PdfCleanUpLocation(i, new Rectangle(0,800,1000,1000)));
}
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
cleaner.cleanUp();
stamper.close();
reader.close();
}
}
示例8: mark
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
void mark(InputStream input, OutputStream output, Pattern pattern) throws DocumentException, IOException
{
PdfReader reader = new PdfReader(input);
PdfStamper stamper = new PdfStamper(reader, output);
try {
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
for (int pageNr = 1; pageNr <= reader.getNumberOfPages(); pageNr++)
{
SearchTextLocationExtractionStrategy strategy = new SearchTextLocationExtractionStrategy(pattern);
parser.processContent(pageNr, strategy, Collections.emptyMap()).getResultantText();
Collection<TextRectangle> locations = strategy.getLocations(null);
if (locations.isEmpty())
continue;
PdfContentByte canvas = stamper.getOverContent(pageNr);
canvas.setRGBColorStroke(255, 255, 0);
for (TextRectangle location : locations)
{
canvas.rectangle(location.getMinX(), location.getMinY(), location.getWidth(), location.getHeight());
}
canvas.stroke();
}
stamper.close();
} finally {
reader.close();
}
}
示例9: testMergeGrandizerFiles
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/28991291/how-to-remove-whitespace-on-merge">
* How To Remove Whitespace on Merge
* </a>
* <p>
* Testing {@link PdfVeryDenseMergeTool} using the OP's files.
* </p>
*/
@Test
public void testMergeGrandizerFiles() throws DocumentException, IOException
{
try ( InputStream docA = getClass().getResourceAsStream("Header.pdf");
InputStream docB = getClass().getResourceAsStream("Body.pdf");
InputStream docC = getClass().getResourceAsStream("Footer.pdf"); )
{
PdfVeryDenseMergeTool tool = new PdfVeryDenseMergeTool(PageSize.A4, 18, 18, 5);
PdfReader readerA = new PdfReader(docA);
PdfReader readerB = new PdfReader(docB);
PdfReader readerC = new PdfReader(docC);
try (FileOutputStream fos = new FileOutputStream(new File(RESULT_FOLDER, "GrandizerMerge-veryDense.pdf")))
{
List<PdfReader> inputs = Arrays.asList(readerA, readerB, readerC);
tool.merge(fos, inputs);
}
finally
{
readerA.close();
readerB.close();
readerC.close();
}
}
}
示例10: fileNotFound
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
@Test(expected = IOException.class)
public void fileNotFound() throws IOException {
try {
PdfReader reader = new PdfReader("noLetter");
reader.close();
} catch (IOException e) {
throw e;
}
}
示例11: testRedactJavishsTest1
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/35374912/itext-cleaning-up-text-in-rectangle-without-cleaning-full-row">
* iText - Cleaning Up Text in Rectangle without cleaning full row
* </a>
* <br/>
* <a href="https://www.dropbox.com/s/zeljo2k8tly7yqi/Test1.pdf?dl=0">
* Test1.pdf
* </a>
* <p>
* With this new file the issue could be reproduced, indeed an iText issue.
* </p>
*/
@Test
public void testRedactJavishsTest1() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("Test1.pdf");
OutputStream result = new FileOutputStream(new File(OUTPUTDIR, "Test1-redactedJavish.pdf")) )
{
PdfReader reader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(reader, result);
List<Float> linkBounds = new ArrayList<Float>();
linkBounds.add(0, (float) 202.3);
linkBounds.add(1, (float) 588.6);
linkBounds.add(2, (float) 265.8);
linkBounds.add(3, (float) 599.7);
Rectangle linkLocation1 = new Rectangle(linkBounds.get(0), linkBounds.get(1), linkBounds.get(2), linkBounds.get(3));
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
cleanUpLocations.add(new PdfCleanUpLocation(1, linkLocation1, BaseColor.GRAY));
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
cleaner.cleanUp();
stamper.close();
reader.close();
}
}
示例12: createCropJob
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public static CropJob createCropJob(File source) throws IOException {
CropJob result = null;
if (source != null && source.exists()) {
PdfReader reader = new PdfReader(source.getAbsolutePath());
result = new CropJob(source, reader.getNumberOfPages(), reader.getInfo(), SimpleBookmark.getBookmark(reader));
reader.close();
return result;
}
return result;
}
示例13: testCreateEllipseAppearanceOnRotated
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/43205385/trying-to-draw-an-ellipse-annotation-and-the-border-on-the-edges-goes-thin-and-t">
* Trying to draw an ellipse annotation and the border on the edges goes thin and thik when i try to roatate pdf itext5
* </a>
* <p>
* This test creates an ellipse annotation with appearance on a page with rotation.
* The ellipse position looks ok but it is deformed.
* This is caused by iText rotating the annotation rectangle but not (how could it?) the appearance rectangle.
* </p>
* @see #testCreateEllipse()
* @see #testCreateEllipseAppearance()
* @see #testCreateEllipseOnRotated()
* @see #testCreateCorrectEllipseAppearanceOnRotated()
*/
@Test
public void testCreateEllipseAppearanceOnRotated() throws IOException, DocumentException
{
try ( InputStream resourceStream = getClass().getResourceAsStream("/mkl/testarea/itext5/merge/testA4.pdf");
OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "testA4-rotated-ellipse-appearance.pdf")) )
{
PdfReader reader = new PdfReader(resourceStream);
reader.getPageN(1).put(PdfName.ROTATE, new PdfNumber(90));
PdfStamper stamper = new PdfStamper(reader, outputStream);
Rectangle rect = new Rectangle(202 + 6f, 300, 200 + 100, 300 + 150);
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(stamper.getWriter(), rect, null, false);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setColor(BaseColor.RED);
annotation.setBorderStyle(new PdfBorderDictionary(3.5f, PdfBorderDictionary.STYLE_SOLID));
PdfContentByte cb = stamper.getOverContent(1);
PdfAppearance app = cb.createAppearance(rect.getWidth(), rect.getHeight());
app.setColorStroke(BaseColor.RED);
app.setLineWidth(3.5);
app.ellipse( 1.5, 1.5, rect.getWidth() - 1.5, rect.getHeight() - 1.5);
app.stroke();
annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
stamper.addAnnotation(annotation, 1);
stamper.close();
reader.close();
}
}
示例14: cleanUp
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
static byte[] cleanUp(byte[] source, List<PdfCleanUpLocation> cleanUpLocations) throws IOException, DocumentException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader(source);
PdfStamper stamper = new PdfStamper(reader, baos);
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
cleaner.cleanUp();
stamper.close();
reader.close();
return baos.toByteArray();
}
示例15: PdfMetaInformation
import com.itextpdf.text.pdf.PdfReader; //導入方法依賴的package包/類
public PdfMetaInformation(final File source) throws IOException {
PdfReader reader = new PdfReader(source.getAbsolutePath());
this.sourcePageCount = reader.getNumberOfPages();
this.sourceMetaInfo = reader.getInfo();
this.sourceBookmarks = SimpleBookmark.getBookmark(reader);
reader.close();
}