本文整理匯總了C#中iTextSharp.text.pdf.PdfCopy.AddJavaScript方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfCopy.AddJavaScript方法的具體用法?C# PdfCopy.AddJavaScript怎麽用?C# PdfCopy.AddJavaScript使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfCopy
的用法示例。
在下文中一共展示了PdfCopy.AddJavaScript方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreatePdf
// ---------------------------------------------------------------------------
/**
* Creates a PDF file with director names.
* @param pdf the PDF file to be used as a reader
*/
public byte[] CreatePdf(byte[] pdf) {
byte[] tmpDoc = null;
using ( MemoryStream ms = new MemoryStream() ) {
using (Document tmp = new Document()) {
PdfWriter writer = PdfWriter.GetInstance(tmp, ms);
// step 3
tmp.Open();
// step 4
var SQL =
@"SELECT name, given_name
FROM film_director
ORDER BY name, given_name";
using (var c = AdoDB.Provider.CreateConnection()) {
c.ConnectionString = AdoDB.CS;
using (DbCommand cmd = c.CreateCommand()) {
cmd.CommandText = SQL;
c.Open();
using (var r = cmd.ExecuteReader()) {
while ( r.Read() ) {
tmp.Add(CreateDirectorParagraph(writer, r));
}
}
}
}
}
tmpDoc = ms.ToArray();
}
jsContents = File.ReadAllText(
Path.Combine(Utility.ResourceJavaScript, RESOURCE)
);
List<byte[]> readers = new List<byte[]>() {tmpDoc, pdf};
using (MemoryStream ms = new MemoryStream()) {
// step 1
using (Document document = new Document()) {
// step 2
using (PdfCopy copy = new PdfCopy(document, ms)) {
// step 3
document.Open();
// step 4
copy.AddJavaScript(jsContents);
for (int i = 0; i < readers.Count; ++i) {
PdfReader reader = new PdfReader(readers[i]);
int n = reader.NumberOfPages;
for (int page = 0; page < n; ) {
copy.AddPage(copy.GetImportedPage(reader, ++page));
}
}
}
}
return ms.ToArray();
}
}