本文整理汇总了C#中iTextSharp.text.pdf.RandomAccessFileOrArray类的典型用法代码示例。如果您正苦于以下问题:C# RandomAccessFileOrArray类的具体用法?C# RandomAccessFileOrArray怎么用?C# RandomAccessFileOrArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomAccessFileOrArray类属于iTextSharp.text.pdf命名空间,在下文中一共展示了RandomAccessFileOrArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestConstructionForType0WithoutToUnicodeMap
virtual public void TestConstructionForType0WithoutToUnicodeMap()
{
int pageNum = 2;
PdfName fontIdName = new PdfName("TT9");
string testFile = TestResourceUtils.GetResourceAsTempFile(TEST_RESOURCES_PATH, "type0FontWithoutToUnicodeMap.pdf");
RandomAccessFileOrArray f = new RandomAccessFileOrArray(testFile);
PdfReader reader = new PdfReader(f, null);
try
{
PdfDictionary fontsDic = reader.GetPageN(pageNum).GetAsDict(PdfName.RESOURCES).GetAsDict(PdfName.FONT);
PdfDictionary fontDicDirect = fontsDic.GetAsDict(fontIdName);
PRIndirectReference fontDicIndirect = (PRIndirectReference)fontsDic.Get(fontIdName);
Assert.AreEqual(PdfName.TYPE0, fontDicDirect.GetAsName(PdfName.SUBTYPE));
Assert.AreEqual("/Identity-H", fontDicDirect.GetAsName(PdfName.ENCODING).ToString());
Assert.IsNull(fontDicDirect.Get(PdfName.TOUNICODE), "This font should not have a ToUnicode map");
new DocumentFont(fontDicIndirect); // this used to throw an NPE
}
finally
{
reader.Close();
}
}
开发者ID:newlysoft,项目名称:itextsharp,代码行数:26,代码来源:DocumentFontTest.cs
示例2: ExtractImages
/// <summary>
/// Extract Image from PDF file and Store in Image Object
/// </summary>
/// <param name="pdfPath">Specify PDF Source Path</param>
/// <returns>elenco dei path relativi alle immagini estratte</returns>
public static List<string> ExtractImages(String pdfPath)
{
var pathTokens = pdfPath.Split(new char[] { '\\' });
var session = pathTokens[pathTokens.Length - 2];
var basePath = Path.GetDirectoryName(pdfPath);
var filename = Path.GetFileNameWithoutExtension(pdfPath);
List<string> urls = new List<string>();
RandomAccessFileOrArray RAFObj = null;
PdfReader PDFReaderObj = null;
PdfObject PDFObj = null;
PdfStream PDFStreamObj = null;
//try
//{
RAFObj = new RandomAccessFileOrArray(pdfPath);//(PDFSourcePath);
PDFReaderObj = new PdfReader(RAFObj, null);
var info = PDFReaderObj.Info;
var j = 0;
for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
{
PDFObj = PDFReaderObj.GetPdfObject(i);
if ((PDFObj != null) && PDFObj.IsStream())
{
PdfDictionary pd = (PdfDictionary)PDFObj;
PDFStreamObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
iTextSharp.text.pdf.PdfObject subtype = PDFStreamObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);
if ((subtype != null) && subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
{
filename = filename + "_" + (++j).ToString();
byte[] bytes = PdfReader.GetStreamBytesRaw((iTextSharp.text.pdf.PRStream)PDFStreamObj);
Tiff tiff = Tiff.Open(Path.Combine(basePath, filename + ".tif"), "w");
tiff.SetField(TiffTag.IMAGEWIDTH, UInt32.Parse(pd.Get(PdfName.WIDTH).ToString()));
tiff.SetField(TiffTag.IMAGELENGTH, UInt32.Parse(pd.Get(PdfName.HEIGHT).ToString()));
tiff.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
tiff.SetField(TiffTag.BITSPERSAMPLE, UInt32.Parse(pd.Get(PdfName.BITSPERCOMPONENT).ToString()));
tiff.SetField(TiffTag.SAMPLESPERPIXEL, 1);
tiff.WriteRawStrip(0, bytes, bytes.Length);
tiff.Close();
var bmp = tiffToBitmap(Path.Combine(basePath, filename + ".tif"));
if (bmp != null)
{
bmp.Save(Path.Combine(basePath, filename + ".bmp"));
urls.Add( session + "/" + filename + ".bmp");
}
}
}
}
PDFReaderObj.Close();
return urls;
}
开发者ID:nicola-ravera,项目名称:PlanCatKO,代码行数:63,代码来源:PdfImageExtractor.cs
示例3: GetGlobalSegment
/**
* Gets a byte array that can be used as a /JBIG2Globals,
* or null if not applicable to the given jbig2.
* @param ra an random access file or array
* @return a byte array
*/
public static byte[] GetGlobalSegment(RandomAccessFileOrArray ra ) {
try {
JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
sr.Read();
return sr.GetGlobal(true);
} catch {
return null;
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:15,代码来源:JBIG2Image.cs
示例4: TestSeek
virtual public void TestSeek()
{
RandomAccessFileOrArray rafoa = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(data));
rafoa.Seek(72);
for (int i = 72; i < data.Length; i++)
{
Assert.AreEqual(data[i], (byte)rafoa.Read());
}
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:9,代码来源:RandomAccessFileOrArrayTest.cs
示例5: GetJbig2Image
/**
* returns an Image representing the given page.
* @param ra the file or array containing the image
* @param page the page number of the image
* @return an Image object
*/
public static Image GetJbig2Image(RandomAccessFileOrArray ra, int page) {
if (page < 1)
throw new ArgumentException(MessageLocalization.GetComposedMessage("the.page.number.must.be.gt.eq.1"));
JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
sr.Read();
JBIG2SegmentReader.JBIG2Page p = sr.GetPage(page);
Image img = new ImgJBIG2(p.pageBitmapWidth, p.pageBitmapHeight, p.GetData(true), sr.GetGlobal(true));
return img;
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:16,代码来源:JBIG2Image.cs
示例6: TestFilePositionWithPushback
virtual public void TestFilePositionWithPushback()
{
RandomAccessFileOrArray rafoa = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(data));
long offset = 72;
rafoa.Seek(offset);
Assert.AreEqual(offset, rafoa.FilePointer);
byte pushbackVal = 42;
rafoa.PushBack(pushbackVal);
Assert.AreEqual(offset - 1, rafoa.FilePointer);
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:10,代码来源:RandomAccessFileOrArrayTest.cs
示例7: SetUp
virtual public void SetUp()
{
MemoryStream os = new MemoryStream();
for (int i = 0; i < 10000; i++)
{
os.WriteByte((byte)i);
}
data = os.ToArray();
rafoa = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(data));
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:10,代码来源:RandomAccessFileOrArrayTest.cs
示例8: AddJBIG2
// ---------------------------------------------------------------------------
public void AddJBIG2(Document document, String path) {
RandomAccessFileOrArray ra = new RandomAccessFileOrArray(path);
int n = JBIG2Image.GetNumberOfPages(ra);
Image img;
for (int i = 1; i <= n; i++) {
img = JBIG2Image.GetJbig2Image(ra, i);
img.ScaleToFit(523, 350);
document.Add(img);
}
}
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:11,代码来源:PagedImages.cs
示例9: GetJbig2Image
/**
* returns an Image representing the given page.
* @param ra the file or array containing the image
* @param page the page number of the image
* @return an Image object
*/
public static Image GetJbig2Image(RandomAccessFileOrArray ra, int page) {
if (page < 1)
throw new ArgumentException("The page number must be >= 1.");
JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
sr.Read();
JBIG2SegmentReader.JBIG2Page p = sr.GetPage(page);
Image img = new ImgJBIG2(p.pageBitmapWidth, p.pageBitmapHeight, p.GetData(true), sr.GetGlobal(true));
return img;
}
开发者ID:nicecai,项目名称:iTextSharp-4.1.6,代码行数:16,代码来源:JBIG2Image.cs
示例10: ExtractImagesFromPDF
public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
{
// NOTE: This will only get the first image it finds per page.
PdfReader pdf = new PdfReader(sourcePdf);
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);
try
{
for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
{
PdfDictionary pg = pdf.GetPageN(pageNumber);
// recursively search pages, forms and groups for images.
PdfObject obj = FindImageInPDFDictionary(pg);
if (obj != null)
{
int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
PdfStream pdfStrem = (PdfStream)pdfObj;
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
if ((bytes != null))
{
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
{
memStream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
// must save the file while stream is open.
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
string path = Path.Combine(outputPath, String.Format(@"{0}.jpg", pageNumber));
System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
System.Drawing.Imaging.ImageCodecInfo jpegEncoder = GetImageEncoder("JPEG");
img.Save(path, jpegEncoder, parms);
}
}
}
}
}
catch
{
throw;
}
finally
{
pdf.Close();
raf.Close();
}
}
开发者ID:alqadasifathi,项目名称:OfficeTools.Pdf2Image.Word2Image,代码行数:53,代码来源:Program.cs
示例11: EnumerateTTC
internal EnumerateTTC(byte[] ttcArray) {
fileName = "Byte array TTC";
rf = new RandomAccessFileOrArray(ttcArray);
FindNames();
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:5,代码来源:EnumerateTTC.cs
示例12: ReadUnsignedInt
private static long ReadUnsignedInt(RandomAccessFileOrArray stream,
bool isBigEndian)
{
if (isBigEndian) {
return stream.ReadUnsignedInt();
} else {
return stream.ReadUnsignedIntLE();
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:9,代码来源:TIFFDirectory.cs
示例13: ReadFloat
private float ReadFloat(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadFloat();
} else {
return stream.ReadFloatLE();
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:8,代码来源:TIFFDirectory.cs
示例14: ReadInt
private int ReadInt(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadInt();
} else {
return stream.ReadIntLE();
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:8,代码来源:TIFFDirectory.cs
示例15: Initialize
private void Initialize(RandomAccessFileOrArray stream) {
long nextTagOffset = 0L;
long maxOffset = (long) stream.Length;
int i, j;
IFDOffset = stream.FilePointer;
numEntries = ReadUnsignedShort(stream);
fields = new TIFFField[numEntries];
for (i = 0; (i < numEntries) && (nextTagOffset < maxOffset); i++) {
int tag = ReadUnsignedShort(stream);
int type = ReadUnsignedShort(stream);
int count = (int)(ReadUnsignedInt(stream));
bool processTag = true;
// The place to return to to read the next tag
nextTagOffset = stream.FilePointer + 4;
try {
// If the tag data can't fit in 4 bytes, the next 4 bytes
// contain the starting offset of the data
if (count*sizeOfType[type] > 4) {
long valueOffset = ReadUnsignedInt(stream);
// bounds check offset for EOF
if (valueOffset < maxOffset) {
stream.Seek(valueOffset);
}
else {
// bad offset pointer .. skip tag
processTag = false;
}
}
} catch (ArgumentOutOfRangeException) {
// if the data type is unknown we should skip this TIFF Field
processTag = false;
}
if (processTag) {
fieldIndex[tag] = i;
Object obj = null;
switch (type) {
case TIFFField.TIFF_BYTE:
case TIFFField.TIFF_SBYTE:
case TIFFField.TIFF_UNDEFINED:
case TIFFField.TIFF_ASCII:
byte[] bvalues = new byte[count];
stream.ReadFully(bvalues, 0, count);
if (type == TIFFField.TIFF_ASCII) {
// Can be multiple strings
int index = 0, prevIndex = 0;
List<string> v = new List<string>();
while (index < count) {
while ((index < count) && (bvalues[index++] != 0));
// When we encountered zero, means one string has ended
char[] cht = new char[index - prevIndex];
Array.Copy(bvalues, prevIndex, cht, 0, index - prevIndex);
v.Add(new String(cht));
prevIndex = index;
}
count = v.Count;
String[] strings = new String[count];
for (int c = 0 ; c < count; c++) {
strings[c] = v[c];
}
obj = strings;
} else {
obj = bvalues;
}
break;
case TIFFField.TIFF_SHORT:
char[] cvalues = new char[count];
for (j = 0; j < count; j++) {
cvalues[j] = (char)(ReadUnsignedShort(stream));
}
obj = cvalues;
break;
case TIFFField.TIFF_LONG:
long[] lvalues = new long[count];
for (j = 0; j < count; j++) {
lvalues[j] = ReadUnsignedInt(stream);
}
obj = lvalues;
break;
case TIFFField.TIFF_RATIONAL:
long[][] llvalues = new long[count][];
for (j = 0; j < count; j++) {
//.........这里部分代码省略.........
开发者ID:jagruti23,项目名称:itextsharp,代码行数:101,代码来源:TIFFDirectory.cs
示例16: TIFFDirectory
/**
* Constructs a TIFFDirectory from a SeekableStream.
* The directory parameter specifies which directory to read from
* the linked list present in the stream; directory 0 is normally
* read but it is possible to store multiple images in a single
* TIFF file by maintaing multiple directories.
*
* @param stream a SeekableStream to read from.
* @param directory the index of the directory to read.
*/
public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
{
long global_save_offset = stream.FilePointer;
long ifd_offset;
// Read the TIFF header
stream.Seek(0L);
int endian = stream.ReadUnsignedShort();
if (!IsValidEndianTag(endian)) {
throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.endianness.tag.not.0x4949.or.0x4d4d"));
}
isBigEndian = (endian == 0x4d4d);
int magic = ReadUnsignedShort(stream);
if (magic != 42) {
throw new ArgumentException(MessageLocalization.GetComposedMessage("bad.magic.number.should.be.42"));
}
// Get the initial ifd offset as an unsigned int (using a long)
ifd_offset = ReadUnsignedInt(stream);
for (int i = 0; i < directory; i++) {
if (ifd_offset == 0L) {
throw new ArgumentException(MessageLocalization.GetComposedMessage("directory.number.too.large"));
}
stream.Seek(ifd_offset);
int entries = ReadUnsignedShort(stream);
stream.Skip(12*entries);
ifd_offset = ReadUnsignedInt(stream);
}
stream.Seek(ifd_offset);
Initialize(stream);
stream.Seek(global_save_offset);
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:48,代码来源:TIFFDirectory.cs
示例17: RandomAccessFileOrArray
public RandomAccessFileOrArray(RandomAccessFileOrArray file)
{
filename = file.filename;
arrayIn = file.arrayIn;
startOffset = file.startOffset;
}
开发者ID:bmictech,项目名称:iTextSharp,代码行数:6,代码来源:RandomAccessFileOrArray.cs
示例18: ReadShort
// Methods to read primitive data types from the stream
private short ReadShort(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadShort();
} else {
return stream.ReadShortLE();
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:10,代码来源:TIFFDirectory.cs
示例19: GetFullFont
protected byte[] GetFullFont()
{
RandomAccessFileOrArray rf2 = null;
try {
rf2 = new RandomAccessFileOrArray(rf);
rf2.ReOpen();
byte[] b = new byte[rf2.Length];
rf2.ReadFully(b);
return b;
}
finally {
try {if (rf2 != null) rf2.Close();} catch {}
}
}
开发者ID:bmictech,项目名称:iTextSharp,代码行数:14,代码来源:TrueTypeFont.cs
示例20: ReadLong
private long ReadLong(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadLong();
} else {
return stream.ReadLongLE();
}
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:8,代码来源:TIFFDirectory.cs
注:本文中的iTextSharp.text.pdf.RandomAccessFileOrArray类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论