本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.Put方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.Put方法的具體用法?C# PdfDictionary.Put怎麽用?C# PdfDictionary.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.Put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreatePdf
// ---------------------------------------------------------------------------
public byte[] CreatePdf() {
using (MemoryStream ms = new MemoryStream()) {
// step 1
using (Document document = new Document(new Rectangle(850, 600))) {
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfContentByte canvas = writer.DirectContent;
// add the clipped image
Image img = Image.GetInstance(
Path.Combine(Utility.ResourceImage, RESOURCE)
);
float w = img.ScaledWidth;
float h = img.ScaledHeight;
canvas.Ellipse(1, 1, 848, 598);
canvas.Clip();
canvas.NewPath();
canvas.AddImage(img, w, 0, 0, h, 0, -600);
// Create a transparent PdfTemplate
PdfTemplate t2 = writer.DirectContent.CreateTemplate(850, 600);
PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
transGroup.Put( PdfName.CS, PdfName.DEVICEGRAY);
transGroup.Isolated = true;
transGroup.Knockout = false;
t2.Group = transGroup;
// Add transparent ellipses to the template
int gradationStep = 30;
float[] gradationRatioList = new float[gradationStep];
for(int i = 0; i < gradationStep; i++) {
/*
* gotta love .NET, guess they forgot to copy java.lang.Math.toRadians
*/
double radians = (Math.PI / 180) * 90.0f / gradationStep * (i + 1);
gradationRatioList[i] = 1 - (float) Math.Sin(radians);
}
for(int i = 1; i < gradationStep + 1; i++) {
t2.SetLineWidth(5 * (gradationStep + 1 - i));
t2.SetGrayStroke(gradationRatioList[gradationStep - i]);
t2.Ellipse(0, 0, 850, 600);
t2.Stroke();
}
// Create an image mask for the direct content
PdfDictionary maskDict = new PdfDictionary();
maskDict.Put(PdfName.TYPE, PdfName.MASK);
maskDict.Put(PdfName.S, new PdfName("Luminosity"));
maskDict.Put(new PdfName("G"), t2.IndirectReference);
PdfGState gState = new PdfGState();
gState.Put(PdfName.SMASK, maskDict );
canvas.SetGState(gState);
canvas.AddTemplate(t2, 0, 0);
}
return ms.ToArray();
}
}
示例2: SetColorProfile
/// <summary>
/// Sets PDF/A Conformance ColorProfile.
/// </summary>
public void SetColorProfile()
{
if (PageSetup.ConformanceLevel == PdfXConformance.PDFXNONE) return;
var pdfDictionary = new PdfDictionary(PdfName.OUTPUTINTENT);
pdfDictionary.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
pdfDictionary.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
pdfDictionary.Put(PdfName.S, PdfName.GTS_PDFA1);
var profileStream = StreamHelper.GetResourceByName("PdfRpt.Core.Helper.srgb.profile");
var pdfICCBased = new PdfICCBased(ICC_Profile.GetInstance(profileStream));
pdfICCBased.Remove(PdfName.ALTERNATE);
pdfDictionary.Put(PdfName.DESTOUTPUTPROFILE, PdfWriter.AddToBody(pdfICCBased).IndirectReference);
PdfWriter.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(pdfDictionary));
}
示例3: AddPage
internal void AddPage(PdfDictionary page) {
if ((pages.Count % leafSize) == 0)
parents.Add(writer.PdfIndirectReference);
PdfIndirectReference parent = parents[parents.Count - 1];
page.Put(PdfName.PARENT, parent);
PdfIndirectReference current = writer.CurrentPage;
writer.AddToBody(page, current);
pages.Add(current);
}
示例4: PdfMediaClipData
internal PdfMediaClipData(String file, PdfFileSpecification fs, String mimeType) {
Put(PdfName.TYPE,new PdfName("MediaClip"));
Put(PdfName.S, new PdfName("MCD"));
Put(PdfName.N, new PdfString("Media clip for "+file));
Put(new PdfName("CT"), new PdfString(mimeType));
PdfDictionary dic = new PdfDictionary();
dic.Put(new PdfName("TF"), new PdfString("TEMPACCESS"));
Put(new PdfName("P"), dic);
Put(PdfName.D, fs.Reference);
}
示例5: addAsAttachment
private void addAsAttachment(IDataExporter exporter, byte[] data)
{
if (string.IsNullOrEmpty(exporter.FileName))
throw new InvalidOperationException("Please fill the exporter.FileName.");
if (string.IsNullOrEmpty(exporter.Description))
exporter.Description = "Exported data";
var pdfDictionary = new PdfDictionary();
pdfDictionary.Put(PdfName.MODDATE, new PdfDate(DateTime.Now));
var fs = PdfFileSpecification.FileEmbedded(_sharedData.PdfWriter, null, exporter.FileName, data, true, null, pdfDictionary);
_sharedData.PdfWriter.AddFileAttachment(exporter.Description, fs);
}
示例6: 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);
}
}
示例7: GetPdfObject
public virtual PdfObject GetPdfObject(PdfWriter writer) {
PdfArray array = new PdfArray(PdfName.LAB);
PdfDictionary dictionary = new PdfDictionary();
if (whitePoint == null
|| whitePoint.Length != 3
|| whitePoint[0] < 0.000001f || whitePoint[2] < 0.000001f
|| whitePoint[1] < 0.999999f || whitePoint[1] > 1.000001f)
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.white.point"));
dictionary.Put(PdfName.WHITEPOINT, new PdfArray(whitePoint));
if (blackPoint != null) {
if (blackPoint.Length != 3
|| blackPoint[0] < -0.000001f || blackPoint[1] < -0.000001f || blackPoint[2] < -0.000001f)
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.black.point"));
dictionary.Put(PdfName.BLACKPOINT, new PdfArray(blackPoint));
}
if (range != null) {
if (range.Length != 4 || range[0] > range[1] || range[2] > range[3])
throw new Exception(MessageLocalization.GetComposedMessage("lab.cs.range"));
dictionary.Put(PdfName.RANGE, new PdfArray(range));
}
array.Add(dictionary);
return array;
}
示例8: SetOriginalResources
internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr) {
if (newNamePtr != null)
namePtr = newNamePtr;
forbiddenNames = new Dictionary<PdfName,object>();
usedNames = new Dictionary<PdfName,PdfName>();
if (resources == null)
return;
originalResources = new PdfDictionary();
originalResources.Merge(resources);
foreach (PdfName key in resources.Keys) {
PdfObject sub = PdfReader.GetPdfObject(resources.Get(key));
if (sub != null && sub.IsDictionary()) {
PdfDictionary dic = (PdfDictionary)sub;
foreach (PdfName name in dic.Keys) {
forbiddenNames[name] = null;
}
PdfDictionary dic2 = new PdfDictionary();
dic2.Merge(dic);
originalResources.Put(key, dic2);
}
}
}
示例9: CompleteExtraCatalog
private void CompleteExtraCatalog(PdfDictionary extraCatalog) {
if (IsPdfX()) {
if (extraCatalog.Get(PdfName.OUTPUTINTENTS) == null) {
PdfDictionary outD = new PdfDictionary(PdfName.OUTPUTINTENT);
outD.Put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995"));
outD.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001"));
outD.Put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org"));
outD.Put(PdfName.INFO, new PdfString(""));
outD.Put(PdfName.S, PdfName.GTS_PDFX);
extraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outD));
}
}
}
示例10: AddDirectImageSimple
/**
* Adds an image to the document but not to the page resources. It is used with
* templates and <CODE>Document.Add(Image)</CODE>.
* @param image the <CODE>Image</CODE> to add
* @param fixedRef the reference to used. It may be <CODE>null</CODE>,
* a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
* @return the name of the image added
* @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName AddDirectImageSimple(Image image, PdfIndirectReference fixedRef) {
PdfName name;
// if the images is already added, just retrieve the name
if (images.ContainsKey(image.MySerialId)) {
name = images[image.MySerialId];
}
// if it's a new image, add it to the document
else {
if (image.IsImgTemplate()) {
name = new PdfName("img" + images.Count);
if (image is ImgWMF){
ImgWMF wmf = (ImgWMF)image;
wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
}
}
else {
PdfIndirectReference dref = image.DirectReference;
if (dref != null) {
PdfName rname = new PdfName("img" + images.Count);
images[image.MySerialId] = rname;
imageDictionary.Put(rname, dref);
return rname;
}
Image maskImage = image.ImageMask;
PdfIndirectReference maskRef = null;
if (maskImage != null) {
PdfName mname = images[maskImage.MySerialId];
maskRef = GetImageReference(mname);
}
PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
if (image is ImgJBIG2) {
byte[] globals = ((ImgJBIG2) image).GlobalBytes;
if (globals != null) {
PdfDictionary decodeparms = new PdfDictionary();
decodeparms.Put(PdfName.JBIG2GLOBALS, GetReferenceJBIG2Globals(globals));
i.Put(PdfName.DECODEPARMS, decodeparms);
}
}
if (image.HasICCProfile()) {
PdfICCBased icc = new PdfICCBased(image.TagICC, image.CompressionLevel);
PdfIndirectReference iccRef = Add(icc);
PdfArray iccArray = new PdfArray();
iccArray.Add(PdfName.ICCBASED);
iccArray.Add(iccRef);
PdfArray colorspace = i.GetAsArray(PdfName.COLORSPACE);
if (colorspace != null) {
if (colorspace.Size > 1 && PdfName.INDEXED.Equals(colorspace[0]))
colorspace[1] = iccArray;
else
i.Put(PdfName.COLORSPACE, iccArray);
}
else
i.Put(PdfName.COLORSPACE, iccArray);
}
Add(i, fixedRef);
name = i.Name;
}
images[image.MySerialId] = name;
}
return name;
}
示例11: AddASEvent
private void AddASEvent(PdfName eventa, PdfName category) {
PdfArray arr = new PdfArray();
foreach (PdfLayer layer in documentOCG.Keys) {
PdfDictionary usage = layer.GetAsDict(PdfName.USAGE);
if (usage != null && usage.Get(category) != null)
arr.Add(layer.Ref);
}
if (arr.Size == 0)
return;
PdfDictionary d = vOCProperties.GetAsDict(PdfName.D);
PdfArray arras = d.GetAsArray(PdfName.AS);
if (arras == null) {
arras = new PdfArray();
d.Put(PdfName.AS, arras);
}
PdfDictionary asa = new PdfDictionary();
asa.Put(PdfName.EVENT, eventa);
asa.Put(PdfName.CATEGORY, new PdfArray(category));
asa.Put(PdfName.OCGS, arr);
arras.Add(asa);
}
示例12: WriteOutlines
protected internal void WriteOutlines(PdfDictionary catalog, bool namedAsNames) {
if (newBookmarks == null || newBookmarks.Count == 0)
return;
PdfDictionary top = new PdfDictionary();
PdfIndirectReference topRef = this.PdfIndirectReference;
Object[] kids = SimpleBookmark.IterateOutlines(this, topRef, newBookmarks, namedAsNames);
top.Put(PdfName.FIRST, (PdfIndirectReference)kids[0]);
top.Put(PdfName.LAST, (PdfIndirectReference)kids[1]);
top.Put(PdfName.COUNT, new PdfNumber((int)kids[2]));
AddToBody(top, topRef);
catalog.Put(PdfName.OUTLINES, topRef);
}
示例13: Add
/**
* Adds some <CODE>PdfContents</CODE> to this Writer.
* <P>
* The document has to be open before you can begin to add content
* to the body of the document.
*
* @return a <CODE>PdfIndirectReference</CODE>
* @param page the <CODE>PdfPage</CODE> to add
* @param contents the <CODE>PdfContents</CODE> of the page
* @throws PdfException on error
*/
internal virtual PdfIndirectReference Add(PdfPage page, PdfContents contents) {
if (!open) {
throw new PdfException(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
}
PdfIndirectObject objecta;
objecta = AddToBody(contents);
page.Add(objecta.IndirectReference);
if (group != null) {
page.Put(PdfName.GROUP, group);
group = null;
}
else if (rgbTransparencyBlending) {
PdfDictionary pp = new PdfDictionary();
pp.Put(PdfName.TYPE, PdfName.GROUP);
pp.Put(PdfName.S, PdfName.TRANSPARENCY);
pp.Put(PdfName.CS, PdfName.DEVICERGB);
page.Put(PdfName.GROUP, pp);
}
root.AddPage(page);
currentPageNumber++;
return null;
}
示例14: MoveRectangle
private static void MoveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) {
Rectangle m = r.GetBoxSize(pageImported, name);
if (m == null)
dic2.Remove(key);
else
dic2.Put(key, new PdfRectangle(m));
}
示例15: WriteLineToContent
//.........這裏部分代碼省略.........
int cap2 = (int)ps[4];
if (cap2 != 0)
graphics.SetLineCap(cap2);
graphics.MoveTo(xMarker, yMarker + shift);
graphics.LineTo(xMarker + width - subtract, yMarker + shift);
graphics.Stroke();
if (scolor != null)
graphics.ResetGrayStroke();
if (cap2 != 0)
graphics.SetLineCap(0);
}
graphics.SetLineWidth(1);
if (inText && IsTagged(writer)) {
graphics.BeginText(true);
}
}
if (chunk.IsAttribute(Chunk.ACTION))
{
float subtract = lastBaseFactor;
if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
subtract = 0;
if (nextChunk == null)
subtract += hangingCorrection;
PdfAnnotation annot = null;
if (chunk.IsImage()) {
annot = new PdfAnnotation(writer, xMarker, yMarker + chunk.ImageOffsetY, xMarker + width - subtract, yMarker + chunk.ImageHeight + chunk.ImageOffsetY, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
}
else {
annot = new PdfAnnotation(writer, xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
}
text.AddAnnotation(annot, true);
if (IsTagged(writer) && chunk.accessibleElement != null) {
int structParent = GetStructParentIndex(annot);
annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
PdfStructureElement strucElem;
structElements.TryGetValue(chunk.accessibleElement.ID, out strucElem);
if (strucElem != null) {
PdfArray kArray = strucElem.GetAsArray(PdfName.K);
if (kArray == null) {
kArray = new PdfArray();
PdfObject k = strucElem.Get(PdfName.K);
if (k != null) {
kArray.Add(k);
}
strucElem.Put(PdfName.K, kArray);
}
PdfDictionary dict = new PdfDictionary();
dict.Put(PdfName.TYPE, PdfName.OBJR);
dict.Put(PdfName.OBJ, annot.IndirectReference);
kArray.Add(dict);
writer.StructureTreeRoot.SetAnnotationMark(structParent, strucElem.Reference);
}
}
}
if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
float subtract = lastBaseFactor;
if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
subtract = 0;
if (nextChunk == null)
subtract += hangingCorrection;
Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
String filename = (String)obj[0];
if (obj[1] is String)
RemoteGoto(filename, (String)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
else
RemoteGoto(filename, (int)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);