本文整理匯總了C#中iTextSharp.text.pdf.PdfFileSpecification.SetUnicodeFileName方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfFileSpecification.SetUnicodeFileName方法的具體用法?C# PdfFileSpecification.SetUnicodeFileName怎麽用?C# PdfFileSpecification.SetUnicodeFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfFileSpecification
的用法示例。
在下文中一共展示了PdfFileSpecification.SetUnicodeFileName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FileEmbedded
/**
* 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));
fs.SetUnicodeFileName(fileDisplay, false);
PdfEFStream stream;
Stream inp = null;
PdfIndirectReference refi;
PdfIndirectReference refFileLength = null;
try {
if (fileStore == null) {
refFileLength = writer.PdfIndirectReference;
if (File.Exists(filePath)) {
inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
}
else {
if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
WebRequest wr = WebRequest.Create(filePath);
wr.Credentials = CredentialCache.DefaultCredentials;
inp = wr.GetResponse().GetResponseStream();
}
else {
inp = StreamUtil.GetResourceStream(filePath);
if (inp == null)
throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
}
}
stream = new PdfEFStream(inp, writer);
}
else
stream = new PdfEFStream(fileStore);
stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
stream.FlateCompress(compressionLevel);
PdfDictionary param = new PdfDictionary();
if (fileParameter != null)
param.Merge(fileParameter);
if (!param.Contains(PdfName.MODDATE)) {
param.Put(PdfName.MODDATE, new PdfDate());
}
if (fileStore != null) {
param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
stream.Put(PdfName.PARAMS, param);
}
else {
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();
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);
f.Put(PdfName.UF, refi);
fs.Put(PdfName.EF, f);
return fs;
}