本文整理匯總了C#中iTextSharp.text.pdf.PdfReader.SelectPages方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfReader.SelectPages方法的具體用法?C# PdfReader.SelectPages怎麽用?C# PdfReader.SelectPages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfReader
的用法示例。
在下文中一共展示了PdfReader.SelectPages方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddDocument
public void AddDocument(PdfReader reader, List<int> pagesToKeep) {
if (indirectMap.ContainsKey(reader)) {
throw new ArgumentException(MessageLocalization.GetComposedMessage("document.1.has.already.been.added", reader.ToString()));
}
reader.SelectPages(pagesToKeep);
AddDocument(reader);
}
示例2: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream) {
MovieTemplates mt = new MovieTemplates();
byte[] pdf = Utility.PdfBytes(mt);
PdfReader reader = new PdfReader(pdf);
using (ZipFile zip = new ZipFile()) {
reader.SelectPages("4-8");
zip.AddEntry(RESULT1, ManipulateWithStamper(reader));
/*
* can't figure out __WHY__, but if i don't reset the reader the example
* will __NOT__ work!
*/
reader = new PdfReader(pdf);
reader.SelectPages("4-8");
zip.AddEntry(RESULT2, ManipulateWithCopy(reader));
zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
zip.Save(stream);
}
}
示例3: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
using (ZipFile zip = new ZipFile())
{
Stationery s = new Stationery();
StampStationery ss = new StampStationery();
byte[] stationery = s.CreateStationary();
byte[] sStationery = ss.ManipulatePdf(
ss.CreatePdf(), stationery
);
byte[] insertPages = ManipulatePdf(sStationery, stationery);
zip.AddEntry(RESULT1, insertPages);
// reorder the pages in the PDF
PdfReader reader = new PdfReader(insertPages);
reader.SelectPages("3-41,1-2");
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
}
zip.AddEntry(RESULT2, ms.ToArray());
}
zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
zip.AddEntry(Utility.ResultFileName(ss.ToString() + ".pdf"), sStationery);
zip.Save(stream);
}
}
示例4: Test
public void Test()
{
PdfReader reader = new PdfReader(dataFile);
try
{
reader.SelectPages("4-8");
ManipulateWithStamper(reader);
ManipulateWithCopy(reader);
}
finally
{
reader.Close();
}
}
示例5: AddDocument
internal void AddDocument(PdfReader reader, ArrayList pagesToKeep)
{
if (!readers2intrefs.ContainsKey(reader) && reader.Tampered)
throw new DocumentException("The document was reused.");
reader = new PdfReader(reader);
reader.SelectPages(pagesToKeep);
if (reader.NumberOfPages == 0)
return;
reader.Tampered = false;
AddDocument(reader);
}
示例6: ProcessPdf
void ProcessPdf(string path)
{
using (var reader = new PdfReader(path))
{
// need this call to parse page numbers
reader.ConsolidateNamedDestinations();
var bookmarks = ParseBookMarks(SimpleBookmark.GetBookmark(reader));
for (int i = 0; i < bookmarks.Count; ++i)
{
int page = bookmarks[i].PageNumberInteger;
int nextPage = i + 1 < bookmarks.Count
// if not top of page will be missing content
? bookmarks[i + 1].PageNumberInteger - 1
/* alternative is to potentially add redundant content:
? bookmarks[i + 1].PageNumberInteger
*/
: reader.NumberOfPages;
string range = string.Format("{0}-{1}", page, nextPage);
// DEMO!
if (i < 1000)
{
var outputPath = Path.Combine(OUTPUT_DIR, bookmarks[i].GetFileName());
using (var readerCopy = new PdfReader(reader))
{
var number = bookmarks[i].Number;
readerCopy.SelectPages(range);
using (FileStream stream = new FileStream(outputPath, FileMode.Create))
{
using (var document = new Document())
{
using (var copy = new PdfCopy(document, stream))
{
document.Open();
int n = readerCopy.NumberOfPages;
for (int j = 0; j < n; )
{
copy.AddPage(copy.GetImportedPage(readerCopy, ++j));
}
}
}
}
}
}
}
}
}
示例7: MakePage
/// <summary>
/// Makes a single PDF page by reference.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="x">The running record total.</param>
/// <param name="dt">DataTable contaning report query.</param>
/// <param name="bdt">DataTable containing the report detail query.</param>
/// <param name="verticalSpacing">The vertical spacing between each line in the report detail.</param>
/// <param name="rpp">Records Per Page.</param>
/// <param name="page">Current Page to read from.</param>
/// <param name="currentPage">Current page to write to.</param>
/// <param name="totalPages">The total number of pages.</param>
/// <param name="queryArguments">The query arguments.</param>
/// <returns>rendered pdf page</returns>
private static MemoryStream MakePage(string filePath, ref int x, ref DataTable dt, ref DataTable bdt,
int verticalSpacing, int rpp, int page, int currentPage, int totalPages, Dictionary<string, object> queryArguments)
{
("FUNCTION /w binaryStream makePage").Debug(10);
MemoryStream ms = new MemoryStream();
PdfReader reader = new PdfReader(filePath);
PdfStamper stamp = new PdfStamper(reader, ms);
Dictionary<string, AField> docFields = new Dictionary<string, AField>();
reader.SelectPages(page.ToString());
float top = 0;
for(var y = 0; rpp > y; y++) {
if(y + x > bdt.Rows.Count - 1) { break; };
foreach(string fieldKey in stamp.AcroFields.Fields.Keys) {
if(fieldKey.StartsWith(">>") || fieldKey.StartsWith(">>image")) {
WriteField(x + y, 1, top, fieldKey, ref stamp, ref docFields, currentPage, totalPages, bdt, queryArguments);
}
}
top -= verticalSpacing;
}
foreach(string fieldKey in stamp.AcroFields.Fields.Keys) {
if(
(fieldKey.StartsWith(">") && (!fieldKey.StartsWith(">>"))) ||
(fieldKey.StartsWith(">image") && (!fieldKey.StartsWith(">>image"))) || fieldKey.StartsWith("_page")
) {
WriteField(0, 0, 0, fieldKey, ref stamp, ref docFields, currentPage, totalPages, dt, queryArguments);
}
}
reader.RemoveFields();
foreach(KeyValuePair<string, AField> f in docFields) {
Rectangle rect = f.Value.Rect;
string value = f.Value.Value;
TextField field = new TextField(stamp.Writer, rect, f.Key);
field.DefaultText = value;
field.FieldName = f.Key;
field.Options = iTextSharp.text.pdf.TextField.MULTILINE;
stamp.AddAnnotation(field.GetTextField(), 1);
}
stamp.Close();
reader.Close();
reader = new PdfReader(ms.GetBuffer());
MemoryStream os = new MemoryStream();
stamp = new PdfStamper(reader, os);
WriteAFieldCollection(ref stamp, docFields, filePath);
reader.RemoveFields();
stamp.Close();
reader.Close();
return os;
}
示例8: GetSecondPage
private PdfReader GetSecondPage()
{
PdfReader PDF = new PdfReader(PDFBytes);
PDF.RemoveUsageRights();
PDF.SelectPages("2");
return PDF;
}