本文整理汇总了C#中iTextSharp.text.Document.AddDocListener方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AddDocListener方法的具体用法?C# Document.AddDocListener怎么用?C# Document.AddDocListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.AddDocListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractPages
public void ExtractPages(string inputFile, string outputFile,
List<int> extractPages, System.Windows.Forms.ProgressBar progres)
{
if (inputFile == outputFile)
{
System.Windows.Forms.MessageBox.Show("Nie możesz użyć pliku wejściowego jako wyjściowego do zapisu.");
}
PdfReader inputPDF = new PdfReader(inputFile);
Document doc = new Document();
PdfReader reader = new PdfReader(inputFile);
progres.Maximum = reader.NumberOfPages;
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Open();
doc.AddDocListener(writer);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
progres.Value = i;
if (extractPages.FindIndex(s => s == i) == -1) continue;
doc.SetPageSize(reader.GetPageSize(i));
doc.NewPage();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage pageImport = writer.GetImportedPage(reader, i);
int rot = reader.GetPageRotation(i);
if (rot == 90 || rot == 270)
{
cb.AddTemplate(pageImport, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(pageImport, 1.0F, 0, 0, 1.0F, 0, 0);
}
}
reader.Close();
doc.Close();
try
{
File.WriteAllBytes(outputFile, memoryStream.ToArray());
}
catch
{
throw new Exception("Błąd przy próbie zapisu do pliku. Upewnij się iż żaden inny proces obecnie go nie używa.");
}
}
}
示例2: RtfWriter2
/**
* Constructs a new RtfWriter that listens to the specified Document and
* writes its output to the Stream.
*
* @param doc The Document that this RtfWriter listens to
* @param os The Stream to write to
*/
protected RtfWriter2(Document doc, Stream os) : base(doc, os) {
doc.AddDocListener(this);
rtfDoc = new RtfDocument();
}
示例3: PdfCopy
/**
* Constructor
* @param document
* @param os outputstream
*/
public PdfCopy(Document document, Stream os)
: base(new PdfDocument(), os)
{
document.AddDocListener(pdf);
pdf.AddWriter(this);
indirectMap = new Dictionary<PdfReader,Dictionary<RefKey,IndirectReferences>>();
}
示例4: GetInstance
/**
* Use this method to get an instance of the <CODE>PdfWriter</CODE>.
*
* @return a new <CODE>PdfWriter</CODE>
* @param document The <CODE>Document</CODE> that has to be written
* @param os The <CODE>Stream</CODE> the writer has to write to.
* @param listener A <CODE>DocListener</CODE> to pass to the PdfDocument.
* @throws DocumentException on error
*/
public static PdfWriter GetInstance(Document document, Stream os, IDocListener listener)
{
PdfDocument pdf = new PdfDocument();
pdf.AddDocListener(listener);
document.AddDocListener(pdf);
PdfWriter writer = new PdfWriter(pdf, os);
pdf.AddWriter(writer);
return writer;
}
示例5: PdfCopy
/**
* Constructor
* @param document
* @param os outputstream
*/
public PdfCopy(Document document, Stream os) : base(new PdfDocument(), os) {
document.AddDocListener(pdf);
pdf.AddWriter(this);
indirectMap = new Hashtable();
}
示例6: open
/**
* @Method open a existing pdf file
* @Param path path of pdfFile
* @Return returns true if the file was opened or false if file couldn't be opened
*/
private bool open(DocumentData pdfDoc)
{
String path;
pdfDoc.Docsignedpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+ "\\"+ pdfDoc.Idoperation + "\\signed\\" + pdfDoc.Docname;
if (pdfDoc.documentHasBeenSigned())
{
path = pdfDoc.Docpath + "-signed.pdf";
//signedpath =
}
else
{
path = pdfDoc.Docpath;
}
if (File.Exists(pdfDoc.Docpath))
{
doc = new Document();
reader = new PdfReader(path);
fos = new FileStream(pdfDoc.Docsignedpath, FileMode.Create, FileAccess.Write);
writer = PdfWriter.GetInstance(doc, fos);
doc.Open();
doc.AddDocListener(writer);
return true;
}
return false;
}