本文整理汇总了C#中iTextSharp.text.Document.NewPage方法的典型用法代码示例。如果您正苦于以下问题:C# Document.NewPage方法的具体用法?C# Document.NewPage怎么用?C# Document.NewPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.NewPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePdf
public override byte[] CreatePdf(List<PdfContentParameter> contents, string[] images, int type)
{
var document = new Document();
float docHeight = document.PageSize.Height - heightOffset;
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
document.SetMargins(50, 50, 10, 40);
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
writer.PageEvent = new HeaderFooterHandler(type);
document.Open();
document.Add(contents[0].Table);
for (int i = 0; i < images.Length; i++)
{
document.NewPage();
float subtrahend = document.PageSize.Height - heightOffset;
iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]);
pool.Alignment = 3;
pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
//pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
document.Add(pool);
}
document.Close();
return output.ToArray();
}
示例2: WriteTOC
protected virtual void WriteTOC(List<PdfContentParameter> contents, PdfWriter writer, Document document)
{
document.NewPage();
PdfPTable t = new PdfPTable(2);
t.WidthPercentage = 100;
t.SetWidths(new float[] { 98f, 2f });
t.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);
t.AddCell(new PdfPCell(
new Phrase(GlobalStringResource.TableOfContents,
FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16))
) { Colspan = 2, Border = Rectangle.NO_BORDER, PaddingBottom = 25 });
foreach (PdfContentParameter item in contents)
{
if (!string.IsNullOrEmpty(item.Header))
{
t.AddCell(
new PdfPCell(
new Phrase(item.Header,
FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
)
) { Border = Rectangle.NO_BORDER, NoWrap = false, FixedHeight = 15, }
);
PdfPCell templateCell = new PdfPCell(Image.GetInstance(item.Template));
templateCell.HorizontalAlignment = Element.ALIGN_RIGHT;
templateCell.Border = Rectangle.NO_BORDER;
t.AddCell(templateCell);
}
}
float docHeight = document.PageSize.Height - heightOffset;
document.Add(t);
}
示例3: CreatePdf
private void CreatePdf(FileStream outputStream)
{
var doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, outputStream);
doc.Open();
WriteFrontPage(doc);
doc.NewPage();
WriteSpecification(doc);
foreach (var representation in _report.Representations)
{
doc.NewPage();
doc.Add(new Paragraph("Representation"));
}
PdfPTable table = new PdfPTable(2);
table.AddCell(new PdfPCell { Colspan = 1 });
PdfPCell cell = new PdfPCell { Colspan = 1, HorizontalAlignment = 1, Phrase = new Phrase("REPRESENTATIONSKOSTNADER") };
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
doc.Add(table);
doc.Close();
}
示例4: MergePdfs
public static byte[] MergePdfs(IEnumerable<byte[]> inputFiles)
{
MemoryStream outputStream = new MemoryStream();
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, outputStream);
document.Open();
PdfContentByte content = writer.DirectContent;
foreach (byte[] input in inputFiles)
{
PdfReader reader = new PdfReader(input);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, i);
int rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
content.AddTemplate(page, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
else
{
content.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
document.Close();
return outputStream.ToArray();
}
示例5: CreateCards
/// <summary>
/// Creates a MemoryStream but does not dispose it.
/// </summary>
/// <param name="members"></param>
/// <param name="expiration"></param>
/// <returns></returns>
public static MemoryStream CreateCards(IEnumerable<Member> members, DateTime expiration)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(CARD_WIDTH, CARD_HEIGHT));
MemoryStream memStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memStream);
writer.CloseStream = false;
doc.Open();
foreach (var member in members)
{
foreach (var passport in new[] { false, true})
{
Render_FrontBase(writer.DirectContentUnder, expiration);
Render_FrontContent(writer.DirectContent, member);
doc.NewPage();
Render_BackBase(writer.DirectContentUnder);
Render_BackContent(writer.DirectContent, member, passport);
doc.NewPage();
}
}
doc.Close();
byte[] buf = new byte[memStream.Position];
memStream.Position = 0;
return memStream;
}
示例6: CreatePdf
// ---------------------------------------------------------------------------
/**
* Creates a PDF document for PdfReader.
*/
public byte[] CreatePdf()
{
using (MemoryStream ms = new MemoryStream())
{
// step 1
using (Document document = new Document(PageSize.POSTCARD, 30, 30, 30, 30))
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfContentByte under = writer.DirectContentUnder;
// page 1: rectangle
under.SetRGBColorFill(0xFF, 0xD7, 0x00);
under.Rectangle(5, 5,
PageSize.POSTCARD.Width - 10, PageSize.POSTCARD.Height - 10);
under.Fill();
document.NewPage();
// page 2: image
Image img = Image.GetInstance(Path.Combine(
Utility.ResourceImage, "loa.jpg"
));
img.SetAbsolutePosition(
(PageSize.POSTCARD.Width - img.ScaledWidth) / 2,
(PageSize.POSTCARD.Height - img.ScaledHeight) / 2
);
document.Add(img);
document.NewPage();
// page 3: the words "Foobar Film Festival"
Paragraph p = new Paragraph(
"Foobar Film Festival", new Font(Font.FontFamily.HELVETICA, 22)
);
p.Alignment = Element.ALIGN_CENTER;
document.Add(p);
document.NewPage();
// page 4: the words "SOLD OUT"
PdfContentByte over = writer.DirectContent;
over.SaveState();
float sinus = (float)Math.Sin(Math.PI / 60);
float cosinus = (float)Math.Cos(Math.PI / 60);
BaseFont bf = BaseFont.CreateFont();
over.BeginText();
over.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
over.SetLineWidth(1.5f);
over.SetRGBColorStroke(0xFF, 0x00, 0x00);
over.SetRGBColorFill(0xFF, 0xFF, 0xFF);
over.SetFontAndSize(bf, 36);
over.SetTextMatrix(cosinus, sinus, -sinus, cosinus, 50, 324);
over.ShowText("SOLD OUT");
over.SetTextMatrix(0, 0);
over.EndText();
over.RestoreState();
}
return ms.ToArray();
}
}
示例7: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document(PageSize.A4.Rotate()))
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
ColumnText column = new ColumnText(writer.DirectContent);
List<string> days = PojoFactory.GetDays();
// COlumn definition
float[][] x = {
new float[] { document.Left, document.Left + 380 },
new float[] { document.Right - 380, document.Right }
};
// Loop over the festival days
foreach (string day in days)
{
// add content to the column
column.AddElement(GetTable(day));
int count = 0;
float height = 0;
// iText-ONLY, 'Initial value of the status' => 0
// iTextSharp **DOES NOT** include this member variable
// int status = ColumnText.START_COLUMN;
int status = 0;
// render the column as long as it has content
while (ColumnText.HasMoreText(status))
{
// add the top-level header to each new page
if (count == 0)
{
height = AddHeaderTable(document, day, writer.PageNumber);
}
// set the dimensions of the current column
column.SetSimpleColumn(
x[count][0], document.Bottom,
x[count][1], document.Top - height - 10
);
// render as much content as possible
status = column.Go();
// go to a new page if you've reached the last column
if (++count > 1)
{
count = 0;
document.NewPage();
}
}
document.NewPage();
}
}
}
示例8: Test
public void Test() {
String file = "tagged_pdf_page_events.pdf";
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
pdfWriter.SetTagged();
pdfWriter.PageEvent = new TaggedPdfPageEventsTest();
document.Open();
document.Add(new Paragraph("Hello"));
document.NewPage();
document.Add(new Paragraph("World"));
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例9: Merge
public static String Merge(String[] pdfs)
{
String tempFilePath = GetTemporaryFile();
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(tempFilePath, FileMode.Create));
document.Open();
PdfContentByte content = writer.DirectContent;
document.NewPage();
foreach (String file in pdfs)
{
PdfReader reader = new PdfReader(file);
int numberOfPages = reader.NumberOfPages;
for (int i = 1; i <= numberOfPages; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
// page, horizontal scaling, x, rotation, vertical scaling, horizontal offset, vertical offset
content.AddTemplate(page, 1, 0, 0, 1, 0.0f, 200.0f);
//content.AddTemplate(page);
}
}
document.Close();
return tempFilePath;
}
示例10: GraphConvertPdf
public bool GraphConvertPdf(string savename,string savepath,string basepath,string basetype)
{
bool flag = true;
Document doc = new Document();
savename = PdfClass.PdfFileNameConverter(savename);
try
{
PdfWriter.GetInstance(doc, new FileStream(@savepath + "\\" + savename + ".pdf", FileMode.Create));
doc.Open();
int max = Directory.GetFiles(@basepath).Count();
for (int i = 0; i < max; i++)
{
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(@basepath + "\\" + i.ToString() + "." + basetype));
iTextSharp.text.Rectangle pagesize = new iTextSharp.text.Rectangle(image.Width / image.DpiX * 25.4f * 2.834f, image.Height / image.DpiY * 25.4f * 2.834f);
doc.SetPageSize(pagesize);
image.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
image.SetAbsolutePosition(0f, 0f);
doc.NewPage();
doc.Add(image);
}
doc.Close();
}
catch
{
flag = false;
}
return flag;
}
示例11: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
// Create a table and fill it with movies
IEnumerable<Movie> movies = PojoFactory.GetMovies(3);
PdfPTable table = new PdfPTable(new float[] { 1, 5, 5, 1 });
foreach (Movie movie in movies)
{
table.AddCell(movie.Year.ToString());
table.AddCell(movie.MovieTitle);
table.AddCell(movie.OriginalTitle);
table.AddCell(movie.Duration.ToString());
}
// set the total width of the table
table.TotalWidth = 600;
PdfContentByte canvas = writer.DirectContent;
// draw the first three columns on one page
table.WriteSelectedRows(0, 2, 0, -1, 236, 806, canvas);
document.NewPage();
// draw the next three columns on the next page
table.WriteSelectedRows(2, -1, 0, -1, 36, 806, canvas);
}
}
示例12: ASPXToPDF
public void ASPXToPDF(HtmlTable objhtml1, HtmlTable objhtml2)
{
string fileName = "AsignacionFolios.pdf";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
StringWriter sw1 = new StringWriter();
HtmlTextWriter hw1 = new HtmlTextWriter(sw1);
objhtml1.RenderControl(hw1);
StringWriter sw2 = new StringWriter();
HtmlTextWriter hw2 = new HtmlTextWriter(sw2);
objhtml2.RenderControl(hw2);
StringReader sr1 = new StringReader(sw1.ToString());
StringReader sr2 = new StringReader(sw2.ToString());
Document pdfDoc = new Document(PageSize.A2, 5f, 5f, 5f, 5f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr1);
pdfDoc.NewPage();
htmlparser.Parse(sr2);
pdfDoc.Close();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.Response.End();
}
示例13: GeneratePdfSingleDataType
public static void GeneratePdfSingleDataType(string filePath, string title, string content)
{
try
{
Logger.LogI("GeneratePDF -> " + filePath);
var doc = new Document(PageSize.A3, 36, 72, 72, 144);
using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.AddTitle(title);
doc.AddAuthor(Environment.MachineName);
doc.Add(
new Paragraph("Title : " + title + Environment.NewLine + "ServerName : " +
Environment.MachineName +
Environment.NewLine + "Author : " + Environment.UserName));
doc.NewPage();
doc.Add(new Paragraph(content));
doc.Close();
}
}
catch (Exception ex)
{
Logger.LogE(ex.Source + " -> " + ex.Message + "\n" + ex.StackTrace);
}
}
示例14: ExportToPdfAsBase64String
public string ExportToPdfAsBase64String(IEnumerable<System.Drawing.Image> imageFiles)
{
var result = "";
using (var pdfDoc = new Document(PdfPageSize))
{
using (var stream = new MemoryStream())
{
var pdfWriter = PdfWriter.GetInstance(pdfDoc, stream);
pdfWriter.SetPdfVersion(new PdfName("1.5"));
pdfWriter.CompressionLevel = PdfStream.BEST_COMPRESSION;
pdfDoc.Open();
foreach (var img in imageFiles.Select(bmpImage => Image.GetInstance(bmpImage, ImageFormat.Bmp)))
{
if (FitImagesToPage)
{
img.ScaleAbsolute(pdfDoc.PageSize.Width, pdfDoc.PageSize.Height);
}
img.SetAbsolutePosition(0, 0);
pdfDoc.Add(img);
pdfDoc.NewPage();
}
result = Convert.ToBase64String(stream.ToArray());
}
}
return result;
}
示例15: VerticalPositionTest0
public void VerticalPositionTest0() {
String file = "vertical_position.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
writer.PageEvent = new CustomPageEvent();
PdfPTable table = new PdfPTable(2);
for (int i = 0; i < 100; i++) {
table.AddCell("Hello " + i);
table.AddCell("World " + i);
}
document.Add(table);
document.NewPage();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++) {
sb.Append("some more text ");
}
document.Add(new Paragraph(sb.ToString()));
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}