本文整理汇总了C#中iTextSharp.text.Rectangle类的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于iTextSharp.text命名空间,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CellLayout
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
TextField text = new TextField(
writer, rectangle, FieldName ?? AddBase64Image.NAME
);
PdfFormField field = text.GetTextField();
writer.AddAnnotation(field);
}
示例2: GetRelativeColumns
public static float[] GetRelativeColumns(Rectangle format)
{
float[] relativeWidths;
if (format == PageSize.A4)
{
relativeWidths = new float[]
{
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F,
35.09F
};
}
else
{
relativeWidths = new float[] {};
}
return relativeWidths;
}
示例3: PDFCreator
/// <summary>
/// PDF Creator Helper With No Page Base (Don't want to write a page or report (header or footer)
/// </summary>
/// <param name="PageSize">Page Size - A4 is a default page size. Use Enum iTextSharp.text.PageSize</param>
/// <param name="LandscapeMode">Do you want the pdf in landscape</param>
/// <param name="MarginTop">Top Margin On The Page</param>
/// <param name="MarginRight">Right Margin On The Page</param>
/// <param name="MarginBottom">Bottom Margin On The Page</param>
/// <param name="MarginLeft">Left Margin On The Page</param>
/// <param name="PageEventHandler">A Page Event Class That Will Raise Any Events You Need</param>
public PDFCreator(Rectangle PageSize,
bool LandscapeMode,
float MarginTop,
float MarginRight,
float MarginBottom,
float MarginLeft,
PageEventsBase PageEventHandler)
{
//create the instance of the ITextSharpDocument
Doc = new Document(PageSize, MarginLeft, MarginRight, MarginTop, MarginBottom);
//let's build the memory stream now
Ms = new MemoryStream();
//let's create the new writer and attach the document
Writer = PdfWriter.GetInstance(Doc, Ms);
//add the page events to my custom class
if (PageEventHandler != null)
{
Writer.PageEvent = PageEventHandler;
}
//if you want the pdf in landscape now, then rotate it
if (LandscapeMode)
{
Doc.SetPageSize(PageSize.Rotate());
}
//let's open the document so the developer can do whatever they wan't with it
Doc.Open();
}
示例4: GenerateReport
/// <summary>
/// Save a pdf file in "../../test.pdf".
/// </summary>
/// <param name="deals">Expect Collection of objects that have Name, Address, ProductName and formula.</param>
public void GenerateReport(IEnumerable<PdfReportModel> deals)
{
FileStream fileStream = new FileStream(ReportsPath, FileMode.Create, FileAccess.Write, FileShare.None);
Rectangle pageSize = new Rectangle(PageSize.A4);
Document reportDocument = new Document(pageSize);
PdfWriter pdfWriter = PdfWriter.GetInstance(reportDocument, fileStream);
var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 17);
reportDocument.Open();
PdfPTable reportTable = new PdfPTable(6);
reportTable.HorizontalAlignment = Element.ALIGN_LEFT;
PdfPCell headerCell = new PdfPCell(new Phrase("Produced products information", boldFont));
headerCell.Colspan = 6;
headerCell.HorizontalAlignment = 0;
reportTable.AddCell(headerCell);
this.PutHeadCells(reportTable);
foreach (var deal in deals)
{
reportTable.AddCell(deal.ProductName);
reportTable.AddCell(deal.Quantity);
reportTable.AddCell(deal.PricePerUnit);
reportTable.AddCell(deal.Formula);
reportTable.AddCell(deal.Address);
reportTable.AddCell(deal.Total);
}
reportDocument.Add(reportTable);
reportDocument.Close();
}
示例5: CellLayout
/**
* @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(
* com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle,
* com.lowagie.text.pdf.PdfContentByte[])
*/
public void CellLayout(
PdfPCell cell, Rectangle rect, PdfContentByte[] canvas
)
{
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.SaveState();
if (duration < 90)
{
cb.SetRGBColorFill(0x7C, 0xFC, 0x00);
}
else if (duration > 120)
{
cb.SetRGBColorFill(0x8B, 0x00, 0x00);
}
else
{
cb.SetRGBColorFill(0xFF, 0xA5, 0x00);
}
cb.Rectangle(
rect.Left, rect.Bottom,
rect.Width * duration / 240, rect.Height
);
cb.Fill();
cb.RestoreState();
}
示例6: CellLayout
/**
* @see com.itextpdf.text.pdf.PdfPCellEvent#cellLayout(com.itextpdf.text.pdf.PdfPCell,
* com.itextpdf.text.Rectangle, com.itextpdf.text.pdf.PdfContentByte[])
*/
virtual public void CellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases) {
float effectivePadding = styleValues.BorderWidthLeft/2 + styleValues.HorBorderSpacing;
float x1 = position.Left + effectivePadding;
if (styleValues.IsLastInRow){
effectivePadding = styleValues.BorderWidthRight/2 + styleValues.HorBorderSpacing;
} else {
effectivePadding = styleValues.BorderWidthRight/2;
}
float x2 = position.Right - effectivePadding;
effectivePadding = styleValues.BorderWidthTop/2 + styleValues.VerBorderSpacing;
float y1 = position.Top - effectivePadding;
effectivePadding = styleValues.BorderWidthBottom/2;
float y2 = position.Bottom + effectivePadding;
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
BaseColor color = styleValues.Background;
if (color != null) {
cb.SetColorStroke(color);
cb.SetColorFill(color);
cb.Rectangle(x1, y1, x2-x1, y2-y1);
cb.Fill();
}
BaseColor borderColor = styleValues.BorderColorLeft;
float width = styleValues.BorderWidthLeft;
if (borderColor != null && width != 0) {
cb.SetLineWidth(width);
cb.SetColorStroke(borderColor);
cb.MoveTo(x1, y1); // start leftUpperCorner
cb.LineTo(x1, y2); // left
cb.Stroke();
}
borderColor = styleValues.BorderColorBottom;
width = styleValues.BorderWidthBottom;
if (borderColor != null && width != 0) {
cb.SetLineWidth(width);
cb.SetColorStroke(borderColor);
cb.MoveTo(x1, y2); // left
cb.LineTo(x2, y2); // bottom
cb.Stroke();
}
borderColor = styleValues.BorderColorRight;
width = styleValues.BorderWidthRight;
if (borderColor != null && width != 0) {
cb.SetLineWidth(width);
cb.SetColorStroke(borderColor);
cb.MoveTo(x2, y2); // bottom
cb.LineTo(x2, y1); // right
cb.Stroke();
}
borderColor = styleValues.BorderColorTop;
width = styleValues.BorderWidthTop;
if (borderColor != null && width != 0) {
cb.SetLineWidth(width);
cb.SetColorStroke(borderColor);
cb.MoveTo(x2, y1); // right
cb.LineTo(x1, y1); // top
cb.Stroke();
}
cb.ResetRGBColorStroke();
}
示例7: CreatePdf
// ---------------------------------------------------------------------------
/**
* Creates a PDF document.
*/
public byte[] CreatePdf()
{
Rectangle rect = new Rectangle(-595, -842, 595, 842);
using (MemoryStream ms = new MemoryStream()) {
using (Document document = new Document(rect)) {
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfContentByte canvas = writer.DirectContent;
canvas.MoveTo(-595, 0);
canvas.LineTo(595, 0);
canvas.MoveTo(0, -842);
canvas.LineTo(0, 842);
canvas.Stroke();
// read the PDF with the logo
PdfReader reader = new PdfReader(RESOURCE);
PdfTemplate template = writer.GetImportedPage(reader, 1);
// add it at different positions using different transformations
canvas.AddTemplate(template, 0, 0);
canvas.AddTemplate(template, 0.5f, 0, 0, 0.5f, -595, 0);
canvas.AddTemplate(template, 0.5f, 0, 0, 0.5f, -297.5f, 297.5f);
canvas.AddTemplate(template, 1, 0, 0.4f, 1, -750, -650);
canvas.AddTemplate(template, 0, -1, -1, 0, 650, 0);
canvas.AddTemplate(template, 0, -0.2f, -0.5f, 0, 350, 0);
}
return ms.ToArray();
}
}
示例8: CreatePdfRectangle
private Rectangle CreatePdfRectangle()
{
Rectangle rect = new Rectangle(PageSize.A4);
rect.BackgroundColor = new BaseColor(System.Drawing.Color.LightGray);
return rect;
}
示例9: Write
// ===========================================================================
public void Write(Stream stream)
{
string RESOURCE = Utility.ResourcePosters;
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
Rectangle rect = new Rectangle(0, 806, 36, 842);
rect.BackgroundColor = BaseColor.RED;
document.Add(rect);
// step 4
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
document.Add(new Paragraph(movie.MovieTitle));
// Add an image
document.Add(
Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg"))
);
}
}
}
示例10: GetPdf
public static byte[] GetPdf()
{
using (MemoryStream ms = new MemoryStream())
{
using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, ms);
document.Open();
int i = 0;
foreach (var fieldName in FieldNames)
{
var rectangle = new Rectangle(20, 800 - i * 40, 40, 780 - i * 40);
var checkbox = new RadioCheckField(
writer, rectangle, fieldName, ON_STATE
);
checkbox.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field = checkbox.CheckField;
writer.AddAnnotation(field);
++i;
}
// add textbox field for sanity-check
var textField = new TextField(
writer,
new Rectangle(20, 800 - i * 40, 400, 780 - i * 40),
TEXT_FIELD
);
writer.AddAnnotation(textField.GetTextField());
}
return ms.ToArray();
}
}
示例11: 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;
}
示例12: ApplyGradientBackground
/// <summary>
/// Draws a rectangular gradient background color.
/// </summary>
/// <param name="pdfRowType">Main table's row types</param>
/// <param name="sharedData">PdfCells Shared Data</param>
/// <param name="position">The coordinates of the cell</param>
/// <param name="canvases">An array of PdfContentByte to add text or graphics</param>
public static void ApplyGradientBackground(RowType pdfRowType, CellSharedData sharedData, Rectangle position, PdfContentByte[] canvases)
{
BaseColor startColor = null;
BaseColor endColor = null;
switch (pdfRowType)
{
case RowType.HeaderRow:
if (sharedData.Template.HeaderBackgroundColor.Count < 2) return;
startColor = sharedData.Template.HeaderBackgroundColor[0];
endColor = sharedData.Template.HeaderBackgroundColor[1];
break;
case RowType.PreviousPageSummaryRow:
if (sharedData.Template.PreviousPageSummaryRowBackgroundColor.Count < 2) return;
startColor = sharedData.Template.PreviousPageSummaryRowBackgroundColor[0];
endColor = sharedData.Template.PreviousPageSummaryRowBackgroundColor[1];
break;
case RowType.SummaryRow:
case RowType.AllGroupsSummaryRow:
if (sharedData.Template.SummaryRowBackgroundColor.Count < 2) return;
startColor = sharedData.Template.SummaryRowBackgroundColor[0];
endColor = sharedData.Template.SummaryRowBackgroundColor[1];
break;
case RowType.PageSummaryRow:
if (sharedData.Template.PageSummaryRowBackgroundColor.Count < 2) return;
startColor = sharedData.Template.PageSummaryRowBackgroundColor[0];
endColor = sharedData.Template.PageSummaryRowBackgroundColor[1];
break;
}
DrawGradientBackground(position, canvases, startColor, endColor);
}
示例13: SetSignatureBox
public void SetSignatureBox(float llx, float lly, float urx, float ury)
{
SignatureBox = new Rectangle(llx, lly, urx, ury)
{
BorderColor = BaseColor.BLACK, Border = Rectangle.BOX, BorderWidth = 1
};
}
示例14: test
virtual public void test() {
PdfReader reader = TestResourceUtils.GetResourceAsPdfReader(TEST_RESOURCES_PATH, "user10.pdf");
Rectangle rectangle = new Rectangle(71, 792 - 84, 225, 792 - 75);
RenderFilter filter = new RegionTextRenderFilter(rectangle);
String txt = PdfTextExtractor.GetTextFromPage(reader, 1, new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter));
Assert.AreEqual("Pname Dname Email Address", txt);
}
示例15: 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
Rectangle rect = new Rectangle(100, 400, 500, 800);
rect.Border = Rectangle.BOX;
rect.BorderWidth = 0.5f;
rect.BorderColor = new BaseColor(0xFF, 0x00, 0x00);
document.Add(rect);
PdfIndirectObject streamObject = null;
using (FileStream fs =
new FileStream(RESOURCE, FileMode.Open, FileAccess.Read))
{
PdfStream stream3D = new PdfStream(fs, writer);
stream3D.Put(PdfName.TYPE, new PdfName("3D"));
stream3D.Put(PdfName.SUBTYPE, new PdfName("U3D"));
stream3D.FlateCompress();
streamObject = writer.AddToBody(stream3D);
stream3D.WriteLength();
}
PdfDictionary dict3D = new PdfDictionary();
dict3D.Put(PdfName.TYPE, new PdfName("3DView"));
dict3D.Put(new PdfName("XN"), new PdfString("Default"));
dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
dict3D.Put(new PdfName("MS"), PdfName.M);
dict3D.Put(
new PdfName("C2W"),
new PdfArray(
new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }
)
);
dict3D.Put(PdfName.CO, new PdfNumber(235));
PdfIndirectObject dictObject = writer.AddToBody(dict3D);
PdfAnnotation annot = new PdfAnnotation(writer, rect);
annot.Put(PdfName.CONTENTS, new PdfString("3D Model"));
annot.Put(PdfName.SUBTYPE, new PdfName("3D"));
annot.Put(PdfName.TYPE, PdfName.ANNOT);
annot.Put(new PdfName("3DD"), streamObject.IndirectReference);
annot.Put(new PdfName("3DV"), dictObject.IndirectReference);
PdfAppearance ap = writer.DirectContent.CreateAppearance(
rect.Width, rect.Height
);
annot.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
annot.SetPage();
writer.AddAnnotation(annot);
}
}