public static GetResourceStream ( string key ) : System.Stream | ||
key | string | |
return | System.Stream |
internal static void ReadCmap(String name, List <char[]> planes) { String fullName = BaseFont.RESOURCE_PATH + "cmaps." + name; Stream inp = BaseFont.GetResourceStream(fullName); if (inp == null) { throw new IOException(MessageLocalization.GetComposedMessage("the.cmap.1.was.not.found", name)); } EncodeStream(inp, planes); inp.Close(); }
internal static void ReadCmap(String name, ArrayList planes) { String fullName = BaseFont.RESOURCE_PATH + "cmaps." + name; Stream inp = BaseFont.GetResourceStream(fullName); if (inp == null) { throw new IOException("The Cmap " + name + " was not found."); } EncodeStream(inp, planes); inp.Close(); }
public RandomAccessFileOrArray(String filename, bool forceRead) { if (!File.Exists(filename)) { if (filename.StartsWith("file:/") || filename.StartsWith("http://") || filename.StartsWith("https://")) { WebRequest wr = WebRequest.Create(new Uri(filename)); wr.Credentials = CredentialCache.DefaultCredentials; Stream isp = wr.GetResponse().GetResponseStream(); try { this.arrayIn = InputStreamToArray(isp); return; } finally { try { isp.Close(); }catch {} } } else { Stream isp = BaseFont.GetResourceStream(filename); if (isp == null) { throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filename)); } try { this.arrayIn = InputStreamToArray(isp); return; } finally { try { isp.Close(); }catch {} } } } else if (forceRead) { Stream s = null; try { s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); this.arrayIn = InputStreamToArray(s); } finally { try{ if (s != null) { s.Close(); } }catch {} } return; } this.filename = filename; rf = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); }
public RandomAccessFileOrArray(String filename, bool forceRead) { if (!File.Exists(filename)) { if (filename.StartsWith("file:/") || filename.StartsWith("http://") || filename.StartsWith("https://")) { Stream isp = WebRequest.Create(new Uri(filename)).GetResponse().GetResponseStream(); try { this.arrayIn = InputStreamToArray(isp); return; } finally { try { isp.Close(); }catch {} } } else { Stream isp = BaseFont.GetResourceStream(filename); if (isp == null) { throw new IOException(filename + " not found as file or resource."); } try { this.arrayIn = InputStreamToArray(isp); return; } finally { try { isp.Close(); }catch {} } } } else if (forceRead) { Stream s = null; try { s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); this.arrayIn = InputStreamToArray(s); } finally { try{ if (s != null) { s.Close(); } }catch {} } return; } this.filename = filename; rf = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); }
/** * Creates a file specification with the file embedded. The file may * come from the file system or from a byte array. * @param writer the <CODE>PdfWriter</CODE> * @param filePath the file path * @param fileDisplay the file information that is presented to the user * @param fileStore the byte array with the file. If it is not <CODE>null</CODE> * it takes precedence over <CODE>filePath</CODE> * @param mimeType the optional mimeType * @param fileParameter the optional extra file parameters such as the creation or modification date * @param compressionLevel the level of compression * @throws IOException on error * @return the file specification * @since 2.1.3 */ public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) { PdfFileSpecification fs = new PdfFileSpecification(); fs.writer = writer; fs.Put(PdfName.F, new PdfString(fileDisplay)); PdfEFStream stream; Stream inp = null; PdfIndirectReference refi; PdfIndirectReference refFileLength; try { refFileLength = writer.PdfIndirectReference; if (fileStore == null) { if (File.Exists(filePath)) { inp = new FileStream(filePath, FileMode.Open, FileAccess.Read); } else { if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) { WebRequest w = WebRequest.Create(filePath); inp = w.GetResponse().GetResponseStream(); } else { inp = BaseFont.GetResourceStream(filePath); if (inp == null) { throw new IOException(filePath + " not found as file or resource."); } } } stream = new PdfEFStream(inp, writer); } else { stream = new PdfEFStream(fileStore); } stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE); stream.FlateCompress(compressionLevel); stream.Put(PdfName.PARAMS, refFileLength); if (mimeType != null) { stream.Put(PdfName.SUBTYPE, new PdfName(mimeType)); } refi = writer.AddToBody(stream).IndirectReference; if (fileStore == null) { stream.WriteLength(); } PdfDictionary param = new PdfDictionary(); if (fileParameter != null) { param.Merge(fileParameter); } param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength)); writer.AddToBody(param, refFileLength); } finally { if (inp != null) { try{ inp.Close(); }catch {} } } PdfDictionary f = new PdfDictionary(); f.Put(PdfName.F, refi); fs.Put(PdfName.EF, f); return(fs); }
public RandomAccessFileOrArray(string filename, bool forceRead) { var cachedBytes = PdfResourceFileCache.Get(filename); if (cachedBytes != null) { ArrayIn = cachedBytes; return; } if (!File.Exists(filename)) { if (filename.StartsWith("file:/", StringComparison.OrdinalIgnoreCase) || filename.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || filename.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { var isp = filename.GetResponseStream(); try { ArrayIn = InputStreamToArray(isp); return; } finally { try { isp.Dispose(); } catch { } } } else { //Stream isp = BaseFont.GetResourceStream(filename); Stream isp = null; if ("-".Equals(filename)) { isp = ((StreamReader)Console.In).BaseStream; } else { isp = BaseFont.GetResourceStream(filename); } if (isp == null) { throw new IOException(filename + " not found as file or resource."); } try { ArrayIn = InputStreamToArray(isp); return; } finally { try { isp.Dispose(); } catch { } } } } else if (forceRead) { Stream s = null; try { s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); ArrayIn = InputStreamToArray(s); } finally { try { if (s != null) { s.Dispose(); } } catch { } } return; } Filename = filename; Rf = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); }
static GlyphList() { Stream istr = null; try { istr = BaseFont.GetResourceStream(BaseFont.RESOURCE_PATH + "glyphlist.txt"); if (istr == null) { String msg = "glyphlist.txt not found as resource."; throw new Exception(msg); } byte[] buf = new byte[1024]; MemoryStream outp = new MemoryStream(); while (true) { int size = istr.Read(buf, 0, buf.Length); if (size == 0) { break; } outp.Write(buf, 0, size); } istr.Close(); istr = null; String s = PdfEncodings.ConvertToString(outp.ToArray(), null); StringTokenizer tk = new StringTokenizer(s, "\r\n"); while (tk.HasMoreTokens()) { String line = tk.NextToken(); if (line.StartsWith("#")) { continue; } StringTokenizer t2 = new StringTokenizer(line, " ;\r\n\t\f"); String name = null; String hex = null; if (!t2.HasMoreTokens()) { continue; } name = t2.NextToken(); if (!t2.HasMoreTokens()) { continue; } hex = t2.NextToken(); int num = int.Parse(hex, NumberStyles.HexNumber); unicode2names[num] = name; names2unicode[name] = new int[] { num }; } } catch (Exception e) { Console.Error.WriteLine("glyphlist.txt loading error: " + e.Message); } finally { if (istr != null) { try { istr.Close(); } catch { // empty on purpose } } } }