本文整理汇总了C#中Reader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.Close方法的具体用法?C# Reader.Close怎么用?C# Reader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_PdfImportStream_01
public static void Test_PdfImportStream_01(string inputPdfFile, string outputPdfFile, string streamFile)
{
_tr.WriteLine("import stream for object TPL1 of pdf file \"{0}\" from \"{1}\" and save pdf to \"{2}\"", inputPdfFile, streamFile, outputPdfFile);
PB_Pdf.PdfReader pr = null;
Reader r = null;
PB_Pdf.PdfWriter pw = null;
try
{
pr = new PB_Pdf.PdfReader(inputPdfFile);
//IPdfObject obj = ReadPdfObject(pr, idObject, "Object");
r = new Reader(streamFile);
//obj.stream = r.ReadBytes((int)r.Length);
//PdfNValue length = obj.value["Length"];
//if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", idObject);
//length.value.valueInt = obj.stream.Length;
pw = new PB_Pdf.PdfWriter(outputPdfFile, FileMode.Create);
pw.reader = pr;
IPdfObject info = ReadPdfObject(pr, pr.Trailer["Info"].value.valueObjectId, "Info");
pw.WriteObject(info, "Info");
IPdfObject root = ReadPdfObject(pr, pr.Trailer["Root"].value.valueObjectId, "Root");
pw.WriteObject(root, "Root");
IPdfObject pages = ReadPdfObject(pr, root.value["Pages"].value.valueObjectId, "Pages");
pw.WriteObject(pages);
IPdfObject page1 = ReadPdfObject(pr, pages.value["Kids"].value[0].valueObjectId, "Page 1");
pw.WriteObject(page1);
IPdfObject page1Content = ReadPdfObject(pr, page1.value["Contents"].value.valueObjectId, "Contents page 1");
pw.WriteObject(page1Content);
IPdfObject page1Ressource = ReadPdfObject(pr, page1.value["Resources"].value.valueObjectId, "Resources page 1");
pw.WriteObject(page1Ressource);
IPdfObject page1Ressource_01 = ReadPdfObject(pr, page1Ressource.value["XObject"].value["TPL1"].value.valueObjectId, "Resources page 1 /TPL1");
// import stream from file
page1Ressource_01.stream = r.ReadBytes((int)r.Length);
PdfNValue length = page1Ressource_01.value["Length"];
if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", page1Ressource_01.id);
length.value.valueInt = page1Ressource_01.stream.Length;
pw.WriteObjectWithChilds(page1Ressource_01);
}
finally
{
if (pr != null) pr.Close();
if (r != null) r.Close();
if (pw != null) pw.Close();
}
}
示例2: Test_PdfUpdateStream_01
public static void Test_PdfUpdateStream_01(string pdfFile, int objectId, string streamFile)
{
_tr.WriteLine("update stream for object {0} with \"{1}\" of pdf file \"{2}\"", objectId, streamFile, pdfFile);
PB_Pdf.PdfWriter pw = null;
Reader r = null;
try
{
pw = new PB_Pdf.PdfWriter(pdfFile, updatePdf: true);
IPdfObject obj = pw.reader.ReadObject(objectId);
r = new Reader(streamFile);
obj.stream = r.ReadBytes((int)r.Length);
PdfNValue length = obj.value["Length"];
if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", obj.id);
length.value.valueInt = obj.stream.Length;
pw.UpdateObject(obj);
}
finally
{
if (r != null) r.Close();
if (pw != null) pw.Close();
}
}