本文整理汇总了C#中iTextSharp.text.pdf.RandomAccessFileOrArray类的典型用法代码示例。如果您正苦于以下问题:C# RandomAccessFileOrArray类的具体用法?C# RandomAccessFileOrArray怎么用?C# RandomAccessFileOrArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RandomAccessFileOrArray类属于iTextSharp.text.pdf命名空间,在下文中一共展示了RandomAccessFileOrArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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;
}
示例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;
}
}
示例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());
}
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例11: EnumerateTTC
internal EnumerateTTC(byte[] ttcArray) {
fileName = "Byte array TTC";
rf = new RandomAccessFileOrArray(ttcArray);
FindNames();
}
示例12: ReadUnsignedInt
private static long ReadUnsignedInt(RandomAccessFileOrArray stream,
bool isBigEndian)
{
if (isBigEndian) {
return stream.ReadUnsignedInt();
} else {
return stream.ReadUnsignedIntLE();
}
}
示例13: ReadFloat
private float ReadFloat(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadFloat();
} else {
return stream.ReadFloatLE();
}
}
示例14: ReadInt
private int ReadInt(RandomAccessFileOrArray stream)
{
if (isBigEndian) {
return stream.ReadInt();
} else {
return stream.ReadIntLE();
}
}
示例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++) {
//.........这里部分代码省略.........