本文整理汇总了C#中iTextSharp.NewPage方法的典型用法代码示例。如果您正苦于以下问题:C# iTextSharp.NewPage方法的具体用法?C# iTextSharp.NewPage怎么用?C# iTextSharp.NewPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp
的用法示例。
在下文中一共展示了iTextSharp.NewPage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addImage
private bool addImage(string sFilename, iTextSharp.text.Document doc)
{
bool bReturn = false;
iTextSharp.text.Image img;
try
{
Paragraph p1 = new Paragraph(new Chunk(sFilename, FontFactory.GetFont(FontFactory.HELVETICA, 12)));
doc.Add(p1);
#if !TEST
Bitmap myBitmap = new Bitmap(sFilename);
if (sFilename.ToLower().EndsWith("jpg"))
img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Jpeg);
else if (sFilename.ToLower().EndsWith("gif"))
img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Gif);
else if (sFilename.ToLower().EndsWith("bmp"))
img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Bmp);
else if (sFilename.ToLower().EndsWith("png"))
img = iTextSharp.text.Image.GetInstance(myBitmap, System.Drawing.Imaging.ImageFormat.Png);
else
throw new NotSupportedException("Unsupported image format");
//is the image to wide or to high?
float fWidth=doc.Right - doc.Left - doc.RightMargin - doc.LeftMargin;
float fHeight=doc.Top - doc.Bottom - doc.TopMargin - doc.BottomMargin;
if ((myBitmap.Width > fWidth) || (myBitmap.Height>fHeight))
img.ScaleToFit(fWidth, fHeight);
#else
img = iTextSharp.text.Image.GetInstance(sFilename);
#endif
doc.Add(img);
doc.NewPage(); //used to create a new page for every image
bReturn = true;
}
catch (iTextSharp.text.BadElementException bx)
{
System.Diagnostics.Debug.WriteLine("BadElementException in doc.add() for '" + sFilename + "': " + bx.Message);
}
catch (iTextSharp.text.DocumentException dx)
{
System.Diagnostics.Debug.WriteLine("DocumentException in doc.add() for '" + sFilename + "': " + dx.Message);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception in doc.add() for '" + sFilename + "': " + ex.Message);
}
return bReturn;
}
示例2: AddAllContractDetails
private static void AddAllContractDetails(SqlDataReader dr, iTextSharp.text.Document document,
string shid, int cropYear, FieldSummaryReportEvent pgEvent)
{
try {
string tmp = "";
int harvestAcres = 0;
float[] layout = new float[] { 50F, 68F, 35F, 61F, 47F, 37.0F, 32.0F, 41F, 35F, 50F, 38F, 46F };
PdfPTable table = null;
decimal grossDollars = 0;
while (dr.Read()) {
if (table == null) {
document.NewPage();
table = PdfReports.CreateTable(layout, 0);
PdfReports.AddText2Table(table, " ", normalFont, "left", layout.Length);
// Header
// Row 1
PdfReports.AddText2Table(table, " ", labelFont, "left");
PdfReports.AddText2Table(table, " ", labelFont, "left");
PdfReports.AddText2Table(table, "Acres", labelFont, "center");
PdfReports.AddText2Table(table, " ", labelFont, "right");
PdfReports.AddText2Table(table, " ", labelFont, "right");
PdfReports.AddText2Table(table, " ", labelFont, "right");
PdfReports.AddText2Table(table, " ", labelFont, "right");
PdfReports.AddText2Table(table, " ", labelFont, "center");
PdfReports.AddText2Table(table, " ", labelFont, "center");
PdfReports.AddText2Table(table, @"Ext. Sugar", labelFont, "right");
PdfReports.AddText2Table(table, " ", labelFont, "center");
PdfReports.AddText2Table(table, " ", labelFont, "center");
// Row 2
PdfReports.AddText2Table(table, "Contract #", labelFont, "left");
PdfReports.AddText2Table(table, "Field Name", labelFont, "left");
PdfReports.AddText2Table(table, "Harvest", labelFont, "center");
PdfReports.AddText2Table(table, "Net Tons", labelFont, "right");
PdfReports.AddText2Table(table, "TPA", labelFont, "right");
PdfReports.AddText2Table(table, "BPA", labelFont, "right");
PdfReports.AddText2Table(table, "Top", labelFont, "right");
PdfReports.AddText2Table(table, "% Sugar", labelFont, "right");
PdfReports.AddText2Table(table, "SLM", labelFont, "right");
PdfReports.AddText2Table(table, "Lbs/Acre", labelFont, "right");
PdfReports.AddText2Table(table, "% Tare", labelFont, "right");
PdfReports.AddText2Table(table, @"$/Acre", labelFont, "right");
}
tmp = dr.GetInt32(dr.GetOrdinal("ContractNo")).ToString();
PdfReports.AddText2Table(table, tmp, normalFont, "left");
tmp = dr.GetString(dr.GetOrdinal("FieldName"));
PdfReports.AddText2Table(table, tmp, normalFont, "left");
harvestAcres = dr.GetInt32(dr.GetOrdinal("AcresHarvested"));
PdfReports.AddText2Table(table, harvestAcres.ToString(), normalFont, "center");
tmp = dr.GetDecimal(dr.GetOrdinal("TonsHarvested")).ToString("#,###.0000");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("TonsPerAcre")).ToString("#,###.0000");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetInt32(dr.GetOrdinal("BeetsPerAcre")).ToString("#,##0");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("AvgTopping")).ToString("0.00");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("SugarPct")).ToString("#,###.00");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("SLMPct")).ToString("#,###.00");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
// convert to lbs\acre extractable
int extSugar = 0;
if (harvestAcres > 0) {
extSugar = Convert.ToInt32(Math.Round(dr.GetDecimal(dr.GetOrdinal("ExtractableSugar")) / harvestAcres, 0));
}
PdfReports.AddText2Table(table, extSugar.ToString("#,###"), normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("TarePct")).ToString("#,###.00");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
tmp = dr.GetDecimal(dr.GetOrdinal("GrossDollarsPerAcre")).ToString("#,###.00");
PdfReports.AddText2Table(table, tmp, normalFont, "right");
grossDollars += dr.GetDecimal(dr.GetOrdinal("GrossDollars"));
}
if (table != null) {
//.........这里部分代码省略.........
示例3: AddPageWithInternalLinks
/// <summary>
/// Add a blank page to the document.
/// </summary>
/// <param name="doc"></param>
private void AddPageWithInternalLinks(iTextSharp.text.Document doc)
{
// Generate links to be embedded in the page
Anchor researchAnchor = new Anchor("Research & Hypothesis\n\n", _standardFont);
researchAnchor.Reference = "#research"; // this link references a named anchor within the document
Anchor graphAnchor = new Anchor("Graph\n\n", _standardFont);
graphAnchor.Reference = "#graph";
Anchor resultsAnchor = new Anchor("Results & Bibliography", _standardFont);
resultsAnchor.Reference = "#results";
// Add a new page to the document
doc.NewPage();
// Add heading text to the page
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, new iTextSharp.text.Chunk("TABLE OF CONTENTS\n\n\n\n\n"));
// Add the links to the page
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _standardFont, researchAnchor);
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _standardFont, graphAnchor);
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _standardFont, resultsAnchor);
}
示例4: AddPageWithImage
/// <summary>
/// Add a page containing a single image. Set the page size to match the image size.
/// </summary>
/// <param name="doc"></param>
/// <param name="imagePath"></param>
private void AddPageWithImage(iTextSharp.text.Document doc, String imagePath)
{
// Read the image file
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(imagePath));
// Set the page size to the dimensions of the image BEFORE adding a new page to the document.
// Pad the height a bit to leave room for the page header.
float imageWidth = image.Width;
float imageHeight = image.Height;
doc.SetMargins(0, 0, 0, 0);
doc.SetPageSize(new iTextSharp.text.Rectangle(imageWidth, imageHeight + 100));
// Add a new page
doc.NewPage();
// The header at the top of the page is an anchor linked to by the table of contents.
iTextSharp.text.Anchor contentsAnchor = new iTextSharp.text.Anchor("\nGRAPH\n\n", _largeFont);
contentsAnchor.Name = "graph";
// Add the anchor and image to the page
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, contentsAnchor);
doc.Add(image);
image = null;
}
示例5: AddPageWithBulletList
/// <summary>
/// Add a page that includes a bullet list.
/// </summary>
/// <param name="doc"></param>
private void AddPageWithBulletList(iTextSharp.text.Document doc)
{
// Add a new page to the document
doc.NewPage();
// The header at the top of the page is an anchor linked to by the table of contents.
iTextSharp.text.Anchor contentsAnchor = new iTextSharp.text.Anchor("RESEARCH\n\n", _largeFont);
contentsAnchor.Name = "research";
// Add the header anchor to the page
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, contentsAnchor);
// Create an unordered bullet list. The 10f argument separates the bullet from the text by 10 points
iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
list.SetListSymbol("\u2022"); // Set the bullet symbol (without this a hypen starts each list item)
list.IndentationLeft = 20f; // Indent the list 20 points
list.Add(new ListItem("Lift, thrust, drag, and gravity are the four forces that act on a plane.", _standardFont));
list.Add(new ListItem("A plane should be light to help fight against gravity's pull to the ground.", _standardFont));
list.Add(new ListItem("Gravity will have less effect on a plane built from the lightest materials available.", _standardFont));
list.Add(new ListItem("In order to fly well, airplanes must be stable.", _standardFont));
list.Add(new ListItem("A plane that is unstable will either pitch up into a stall, or nose-dive.", _standardFont));
doc.Add(list); // Add the list to the page
// Add some white space and another heading
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, new Chunk("\n\n\n"));
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, new Chunk("HYPOTHESIS\n\n"));
// Add some final text to the page
this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_LEFT, _standardFont, new Chunk("Given five paper airplanes made out of newspaper, printer paper, construction paper, paper towel, and posterboard, the airplane made out of printer paper will fly the furthest."));
}
示例6: Settings
/// <summary>
/// This method consist settings of pdf file
/// </summary>
/// <param name="ms"></param>
/// <param name="doc"></param>
public void Settings(MemoryStream ms, iTextSharp.text.Document doc)
{
PdfWriter.GetInstance(doc, ms);
iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4);
doc.SetPageSize(rec);
doc.SetMargins(0, 0, 0, 0);
doc.Open();
doc.NewPage();
}