本文整理汇总了C#中iTextSharp.text.List.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToArray方法的具体用法?C# List.ToArray怎么用?C# List.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.List
的用法示例。
在下文中一共展示了List.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: parsePdfToHtml
/**
* Parses the PDF using PRTokeniser
* @param src the path to the original PDF file
* @param dest the path to the resulting text file
*/
public string[] parsePdfToHtml(string src)
{
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(src);
//StreamWriter output = new StreamWriter();
SimpleTextExtractionStrategy strategy = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
List<string> text = new List<string>(); ;
int pageCount = reader.NumberOfPages;
for (int pg = 1; pg <= pageCount; pg++)
{
text.Add(PdfTextExtractor.GetTextFromPage(reader, pg, strategy));
}
return text.ToArray();
}
示例2: ParsePdfToText
/**
* Parses the PDF using PRTokeniser
* @param src the path to the original PDF file
* @param dest the path to the resulting text file
*/
public string[] ParsePdfToText(string src)
{
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(src);
//reader.t
//StreamWriter output = new StreamWriter();
LocationTextExtractionStrategy strategy = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
List<string> text = new List<string>();
int pageCount = reader.NumberOfPages;
for (int pg = 1; pg <= pageCount; pg++)
{
string content=PdfTextExtractor.GetTextFromPage(reader, pg, strategy);
text.Add(content);
}
return text.ToArray();
}
示例3: Split
public void Split(string pdfPath, string destPath, BackgroundWorker worker = null)
{
//Inicjalizacja raportowania
if (this.ReportCheckBox.Checked) {
this.logsFile = new StreamWriter(Path.Combine(destPath, DateTime.Now.ToString("yyyyMMddHHmmss") + "RAPORT.txt"));
}
#region Wstępne rozpoznawanie
BitmapPDF pdfBitmap = new BitmapPDF(pdfPath);
PdfReader pdfDoc = new PdfReader(pdfPath);
int[] results = new int[pdfDoc.NumberOfPages];
for (int i = 0; i < pdfDoc.NumberOfPages && !worker.CancellationPending; i++) {
try {
results[i] = pdfBitmap.Current.AvgContent;
if (logsFile != null) {
logsFile.WriteLine(String.Format("Strona {0}: {1}", i + 1, results[i]));
}
worker.ReportProgress(((i + 1) * 100) / pdfDoc.NumberOfPages);
pdfBitmap.MoveNext();
} catch (Exception ex) {
//Będzie zawsze na końcu
Console.WriteLine(ex.Message);
}
}
pdfDoc.Close();
pdfBitmap.Dispose();
if (logsFile != null)
logsFile.Close();
#endregion
#region Właściwe rozdzielanie
if (!worker.CancellationPending) {
int j = 1;
List<int> pages = new List<int>();
foreach (int result in results) {
if (result > int.Parse(Properties.Settings.Default.MaxSensitivity)) {
if (pages.Count > 0) {
try {
string pdfDest = Path.Combine(destPath, DateTime.Now.ToString("yyyyMMddHHmmss") + j.ToString().PadLeft(4, '0') + ".pdf");
this.ExtractPages(pdfPath, pdfDest, pages.ToArray());
} catch (Exception ex) {
MessageBox.Show("Wystąpił błąd! " + ex.Message, "To jakiś straszny błąd!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
pages.Clear();
}
} else if (result > int.Parse(Properties.Settings.Default.MinSensitivity)) {
pages.Add(j);
}
j++;
}
//Na wszelki wypadek, gdyby końcówka została
if (pages.Count > 0) {
try {
string pdfDest = Path.Combine(destPath, DateTime.Now.ToString("yyyyMMddHHmmss") + j.ToString().PadLeft(4, '0') + ".pdf");
this.ExtractPages(pdfPath, pdfDest, pages.ToArray());
} catch (Exception ex) {
MessageBox.Show("Wystąpił błąd! " + ex.Message, "To jakiś straszny błąd!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
#endregion
worker.ReportProgress(0);
}
示例4: RetrieveSPFs
public JsonResult RetrieveSPFs(int pupilID)
{
if (IsAuthorized())
{
Teacher user = VaKEGradeRepository.Instance.GetTeacher(((Teacher)Session["User"]).ID);
Session["User"] = user;
Pupil pupil = VaKEGradeRepository.Instance.GetPupil(pupilID);
//Session["SelPupilID"] = pupil.ID;
if (pupil != null)
{
List<Database.SPF> spfs = pupil.SPFs.ToList();
GridData gData = new GridData() { page = 1 };
List<RowData> rows = new List<RowData>();
Session["pupilID"] = pupilID;
foreach (SPF spf in spfs)
{
rows.Add(new RowData() { id = spf.ID, cell = new string[] { spf.Subject.Name, spf.Level.ToString() } });
}
gData.records = rows.Count();
gData.total = rows.Count();
gData.rows = rows.ToArray();
return Json(gData, JsonRequestBehavior.AllowGet);
}
return null;
}
return null;
}
示例5: mergeDocuments
protected static string mergeDocuments(string sourcepath, string destinationPath, int leadID, int claimID)
{
List<LeadsDocument> documents = null;
List<ClaimDocument> claimDocuments = null;
List<string> pdfs = new List<string>();
string mergedReportPath = null;
documents = LeadsUploadManager.getLeadsDocumentForExportByLeadID(leadID);
claimDocuments = ClaimDocumentManager.GetAll(claimID);
// add original document to list
pdfs.Insert(0, sourcepath);
// lead documents
if (documents != null && documents.Count > 0) {
List<string> leadPDFs = (from x in documents
where x.DocumentName.Contains(".pdf")
select string.Format("{0}/LeadsDocument/{1}/{2}/{3}", appPath, x.LeadId, x.LeadDocumentId, x.DocumentName)
).ToList();
foreach(string pdf in leadPDFs) {
pdfs.Add(pdf);
}
}
// claim documents
if (claimDocuments != null && claimDocuments.Count > 0) {
List<string> claimPDFs = (from x in claimDocuments
where x.DocumentName.Contains(".pdf")
select string.Format("{0}/ClaimDocuments/{1}/{2}/{3}", appPath, x.ClaimID, x.ClaimDocumentID, x.DocumentName)
).ToList();
foreach (string pdf in claimPDFs) {
pdfs.Add(pdf);
}
}
// mergedReportPath = Path.GetDirectoryName(sourcepath) + "\\" + Guid.NewGuid().ToString() + ".pdf";
// mergePDFFiles(mergedReportPath, pdfs.ToArray());
mergePDFFiles(destinationPath, pdfs.ToArray());
return destinationPath;
}
示例6: setPublicKeyEncryption
private void setPublicKeyEncryption(List<int> permissionsList)
{
if (DocumentSecurity.EncryptionPreferences.EncryptionType != EncryptionType.PublicKeyEncryption) return;
if (permissionsList.Count == 0) permissionsList.Add(PdfWriter.AllowScreenReaders);
var certs = PfxReader.ReadCertificate(DocumentSecurity.EncryptionPreferences.PublicKeyEncryption.PfxPath, DocumentSecurity.EncryptionPreferences.PublicKeyEncryption.PfxPassword);
PdfWriter.SetEncryption(
certs: certs.X509PrivateKeys,
permissions: permissionsList.ToArray(),
encryptionType: PdfWriter.ENCRYPTION_AES_128);
}
示例7: AnchoDeColumnas
float[] AnchoDeColumnas()
{
var anchos = new List<float> ();
foreach (var columna in Columnas) {
anchos.Add (columna.Ancho);
}
return anchos.ToArray ();
}
示例8: CreatePDF
/// <summary>
/// Create the PDF using the defined page size, label type and content provided
/// Ensure you have added something first using either AddImage() or AddText()
/// </summary>
/// <returns></returns>
public Stream CreatePDF()
{
//Get the itext page size
Rectangle pageSize;
switch (_label.PageSize)
{
case Enums.PageSize.A4:
pageSize = iTextSharp.text.PageSize.A4;
break;
default:
pageSize = iTextSharp.text.PageSize.A4;
break;
}
//Create a new iText document object, define the paper size and the margins required
var doc = new Document(pageSize,
_label.PageMarginLeft,
_label.PageMarginRight,
_label.PageMarginTop,
_label.PageMarginBottom);
//Create a stream to write the PDF to
var output = new MemoryStream();
//Creates the document tells the PdfWriter to use the output stream when Document.Close() is called
var writer = PdfWriter.GetInstance(doc, output);
//Ensure stream isn't closed when done - we need to return it
writer.CloseStream = false;
//Open the document to begin adding elements
doc.Open();
//Create a new table with label and gap columns
var numOfCols = _label.LabelsPerRow + (_label.LabelsPerRow - 1);
var tbl = new PdfPTable(numOfCols);
//Build the column width array, even numbered index columns will be gap columns
var colWidths = new List<float>();
for (int i = 1; i <= numOfCols; i++)
{
if (i % 2 > 0)
{
colWidths.Add(_label.Width);
}
else
{
//Even numbered columns are gap columns
colWidths.Add(_label.HorizontalGapWidth);
}
}
/* The next 3 lines are the key to making SetWidthPercentage work */
/* "size" specifies the size of the page that equates to 100% - even though the values passed are absolute not relative?! */
/* (I will never get those 3 hours back) */
var w = iTextSharp.text.PageSize.A4.Width - (doc.LeftMargin + doc.RightMargin);
var h = iTextSharp.text.PageSize.A4.Height - (doc.TopMargin + doc.BottomMargin);
var size = new iTextSharp.text.Rectangle(w, h);
//Set the column widths (in points) - take note of the size parameter mentioned above
tbl.SetWidthPercentage(colWidths.ToArray(), size);
//Create the rows for the table
for (int iRow = 0; iRow < _label.LabelRowsPerPage; iRow++)
{
var rowCells = new List<PdfPCell>();
//Build the row - even numbered index columns are gaps
for (int iCol = 1; iCol <= numOfCols; iCol++)
{
if (iCol % 2 > 0)
{
// Create a new Phrase and add the image to it
var cellContent = new Phrase();
foreach (var img in _images)
{
var pdfImg = iTextSharp.text.Image.GetInstance(img);
cellContent.Add(new Chunk(pdfImg, 0, 0));
}
foreach (var txt in _textChunks)
{
var font = FontFactory.GetFont(txt.FontName, BaseFont.CP1250, txt.EmbedFont, txt.FontSize, txt.FontStyle);
cellContent.Add(new Chunk("\n" + txt.Text, font));
}
//Create a new cell specifying the content
var cell = new PdfPCell(cellContent);
//Ensure our label height is adhered to
cell.FixedHeight = _label.Height;
//.........这里部分代码省略.........
示例9: GeneratePdf
public MemoryStream GeneratePdf(MemoryStream stream, List<BarcodeGroup> barcodes, int barcodeCount)
{
Document document = new Document(PageSize.A4, MmToPoint(7.2), MmToPoint(7.2), MmToPoint(15.1),
MmToPoint(15.1));
PdfWriter msWriter = PdfWriter.GetInstance(document, stream);
document.Open();
int numOfCols = 5;
PdfPTable tbl = new PdfPTable(numOfCols);
List<float> colWidths = new List<float>();
for (var i = 1; i <= numOfCols; i++)
{
colWidths.Add(i % 2 > 0 ? MmToPoint(63.5) : MmToPoint(2.5));
}
float w = PageSize.A4.Width - (MmToPoint(7.2) + MmToPoint(7.2));
float h = PageSize.A4.Height - (MmToPoint(15.1) + MmToPoint(15.1));
Rectangle size = new Rectangle(w, h);
tbl.SetWidthPercentage(colWidths.ToArray(), size);
int index = 0;
double div = Convert.ToDouble(barcodeCount) / 21.0;
double dbl = Math.Ceiling(div);
for (var i = 0; i < dbl; i++)
{
document.NewPage();
tbl = new PdfPTable(numOfCols);
tbl.SetWidthPercentage(colWidths.ToArray(), size);
for (var iRow = 0; iRow < 7; iRow++)
{
List<PdfPCell> rowCells = new List<PdfPCell>();
for (var iCol = 1; iCol <= numOfCols; iCol++)
{
if (iCol % 2 > 0)
{
if (index < barcodes.Count)
{
Phrase cellContent = new Phrase();
var img = barcodes[index].image;
Image pic = Image.GetInstance(img, ImageFormat.Bmp);
pic.ScaleAbsolute(MmToPoint(60), MmToPoint(24));
Image pdfImg = Image.GetInstance(pic);
cellContent.Add(new Chunk(pdfImg, 0, -70f));
cellContent.Add(new Chunk("\n"));
cellContent.Add(new Chunk("\n"));
cellContent.Add(new Chunk("\n"));
cellContent.Add(new Chunk("\n"));
cellContent.Add(new Chunk("\n"));
cellContent.Add(new Chunk("\n"));
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
Font f = new Font(bf, 5.0f, Font.NORMAL, BaseColor.BLACK);
cellContent.Add(
new Chunk(
"\n" + barcodes[index].serial.ToString().PadLeft(6, '0') +
" " +
barcodes[index].from + " " + barcodes[index].to, f));
PdfPCell cell = new PdfPCell(cellContent)
{
FixedHeight = MmToPoint(38.1),
HorizontalAlignment = Element.ALIGN_CENTER,
Border = false ? Rectangle.BOX : Rectangle.NO_BORDER
};
rowCells.Add(cell);
index++;
}
else
{
Phrase cellContent = new Phrase();
PdfPCell cell = new PdfPCell(cellContent)
{
FixedHeight = MmToPoint(38.1),
HorizontalAlignment = Element.ALIGN_CENTER,
Border = false ? Rectangle.BOX : Rectangle.NO_BORDER
};
rowCells.Add(cell);
index++;
}
}
else
{
PdfPCell gapCell = new PdfPCell
{
FixedHeight = MmToPoint(38.1),
Border = Rectangle.NO_BORDER
};
rowCells.Add(gapCell);
}
}
tbl.Rows.Add(new PdfPRow(rowCells.ToArray()));
}
document.Add(tbl);
}
document.Close();
return stream;
}
示例10: ReadCountryInfo
private static CountryInfo[] ReadCountryInfo()
{
List<CountryInfo> countryInfoList = new List<CountryInfo>();
string country = String.Empty;
try
{
CsvReader reader = new CsvReader();
CsvLines lines = reader.Load(HttpContext.Current.Server.MapPath("~/country.info"));
foreach (CsvLine line in lines)
{
country = line.Fields[0];
CountryInfo ci = new CountryInfo(
line.Fields[0],
line.Fields[1],
line.Fields[2],
Convert.ToInt32(line.Fields[3]),
line.Fields[4],
line.Fields[5],
line.Fields[6],
line.Fields[7]);
countryInfoList.Add(ci);
}
}
catch (Exception ex)
{
string err = country + " " + ex.Message;
}
return countryInfoList.ToArray();
}
示例11: CreateInvoice
internal static string CreateInvoice(long userId, string status, string transid, string paymentmethod, ProductInfo productInfo, ProductPriceInfo ppi)
{
string companyName = string.Empty;
string userPath = String.Empty;
string password = HttpContext.Current.Session["access"] as string;
UserInfo userInfo = null;
ClientInfo clientInfo = null;
using (Database db = new MySqlDatabase())
{
userPath = db.GetUserDocumentPath(userId, password);
userPath = userPath.Replace("\\", "/");
if (!Directory.Exists(userPath))
Directory.CreateDirectory(userPath);
userInfo = db.GetUser(userId, password);
clientInfo = db.GetClientInfo(userId);
companyName = clientInfo.CompanyName;
}
// complete userPath with document name
string filename = String.Format("INV{0}.pdf", transid);
userPath = Path.Combine(userPath, filename);
// Get the invoice template from the proper location
string templatePath = Resource.InvoiceTemplate;
string invoiceTemplate = HttpContext.Current.Server.MapPath(templatePath);
try
{
InvoiceForm form = new InvoiceForm(invoiceTemplate);
string culture = "nl-NL";
if (HttpContext.Current.Session["culture"] != null)
culture = HttpContext.Current.Session["culture"] as string;
CultureInfo cultureInfo = new CultureInfo(culture);
List<string> fields = new List<string>();
fields.Add(clientInfo.GetFullName());
fields.Add(clientInfo.AddressLine1);
if (!string.IsNullOrEmpty(clientInfo.AddressLine2))
fields.Add(clientInfo.AddressLine2);
string tmpResidence = clientInfo.ZipCode + " " + clientInfo.City.ToUpper();
if (!string.IsNullOrEmpty(tmpResidence))
fields.Add(tmpResidence);
if (!string.IsNullOrEmpty(clientInfo.Country))
fields.Add(clientInfo.Country);
while (fields.Count < 5)
fields.Add(" ");
form.ClientAddress = fields.ToArray();
form.InvoiceDate = DateTime.Now.ToString("d", cultureInfo);
form.InvoiceNumber = transid;
using (Database db = new MySqlDatabase())
{
Transaction transaction = db.GetTransaction(Util.UserId, transid);
foreach (TransactionLine tl in transaction.TransactionLines)
{
form.InvoiceLines.Add(new PdfInvoiceLine()
{
Description = tl.Description,
Quantity = tl.Quantity,
UnitPrice = tl.Price,
VatRate = tl.VatPercentage
});
}
}
form.GenerateInvoice(userPath, companyName);
}
catch (Exception ex)
{
Logger.Instance.Write(LogLevel.Error, ex, "[CreateInvoice]");
}
SendInvoice(userId, userPath);
return userPath;
}
示例12: SendInvoice
private static void SendInvoice(long userId, string userPath)
{
UserInfo ui = null;
ClientInfo ci = null;
using (Database db = new MySqlDatabase())
{
ui = db.GetUser(userId);
ci = db.GetClientInfo(userId);
}
string email = ui.Email;
if (!String.IsNullOrEmpty(ci.EmailReceipt))
email = ci.EmailReceipt;
List<string> attachments = new List<string>();
attachments.Add(userPath);
using (TextReader rdr = new StreamReader(HttpContext.Current.Server.MapPath(Resources.Resource.tplInvoice)))
{
string body = rdr.ReadToEnd();
body = body.Replace("{%EmailHeaderLogo%}", ConfigurationManager.AppSettings["EmailHeaderLogo"]);
body = body.Replace("{%EmailmailToLink%}", ConfigurationManager.AppSettings["EmailmailToLink"]);
body = body.Replace("{%SiteNavigationLink%}", ConfigurationManager.AppSettings["SiteNavigationLink"]);
body = body.Replace("{%EmailFooterLogo%}", ConfigurationManager.AppSettings["EmailFooterLogo"]);
body = body.Replace("{%EmailFBlink%}", ConfigurationManager.AppSettings["EmailFBlink"]);
body = body.Replace("{%EmailFBLogo%}", ConfigurationManager.AppSettings["EmailFBLogo"]);
body = body.Replace("{%EmailTwitterLink%}", ConfigurationManager.AppSettings["EmailTwitterLink"]);
body = body.Replace("{%EmailTwitterLogo%}", ConfigurationManager.AppSettings["EmailTwitterLogo"]);
body = body.Replace("{%EmailSoundCloudLink%}", ConfigurationManager.AppSettings["EmailSoundCloudLink"]);
body = body.Replace("{%EmailSoundCloudLogo%}", ConfigurationManager.AppSettings["EmailSoundCloudLogo"]);
body = body.Replace("{%receivingRelation%}", ci.GetFullName());
SendEmail(new string[] { email }, null, Resource.SubjectYourInvoice, body,
attachments.ToArray(), 0);
}
}
示例13: ReadLanguageInfo
private static LanguageInfo[] ReadLanguageInfo()
{
List<LanguageInfo> languageInfoList = new List<LanguageInfo>();
try
{
CsvReader reader = new CsvReader();
CsvLines lines = reader.Load(HttpContext.Current.Server.MapPath("~/language.info"));
foreach (CsvLine line in lines)
{
LanguageInfo li = new LanguageInfo(
line.Fields[0],
line.Fields[1],
line.Fields[2]);
languageInfoList.Add(li);
}
}
catch (Exception)
{
}
return languageInfoList.ToArray();
}
示例14: CreatePDF
/// <summary>
/// Create the PDF using the defined page size, label type and content provided
/// Ensure you have added something first using either AddImage() or AddText()
/// </summary>
/// <returns></returns>
public Stream CreatePDF()
{
//Get the itext page size
Rectangle pageSize;
switch (_labelDefinition.PageSize)
{
case Enums.PageSize.A4:
pageSize = iTextSharp.text.PageSize.A4;
break;
default:
pageSize = iTextSharp.text.PageSize.A4;
break;
}
//Create a new iText document object, define the paper size and the margins required
var doc = new Document(pageSize,
_labelDefinition.PageMarginLeft,
_labelDefinition.PageMarginRight,
_labelDefinition.PageMarginTop,
_labelDefinition.PageMarginBottom);
//Create a stream to write the PDF to
var output = new MemoryStream();
//Creates the document tells the PdfWriter to use the output stream when Document.Close() is called
var writer = PdfWriter.GetInstance(doc, output);
//Ensure stream isn't closed when done - we need to return it
writer.CloseStream = false;
//Open the document to begin adding elements
doc.Open();
//Create a new table with label and gap columns
var numOfCols = _labelDefinition.LabelsPerRow + (_labelDefinition.LabelsPerRow - 1);
// var tbl = new PdfPTable(numOfCols);
//Build the column width array, even numbered index columns will be gap columns
var colWidths = new List<float>();
for (int i = 1; i <= numOfCols; i++)
{
if (i % 2 > 0)
{
colWidths.Add(_labelDefinition.Width);
}
else
{
//Even numbered columns are gap columns
colWidths.Add(_labelDefinition.HorizontalGapWidth);
}
}
/* The next 3 lines are the key to making SetWidthPercentage work */
/* "size" specifies the size of the page that equates to 100% - even though the values passed are absolute not relative?! */
/* (I will never get those 3 hours back) */
var w = iTextSharp.text.PageSize.A4.Width - (doc.LeftMargin + doc.RightMargin);
var h = iTextSharp.text.PageSize.A4.Height - (doc.TopMargin + doc.BottomMargin);
var size = new iTextSharp.text.Rectangle(w, h);
// loop over the labels
var rowNumber = 0;
var colNumber = 0;
PdfPTable tbl = null;
foreach (var label in _labels)
{
if (rowNumber == 0)
{
tbl = new PdfPTable(numOfCols);
tbl.SetWidthPercentage(colWidths.ToArray(), size);
rowNumber = 1; // so we start with row 1
doc.NewPage();
}
colNumber++; // so we start with col 1
// add the label cell.
var cell = FormatCell(label.GetLabelCell());
//Add to the row
tbl.AddCell(cell);
//Create a empty cell to use as a gap
if (colNumber < numOfCols)
{
tbl.AddCell(CreateGapCell());
colNumber++; // increment for the gap row
}
//On all but the last row, after the last column, add a gap row if needed
if (colNumber == numOfCols && ((rowNumber) < _labelDefinition.LabelRowsPerPage && _labelDefinition.VerticalGapHeight > 0))
{
tbl.Rows.Add(CreateGapRow(numOfCols));
}
//.........这里部分代码省略.........
示例15: CreateGapRow
private PdfPRow CreateGapRow(int numOfCols)
{
var cells = new List<PdfPCell>();
for (int i = 0; i < numOfCols; i++)
{
cells.Add(CreateGapCell());
}
return new PdfPRow(cells.ToArray());
}