本文整理汇总了Java中com.lowagie.text.pdf.RandomAccessFileOrArray.close方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFileOrArray.close方法的具体用法?Java RandomAccessFileOrArray.close怎么用?Java RandomAccessFileOrArray.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.RandomAccessFileOrArray
的用法示例。
在下文中一共展示了RandomAccessFileOrArray.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentBytesForPage
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Gets the content stream of a page.
* @param pageNum the page number of page you want get the content stream from
* @return a byte array with the content stream of a page
* @throws IOException
*/
private byte[] getContentBytesForPage(int pageNum) throws IOException {
RandomAccessFileOrArray f = reader.getSafeFile();
byte[] contentBytes = reader.getPageContent(pageNum, f);
f.close();
return contentBytes;
}
示例2: listContentStreamForPage
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Writes information about a specific page from PdfReader to the specified output stream.
* @since 2.1.5
* @param reader the PdfReader to read the page content from
* @param pageNum the page number to read
* @param out the output stream to send the content to
* @throws IOException
*/
static public void listContentStreamForPage(PdfReader reader, int pageNum, PrintWriter out) throws IOException {
out.println("==============Page " + pageNum + "====================");
out.println("- - - - - Dictionary - - - - - -");
PdfDictionary pageDictionary = reader.getPageN(pageNum);
out.println(getDictionaryDetail(pageDictionary));
out.println("- - - - - Content Stream - - - - - -");
RandomAccessFileOrArray f = reader.getSafeFile();
byte[] contentBytes = reader.getPageContent(pageNum, f);
f.close();
InputStream is = new ByteArrayInputStream(contentBytes);
int ch;
while ((ch = is.read()) != -1){
out.print((char)ch);
}
out.println("- - - - - Text Extraction - - - - - -");
PdfTextExtractor extractor = new PdfTextExtractor(reader);
String extractedText = extractor.getTextFromPage(pageNum);
if (extractedText.length() != 0)
out.println(extractedText);
else
out.println("No text found on page " + pageNum);
out.println();
}
示例3: main
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Combines 2 tiff-files into 1 PDF (similar to tiffmesh).
*
* @param args
* [0] the file with the odd pages [1] the file with the even
* pages [2] the resulting file
*/
public void main(String... args) throws Exception {
if (args.length < 3) {
System.err.println("OddEven needs 3 Arguments.");
System.out
.println("Usage: com.lowagie.examples.objects.images.tiff.OddEven odd_file.tif even_file.tif combined_file.pdf");
return;
}
RandomAccessFileOrArray odd = new RandomAccessFileOrArray(args[0]);
RandomAccessFileOrArray even = new RandomAccessFileOrArray(args[1]);
Image img = TiffImage.getTiffImage(odd, 1);
Document document = new Document(new Rectangle(img.getScaledWidth(), img.getScaledHeight()));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(args[2]));
document.open();
PdfContentByte cb = writer.getDirectContent();
int count = Math.max(TiffImage.getNumberOfPages(odd), TiffImage.getNumberOfPages(even));
for (int c = 0; c < count; ++c) {
Image imgOdd = TiffImage.getTiffImage(odd, c + 1);
Image imgEven = TiffImage.getTiffImage(even, count - c);
document.setPageSize(new Rectangle(imgOdd.getScaledWidth(), imgOdd.getScaledHeight()));
document.newPage();
imgOdd.setAbsolutePosition(0, 0);
cb.addImage(imgOdd);
document.setPageSize(new Rectangle(imgEven.getScaledWidth(), imgEven.getScaledHeight()));
document.newPage();
imgEven.setAbsolutePosition(0, 0);
cb.addImage(imgEven);
}
odd.close();
even.close();
document.close();
}
示例4: listContentStreamForPage
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Writes information about a specific page from PdfReader to the specified
* output stream.
*
* @since 2.1.5
* @param reader
* the PdfReader to read the page content from
* @param pageNum
* the page number to read
* @param out
* the output stream to send the content to
* @throws IOException
*/
static public void listContentStreamForPage(PdfReader reader, int pageNum, PrintWriter out) throws IOException {
out.println("==============Page " + pageNum + "====================");
out.println("- - - - - Dictionary - - - - - -");
PdfDictionary pageDictionary = reader.getPageN(pageNum);
out.println(getDictionaryDetail(pageDictionary));
out.println("- - - - - Content Stream - - - - - -");
RandomAccessFileOrArray f = reader.getSafeFile();
byte[] contentBytes = reader.getPageContent(pageNum, f);
f.close();
InputStream is = new ByteArrayInputStream(contentBytes);
int ch;
while ((ch = is.read()) != -1) {
out.print((char) ch);
}
out.println("- - - - - Text Extraction - - - - - -");
PdfTextExtractor extractor = new PdfTextExtractor(reader);
String extractedText = extractor.getTextFromPage(pageNum);
if (extractedText.length() != 0)
out.println(extractedText);
else
out.println("No text found on page " + pageNum);
out.println();
}
示例5: process
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Reads the font data.
*
* @param ttfAfm
* the font as a <CODE>byte</CODE> array, possibly <CODE>null</CODE>
* @throws DocumentException
* the font is invalid
* @throws IOException
* the font file could not be read
*/
void process( ) throws DocumentException, IOException
{
positionTables = new HashMap<String, int[]>( );
metadataTables = new HashMap<String, byte[]>( );
try
{
rf = new RandomAccessFileOrArray( fileName );
if ( ttcIndex.length( ) > 0 )
{
int dirIdx = Integer.parseInt( ttcIndex );
if ( dirIdx < 0 )
throw new DocumentException( "The font index for "
+ fileName + " must be positive." );
String mainTag = readStandardString( 4 );
if ( !mainTag.equals( "ttcf" ) )
throw new DocumentException( fileName
+ " is not a valid TTC file." );
rf.skipBytes( 4 );
int dirCount = rf.readInt( );
if ( dirIdx >= dirCount )
throw new DocumentException( "The font index for "
+ fileName + " must be between 0 and "
+ ( dirCount - 1 ) + ". It was " + dirIdx + "." );
rf.skipBytes( dirIdx * 4 );
directoryOffset = rf.readInt( );
}
rf.seek( directoryOffset );
rf.readFully( directoryRawData );
int ttId = Util.getInt( directoryRawData, 0 );
if ( ttId != 0x00010000 && ttId != 0x4F54544F )
throw new DocumentException( fileName
+ " is not a valid TTF or OTF file." );
int num_tables = Util.getUnsignedShort( directoryRawData, 4 );
for ( int k = 0; k < num_tables; ++k )
{
byte[] rawData = new byte[16];
rf.readFully( rawData );
String tag = getStandardString( rawData, 0, 4 );
int table_location[] = new int[2];
table_location[0] = Util.getInt( rawData, 8 );
table_location[1] = Util.getInt( rawData, 12 );
positionTables.put( tag, table_location );
metadataTables.put( tag, rawData );
}
fontName = getBaseFont( );
fullName = getNames( 4 ); // full name
familyName = getNames( 1 ); // family name
notice = getNames( 0 );
version = getNames( 5 );
if ( !justNames )
{
fillTables( );
readGlyphWidths( );
readCMaps( );
readKerning( );
readBbox( );
GlyphWidths = null;
}
}
finally
{
if ( rf != null )
{
rf.close( );
if ( !embedded )
rf = null;
}
}
}