本文整理汇总了C#中iTextSharp.text.pdf.PdfWriter类的典型用法代码示例。如果您正苦于以下问题:C# PdfWriter类的具体用法?C# PdfWriter怎么用?C# PdfWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfWriter类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PdfWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document) {
ColumnText.ShowTextAligned(
writer.DirectContentUnder,
Element.ALIGN_CENTER, new Phrase("FOOBAR FILM FESTIVAL", FONT),
297.5f, 421, writer.PageNumber % 2 == 1 ? 45 : -45
);
}
示例3: GetSpotObject
protected internal virtual PdfObject GetSpotObject(PdfWriter writer) {
PdfArray array = new PdfArray(PdfName.SEPARATION);
array.Add(name);
PdfFunction func = null;
if (altcs is ExtendedColor) {
int type = ((ExtendedColor)altcs).Type;
switch (type) {
case ExtendedColor.TYPE_GRAY:
array.Add(PdfName.DEVICEGRAY);
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0}, new float[]{((GrayColor)altcs).Gray}, 1);
break;
case ExtendedColor.TYPE_CMYK:
array.Add(PdfName.DEVICECMYK);
CMYKColor cmyk = (CMYKColor)altcs;
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0, 0, 0, 0},
new float[]{cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black}, 1);
break;
default:
throw new Exception(MessageLocalization.GetComposedMessage("only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces"));
}
}
else {
array.Add(PdfName.DEVICERGB);
func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{1, 1, 1},
new float[]{(float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255}, 1);
}
array.Add(func.Reference);
return array;
}
示例4: PdfReaderInstance
internal PdfReaderInstance(PdfReader reader, PdfWriter writer)
{
this.reader = reader;
this.writer = writer;
file = reader.SafeFile;
myXref = new int[reader.XrefSize];
}
示例5: Url
/**
* Creates a file specification of type URL.
* @param writer the <CODE>PdfWriter</CODE>
* @param url the URL
* @return the file specification
*/
public static PdfFileSpecification Url(PdfWriter writer, String url) {
PdfFileSpecification fs = new PdfFileSpecification();
fs.writer = writer;
fs.Put(PdfName.FS, PdfName.URL);
fs.Put(PdfName.F, new PdfString(url));
return fs;
}
示例6: OnChapter
/**
* Initialize one of the headers, based on the chapter title;
* reset the page number.
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onChapter(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document, float,
* com.itextpdf.text.Paragraph)
*/
public override void OnChapter(
PdfWriter writer, Document document,
float paragraphPosition, Paragraph title)
{
header[1] = new Phrase(title.Content);
pagenumber = 1;
}
示例7: PageFinished
/// <summary>
/// Fires when a page is finished, just before being written to the document.
/// </summary>
/// <param name="writer">PdfWriter</param>
/// <param name="document">PDF Document</param>
/// <param name="columnCellsSummaryData">List of all rows summaries data</param>
public void PageFinished(PdfWriter writer, Document document, IList<SummaryCellData> columnCellsSummaryData)
{
var footerTable = AddPageFooter(new FooterData
{
PdfDoc = document,
PdfWriter = writer,
SummaryData = columnCellsSummaryData,
CurrentPageNumber = writer.PageNumber,
TotalPagesCountImage = _totalPageCountImage
});
var table = new PdfGrid(1)
{
RunDirection = (int)FooterProperties.RunDirection,
WidthPercentage = FooterProperties.TableWidthPercentage
};
var tableCell = new PdfPCell(footerTable) { Border = 0 };
table.AddCell(tableCell);
var page = document.PageSize;
table.SetTotalWidth(new[] { page.Width - document.LeftMargin - document.RightMargin });
table.WriteSelectedRows(
rowStart: 0,
rowEnd: -1,
xPos: document.LeftMargin,
yPos: document.BottomMargin - FooterProperties.SpacingBeforeTable,
canvas: writer.DirectContent);
}
示例8: OnOpenDocument
// we override the onOpenDocument method
public override void OnOpenDocument(PdfWriter writer, Document document)
{
_bf = _normalFont.GetCalculatedBaseFont(false);
_cb = writer.DirectContent;
_ct = new ColumnText(_cb);
base.OnOpenDocument(writer, document);
}
示例9: OnOpenDocument
public override void OnOpenDocument(PdfWriter writer, Document document)
{
total = writer.DirectContent.CreateTemplate(100, 100);
total.BoundingBox = new Rectangle(-20, -20, 100, 100);
helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
示例10: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
string text = "Page " + writer.PageNumber + " of ";
float textBase = document.Bottom - 20;
float textSize = 12; //helv.GetWidthPoint(text, 12);
cb.BeginText();
cb.SetFontAndSize(helv, 12);
if ((writer.PageNumber % 2) == 1)
{
cb.SetTextMatrix(document.Left, textBase);
cb.ShowText(text);
cb.EndText();
cb.AddTemplate(total, document.Left + textSize, textBase);
}
else
{
float adjust = helv.GetWidthPoint("0", 12);
cb.SetTextMatrix(document.Right - textSize - adjust, textBase);
cb.ShowText(text);
cb.EndText();
cb.AddTemplate(total, document.Right - adjust, textBase);
}
cb.RestoreState();
}
示例11: Close
public override void Close(PdfWriter writer) {
base.Close(writer);
bool ok = false;
IXmpMeta xmpMeta = writer.XmpWriter.XmpMeta;
try {
String docFileName = xmpMeta.GetPropertyString(PdfAXmpWriter.zugferdSchemaNS,
PdfAXmpWriter.zugferdDocumentFileName);
foreach (PdfFileSpecification attachment in attachments) {
if (docFileName.Equals(attachment.GetAsString(PdfName.UF).ToString())) {
PdfName relationship = attachment.GetAsName(PdfName.AFRELATIONSHIP);
if (!AFRelationshipValue.Alternative.Equals(relationship)) {
attachments.Clear();
throw new PdfAConformanceException(attachment,
MessageLocalization.GetComposedMessage("afrelationship.value.shall.be.alternative"));
}
ok = true;
break;
}
}
} catch (Exception e) {
attachments.Clear();
throw e;
}
attachments.Clear();
if (!ok) {
throw new PdfAConformanceException(xmpMeta,
MessageLocalization.GetComposedMessage("zugferd.xmp.schema.shall.contain.attachment.name"));
}
}
示例12: OnStartPage
public override void OnStartPage(PdfWriter writer, Document document) {
PdfPTable headerTable = new PdfPTable(1);
headerTable.AddCell(new Phrase("Header"));
WriteTable(writer.DirectContent, headerTable,
new Rectangle(0, document.PageSize.Height - 50f, document.PageSize.Width, document.PageSize.Height));
}
示例13: CheckPdfAConformance
/**
*
* @param writer
* @param key
* @param obj1
*/
static public void CheckPdfAConformance(PdfWriter writer, int key, Object obj1) {
if (writer == null || !writer.IsPdfIso())
return;
switch (key) {
case PdfIsoKeys.PDFISOKEY_FONT:
if (!((BaseFont)obj1).IsEmbedded())
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont) obj1).PostscriptFontName));
break;
case PdfIsoKeys.PDFISOKEY_IMAGE:
PdfImage image = (PdfImage)obj1;
if (image.Get(PdfName.SMASK) != null)
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
break;
case PdfIsoKeys.PDFISOKEY_GSTATE:
PdfDictionary gs = (PdfDictionary)obj1;
PdfObject obj = gs.Get(PdfName.BM);
if (obj != null && !PdfGState.BM_NORMAL.Equals(obj) && !PdfGState.BM_COMPATIBLE.Equals(obj))
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("blend.mode.1.not.allowed", obj.ToString()));
obj = gs.Get(PdfName.CA);
double v = 0.0;
if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
obj = gs.Get(PdfName.ca_);
v = 0.0;
if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
break;
case PdfIsoKeys.PDFISOKEY_LAYER:
throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("layers.are.not.allowed"));
default:
break;
}
}
示例14: OnEndPage
//重写 关闭一个页面时
public override void OnEndPage(PdfWriter writer, Document document)
{
try
{
Font font = new Font(basefont, defaultFontSize);
Phrase head = new Phrase(header, font);
PdfContentByte cb = writer.DirectContent;
//页眉显示的位置
ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, head,
document.Right - 10 + document.LeftMargin, document.Top + 10, 0);
if (PAGE_NUMBER)
{
Phrase footer = new Phrase("第 " + writer.PageNumber + " / " + " "+" 頁", font);
cb = writer.DirectContent;
//tpl = cb.CreateTemplate(100, 100);
//模版 显示总共页数
cb.AddTemplate(tpl, document.Left / 2 + document.Right / 2 , document.Bottom - 10);//调节模版显示的位置
//页脚显示的位置
ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, footer,
document.Left / 2+document.Right/ 2+23, document.Bottom - 10, 0);
}
}
catch (Exception ex)
{
throw new Exception("HeaderAndFooterEvent-->OnEndPage-->" + ex.Message);
}
}
示例15: CreateTitle
/**
* Creates a title layer. A title layer is not really a layer but a collection of layers
* under the same title heading.
* @param title the title text
* @param writer the <CODE>PdfWriter</CODE>
* @return the title layer
*/
public static PdfLayer CreateTitle(String title, PdfWriter writer) {
if (title == null)
throw new ArgumentNullException("Title cannot be null.");
PdfLayer layer = new PdfLayer(title);
writer.RegisterLayer(layer);
return layer;
}