本文整理汇总了C#中iTextSharp.text.pdf.PdfStream类的典型用法代码示例。如果您正苦于以下问题:C# PdfStream类的具体用法?C# PdfStream怎么用?C# PdfStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfStream类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PdfStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFormXObject
/**
* Gets the stream representing this object.
*
* @param compressionLevel the compressionLevel
* @return the stream representing this template
* @since 2.1.3 (replacing the method without param compressionLevel)
* @throws IOException
*/
override public PdfStream GetFormXObject(int compressionLevel) {
PdfStream s = new PdfStream(content.ToByteArray());
s.Put(PdfName.TYPE, PdfName.XOBJECT);
s.Put(PdfName.SUBTYPE, PdfName.PS);
s.FlateCompress(compressionLevel);
return s;
}
示例2: 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);
}
}
示例3: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src)
{
// the font file
byte[] fontfile = null;
using (FileStream fs = new FileStream(
FONT, FileMode.Open, FileAccess.Read))
{
fontfile = new byte[fs.Length];
fs.Read(fontfile, 0, (int) fs.Length);
}
// create a new stream for the font file
PdfStream stream = new PdfStream(fontfile);
stream.FlateCompress();
stream.Put(PdfName.LENGTH1, new PdfNumber(fontfile.Length));
// create a reader object
PdfReader reader = new PdfReader(src);
int n = reader.XrefSize;
PdfDictionary font;
using (MemoryStream ms = new MemoryStream()) {
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
PdfName fontname = new PdfName(FONTNAME);
for (int i = 0; i < n; i++) {
PdfObject objectPdf = reader.GetPdfObject(i);
if (objectPdf == null || !objectPdf.IsDictionary()) {
continue;
}
font = (PdfDictionary)objectPdf;
if (PdfName.FONTDESCRIPTOR.Equals(font.Get(PdfName.TYPE))
&& fontname.Equals(font.Get(PdfName.FONTNAME)))
{
PdfIndirectObject objref = stamper.Writer.AddToBody(stream);
font.Put(PdfName.FONTFILE2, objref.IndirectReference);
}
}
}
return ms.ToArray();
}
}
示例4: GetReferenceJBIG2Globals
/**
* Gets an indirect reference to a JBIG2 Globals stream.
* Adds the stream if it hasn't already been added to the writer.
* @param content a byte array that may already been added to the writer inside a stream object.
* @since 2.1.5
*/
protected internal PdfIndirectReference GetReferenceJBIG2Globals(byte[] content) {
if (content == null) return null;
foreach (PdfStream str in JBIG2Globals.Keys) {
if (Org.BouncyCastle.Utilities.Arrays.AreEqual(content, str.GetBytes())) {
return JBIG2Globals[str];
}
}
PdfStream stream = new PdfStream(content);
PdfIndirectObject refi;
try {
refi = AddToBody(stream);
} catch (IOException) {
return null;
}
JBIG2Globals[stream] = refi.IndirectReference;
return refi.IndirectReference;
}
示例5: Close
/**
* Signals that the <CODE>Document</CODE> was closed and that no other
* <CODE>Elements</CODE> will be added.
* <P>
* The pages-tree is built and written to the outputstream.
* A Catalog is constructed, as well as an Info-object,
* the referencetable is composed and everything is written
* to the outputstream embedded in a Trailer.
*/
public override void Close() {
if (open) {
if ((currentPageNumber - 1) != pageReferences.Count)
throw new Exception("The page " + pageReferences.Count +
" was requested but the document has only " + (currentPageNumber - 1) + " pages.");
pdf.Close();
AddSharedObjectsToBody();
foreach (IPdfOCG layer in documentOCG.Keys) {
AddToBody(layer.PdfObject, layer.Ref);
}
// add the root to the body
PdfIndirectReference rootRef = root.WritePageTree();
// make the catalog-object and add it to the body
PdfDictionary catalog = GetCatalog(rootRef);
// [C9] if there is XMP data to add: add it
if (xmpMetadata != null) {
PdfStream xmp = new PdfStream(xmpMetadata);
xmp.Put(PdfName.TYPE, PdfName.METADATA);
xmp.Put(PdfName.SUBTYPE, PdfName.XML);
if (crypto != null && !crypto.IsMetadataEncrypted()) {
PdfArray ar = new PdfArray();
ar.Add(PdfName.CRYPT);
xmp.Put(PdfName.FILTER, ar);
}
catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
}
// [C10] make pdfx conformant
if (IsPdfX()) {
CompleteInfoDictionary(Info);
CompleteExtraCatalog(ExtraCatalog);
}
// [C11] Output Intents
if (extraCatalog != null) {
catalog.MergeDifferent(extraCatalog);
}
WriteOutlines(catalog, false);
// add the Catalog to the body
PdfIndirectObject indirectCatalog = AddToBody(catalog, false);
// add the info-object to the body
PdfIndirectObject infoObj = AddToBody(Info, false);
// [F1] encryption
PdfIndirectReference encryption = null;
PdfObject fileID = null;
body.FlushObjStm();
if (crypto != null) {
PdfIndirectObject encryptionObject = AddToBody(crypto.GetEncryptionDictionary(), false);
encryption = encryptionObject.IndirectReference;
fileID = crypto.FileID;
}
else
fileID = PdfEncryption.CreateInfoId(PdfEncryption.CreateDocumentId());
// write the cross-reference table of the body
body.WriteCrossReferenceTable(os, indirectCatalog.IndirectReference,
infoObj.IndirectReference, encryption, fileID, prevxref);
// make the trailer
// [F2] full compression
if (fullCompression) {
WriteKeyInfo(os);
byte[] tmp = GetISOBytes("startxref\n");
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes(body.Offset.ToString());
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes("\n%%EOF\n");
os.Write(tmp, 0, tmp.Length);
}
else {
PdfTrailer trailer = new PdfTrailer(body.Size,
body.Offset,
indirectCatalog.IndirectReference,
infoObj.IndirectReference,
encryption,
fileID, prevxref);
trailer.ToPdf(this, os);
}
base.Close();
}
}
示例6: Close
//.........这里部分代码省略.........
buf = new StringBuilder(producer.Substring(0, idx));
buf.Append("; modified using ");
buf.Append(version.GetVersion);
producer = buf.ToString();
}
PdfIndirectReference info = null;
PdfDictionary newInfo = new PdfDictionary();
if (oldInfo != null) {
foreach (PdfName key in oldInfo.Keys) {
PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
newInfo.Put(key, value);
}
}
if (moreInfo != null) {
foreach (KeyValuePair<string,string> entry in moreInfo) {
PdfName keyName = new PdfName(entry.Key);
String value = entry.Value;
if (value == null)
newInfo.Remove(keyName);
else
newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
}
}
PdfDate date = new PdfDate();
newInfo.Put(PdfName.MODDATE, date);
newInfo.Put(PdfName.PRODUCER, new PdfString(producer, PdfObject.TEXT_UNICODE));
if (append) {
if (iInfo == null) {
info = AddToBody(newInfo, false).IndirectReference;
} else {
info = AddToBody(newInfo, iInfo.Number, false).IndirectReference;
}
} else {
info = AddToBody(newInfo, false).IndirectReference;
}
// XMP
byte[] altMetadata = null;
PdfObject xmpo = PdfReader.GetPdfObject(catalog.Get(PdfName.METADATA));
if (xmpo != null && xmpo.IsStream()) {
altMetadata = PdfReader.GetStreamBytesRaw((PRStream)xmpo);
PdfReader.KillIndirect(catalog.Get(PdfName.METADATA));
}
PdfStream xmp = null;
if (xmpMetadata != null) {
altMetadata = xmpMetadata;
} else if (xmpWriter != null) {
try {
MemoryStream baos = new MemoryStream();
PdfProperties.SetProducer(xmpWriter.XmpMeta, producer);
XmpBasicProperties.SetModDate(xmpWriter.XmpMeta, date.GetW3CDate());
XmpBasicProperties.SetMetaDataDate(xmpWriter.XmpMeta, date.GetW3CDate());
xmpWriter.Serialize(baos);
xmpWriter.Close();
xmp = new PdfStream(baos.ToArray());
} catch (XmpException) {
xmpWriter = null;
}
}
if (xmp == null && altMetadata != null) {
try {
MemoryStream baos = new MemoryStream();
if (moreInfo == null || xmpMetadata != null) {
IXmpMeta xmpMeta = XmpMetaFactory.ParseFromBuffer(altMetadata);
PdfProperties.SetProducer(xmpMeta, producer);
XmpBasicProperties.SetModDate(xmpMeta, date.GetW3CDate());
XmpBasicProperties.SetMetaDataDate(xmpMeta, date.GetW3CDate());
SerializeOptions serializeOptions = new SerializeOptions();
serializeOptions.Padding = 2000;
XmpMetaFactory.Serialize(xmpMeta, baos, serializeOptions);
} else {
XmpWriter xmpw = CreateXmpWriter(baos, newInfo);
xmpw.Close();
}
xmp = new PdfStream(baos.ToArray());
} catch (XmpException) {
xmp = new PdfStream(altMetadata);
} catch (IOException) {
xmp = new PdfStream(altMetadata);
}
}
if (xmp != null) {
xmp.Put(PdfName.TYPE, PdfName.METADATA);
xmp.Put(PdfName.SUBTYPE, PdfName.XML);
if (crypto != null && !crypto.IsMetadataEncrypted()) {
PdfArray ar = new PdfArray();
ar.Add(PdfName.CRYPT);
xmp.Put(PdfName.FILTER, ar);
}
if (append && xmpo != null) {
body.Add(xmp, xmpo.IndRef);
}
else {
catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
MarkUsed(catalog);
}
}
Close(info, skipInfo);
}
示例7: AlterContents
public void AlterContents()
{
if (over == null && under == null)
return;
PdfArray ar = null;
PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN);
if (content == null) {
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
else if (content.IsArray()) {
ar = (PdfArray)content;
}
else if (content.IsStream()) {
ar = new PdfArray();
ar.Add(pageN.Get(PdfName.CONTENTS));
pageN.Put(PdfName.CONTENTS, ar);
}
else {
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
ByteBuffer out_p = new ByteBuffer();
if (under != null) {
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(under.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
}
if (over != null)
out_p.Append(PdfContents.SAVESTATE);
PdfStream stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(cstp.CompressionLevel);
PdfIndirectReference ref1 = cstp.AddToBody(stream).IndirectReference;
ar.AddFirst(ref1);
out_p.Reset();
if (over != null) {
out_p.Append(' ');
out_p.Append(PdfContents.RESTORESTATE);
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(over.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(cstp.CompressionLevel);
ar.Add(cstp.AddToBody(stream).IndirectReference);
}
pageN.Put(PdfName.RESOURCES, pageResources.Resources);
}
示例8: WriteFont
/**
* @see TtfUnicodeWriter#writeFont(TrueTypeFontUnicode, PdfIndirectReference, Object[], byte[])
*/
override protected void WriteFont(TrueTypeFontUnicode font, PdfIndirectReference refer, Object[] parameters, byte[] rotbits) {
Dictionary<int, int[]> longTag = (Dictionary<int, int[]>)parameters[0];
font.AddRangeUni(longTag, true, font.Subset);
int [][] metrics = new int[longTag.Count][];
longTag.Values.CopyTo(metrics, 0);
Array.Sort(metrics, font);
PdfIndirectReference ind_font = null;
PdfObject pobj = null;
PdfIndirectObject obj = null;
PdfIndirectReference cidset = null;
PdfStream stream;
if (metrics.Length == 0) {
stream = new PdfStream(new byte[]{(byte)0x80});
}
else {
int top = metrics[metrics.Length - 1][0];
byte[] bt = new byte[top / 8 + 1];
for (int k = 0; k < metrics.Length; ++k) {
int v = metrics[k][0];
bt[v / 8] |= rotbits[v % 8];
}
stream = new PdfStream(bt);
stream.FlateCompress(font.CompressionLevel);
}
cidset = writer.AddToBody(stream).IndirectReference;
if (font.Cff) {
byte[] b = font.ReadCffFont();
if (font.Subset || font.SubsetRanges != null) {
CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag);
b = cff.Process(cff.GetNames()[0]);
}
pobj = new BaseFont.StreamFont(b, "CIDFontType0C", font.CompressionLevel);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
} else {
byte[] b;
if (font.Subset || font.DirectoryOffset != 0) {
TrueTypeFontSubSet sb = new TrueTypeFontSubSet(font.FileName, new RandomAccessFileOrArray(font.Rf), longTag, font.DirectoryOffset, false, false);
b = sb.Process();
}
else {
b = font.GetFullFont();
}
int[] lengths = new int[] { b.Length };
pobj = new BaseFont.StreamFont(b,lengths, font.CompressionLevel);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
}
String subsetPrefix = "";
if (font.Subset)
subsetPrefix = BaseFont.CreateSubsetPrefix();
PdfDictionary dic = font.GetFontDescriptor(ind_font, subsetPrefix, cidset);
obj = writer.AddToBody(dic);
ind_font = obj.IndirectReference;
pobj = font.GetCIDFontType2(ind_font, subsetPrefix, metrics);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
pobj = font.GetToUnicode(metrics);
PdfIndirectReference toUnicodeRef = null;
if (pobj != null) {
obj = writer.AddToBody(pobj);
toUnicodeRef = obj.IndirectReference;
}
pobj = font.GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
writer.AddToBody(pobj, refer);
}
示例9: AnnotationCheckTest11
public void AnnotationCheckTest11() {
Document document = new Document();
PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest11.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2A);
writer.CreateXmpMetadata();
writer.SetTagged();
document.Open();
document.AddLanguage("en-US");
Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
document.Add(new Paragraph("Hello World", font));
FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
iccProfileFileStream.Close();
writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
annot.Put(PdfName.SUBTYPE, PdfName.STAMP);
annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
annot.Put(PdfName.CONTENTS, new PdfString("Hello World"));
PdfDictionary ap = new PdfDictionary();
PdfStream s = new PdfStream(Encoding.Default.GetBytes("Hello World"));
ap.Put(PdfName.N, writer.AddToBody(s).IndirectReference);
annot.Put(PdfName.AP, ap);
PdfContentByte canvas = writer.DirectContent;
canvas.AddAnnotation(annot);
document.Close();
}
示例10: InsertFormXObj
private void InsertFormXObj(PdfContentByte canvas, PdfDictionary pageDict, PdfStream formXObj, IList<Rectangle> clippingRects, Rectangle annotRect) {
PdfName xobjName = GenerateNameForXObj(pageDict);
canvas.SaveState();
foreach (Rectangle rect in clippingRects) {
canvas.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
}
canvas.Clip();
canvas.NewPath();
canvas.AddFormXObj(formXObj, xobjName, 1, 0, 0, 1, annotRect.Left, annotRect.Bottom);
canvas.RestoreState();
}
示例11: AddFormXObj
/**
* Adds a form XObject to this content.
*
* @param formXObj the form XObject
* @param name the name of form XObject in content stream. The name is changed, if if it already exists in page resources
* @param a an element of the transformation matrix
* @param b an element of the transformation matrix
* @param c an element of the transformation matrix
* @param d an element of the transformation matrix
* @param e an element of the transformation matrix
* @param f an element of the transformation matrix
*
* @return Name under which XObject was stored in resources. See <code>name</code> parameter
*/
public virtual PdfName AddFormXObj(PdfStream formXObj, PdfName name, float a, float b, float c, float d, float e, float f) {
return AddFormXObj(formXObj, name, (double) a, (double) b, (double) c, (double) d, (double) e, (double) f);
}
示例12: OutputDss
private void OutputDss(PdfDictionary dss, PdfDictionary vrim, PdfArray ocsps, PdfArray crls, PdfArray certs) {
PdfDictionary catalog = reader.Catalog;
writer.MarkUsed(catalog);
foreach (PdfName vkey in validated.Keys) {
PdfArray ocsp = new PdfArray();
PdfArray crl = new PdfArray();
PdfArray cert = new PdfArray();
PdfDictionary vri = new PdfDictionary();
foreach (byte[] b in validated[vkey].crls) {
PdfStream ps = new PdfStream(b);
ps.FlateCompress();
PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
crl.Add(iref);
crls.Add(iref);
}
foreach (byte[] b in validated[vkey].ocsps) {
PdfStream ps = new PdfStream(b);
ps.FlateCompress();
PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
ocsp.Add(iref);
ocsps.Add(iref);
}
foreach (byte[] b in validated[vkey].certs) {
PdfStream ps = new PdfStream(b);
ps.FlateCompress();
PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
cert.Add(iref);
certs.Add(iref);
}
if (ocsp.Size > 0)
vri.Put(PdfName.OCSP, writer.AddToBody(ocsp, false).IndirectReference);
if (crl.Size > 0)
vri.Put(PdfName.CRL, writer.AddToBody(crl, false).IndirectReference);
if (cert.Size > 0)
vri.Put(PdfName.CERT, writer.AddToBody(cert, false).IndirectReference);
vrim.Put(vkey, writer.AddToBody(vri, false).IndirectReference);
}
dss.Put(PdfName.VRI, writer.AddToBody(vrim, false).IndirectReference);
if (ocsps.Size > 0)
dss.Put(PdfName.OCSPS, writer.AddToBody(ocsps, false).IndirectReference);
if (crls.Size > 0)
dss.Put(PdfName.CRLS, writer.AddToBody(crls, false).IndirectReference);
if (certs.Size > 0)
dss.Put(PdfName.CERTS, writer.AddToBody(certs, false).IndirectReference);
catalog.Put(PdfName.DSS, writer.AddToBody(dss, false).IndirectReference);
}
示例13: SetXfa
/**
* Sets the XFA key from a byte array. The old XFA is erased.
* @param xfaData the data
* @param reader the reader
* @param writer the writer
* @throws java.io.IOException on error
*/
public static void SetXfa(byte[] xfaData, PdfReader reader, PdfWriter writer)
{
PdfDictionary af = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
if (af == null) {
return;
}
reader.KillXref(af.Get(PdfName.XFA));
PdfStream str = new PdfStream(xfaData);
str.FlateCompress();
PdfIndirectReference refe = writer.AddToBody(str).IndirectReference;
af.Put(PdfName.XFA, refe);
}
示例14: WriteFont
/** Outputs to the writer the font dictionaries and streams.
* @param writer the writer for this document
* @param ref the font indirect reference
* @param parms several parameters that depend on the font type
* @throws IOException on error
* @throws DocumentException error in generating the object
*/
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms) {
Hashtable longTag = (Hashtable)parms[0];
AddRangeUni(longTag, true, subset);
ArrayList tmp = new ArrayList();
foreach (object o in longTag.Values) {
tmp.Add(o);
}
Object[] metrics = tmp.ToArray();
Array.Sort(metrics, this);
PdfIndirectReference ind_font = null;
PdfObject pobj = null;
PdfIndirectObject obj = null;
PdfIndirectReference cidset = null;
if (writer.PDFXConformance == PdfWriter.PDFA1A || writer.PDFXConformance == PdfWriter.PDFA1B) {
PdfStream stream;
if (metrics.Length == 0) {
stream = new PdfStream(new byte[]{(byte)0x80});
}
else {
int top = ((int[])metrics[metrics.Length - 1])[0];
byte[] bt = new byte[top / 8 + 1];
for (int k = 0; k < metrics.Length; ++k) {
int v = ((int[])metrics[k])[0];
bt[v / 8] |= rotbits[v % 8];
}
stream = new PdfStream(bt);
stream.FlateCompress(compressionLevel);
}
cidset = writer.AddToBody(stream).IndirectReference;
}
// sivan: cff
if (cff) {
byte[] b = ReadCffFont();
if (subset || subsetRanges != null) {
CFFFontSubset cffs = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag);
b = cffs.Process((cffs.GetNames())[0] );
}
pobj = new StreamFont(b, "CIDFontType0C", compressionLevel);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
} else {
byte[] b;
if (subset || directoryOffset != 0) {
TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false);
b = sb.Process();
}
else {
b = GetFullFont();
}
int[] lengths = new int[]{b.Length};
pobj = new StreamFont(b, lengths, compressionLevel);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
}
String subsetPrefix = "";
if (subset)
subsetPrefix = CreateSubsetPrefix();
PdfDictionary dic = GetFontDescriptor(ind_font, subsetPrefix, cidset);
obj = writer.AddToBody(dic);
ind_font = obj.IndirectReference;
pobj = GetCIDFontType2(ind_font, subsetPrefix, metrics);
obj = writer.AddToBody(pobj);
ind_font = obj.IndirectReference;
pobj = GetToUnicode(metrics);
PdfIndirectReference toUnicodeRef = null;
if (pobj != null) {
obj = writer.AddToBody(pobj);
toUnicodeRef = obj.IndirectReference;
}
pobj = GetFontBaseType(ind_font, subsetPrefix, toUnicodeRef);
writer.AddToBody(pobj, piref);
}
示例15: NewPage
/**
* Makes a new page and sends it to the <CODE>PdfWriter</CODE>.
*
* @return a <CODE>bool</CODE>
* @throws DocumentException on error
*/
public override bool NewPage() {
lastElementType = -1;
if (PageEmpty) {
SetNewPageSizeAndMargins();
return false;
}
if (!open || close) {
throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
}
IPdfPageEvent pageEvent = writer.PageEvent;
if (pageEvent != null)
pageEvent.OnEndPage(writer, this);
//Added to inform any listeners that we are moving to a new page (added by David Freels)
base.NewPage();
// the following 2 lines were added by Pelikan Stephan
indentation.imageIndentLeft = 0;
indentation.imageIndentRight = 0;
// we flush the arraylist with recently written lines
FlushLines();
// we prepare the elements of the page dictionary
// [U1] page size and rotation
int rotation = pageSize.Rotation;
// [C10]
if (writer.IsPdfX()) {
if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
if (thisBoxSize.ContainsKey("crop"))
thisBoxSize["trim"] = thisBoxSize["crop"];
else
thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
}
}
// [M1]
pageResources.AddDefaultColorDiff(writer.DefaultColorspace);
if (writer.RgbTransparencyBlending) {
PdfDictionary dcs = new PdfDictionary();
dcs.Put(PdfName.CS, PdfName.DEVICERGB);
pageResources.AddDefaultColorDiff(dcs);
}
PdfDictionary resources = pageResources.Resources;
// we create the page dictionary
PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
page.Put(PdfName.TABS, writer.Tabs);
// we complete the page dictionary
// [C9] if there is XMP data to add: add it
if (xmpMetadata != null) {
PdfStream xmp = new PdfStream(xmpMetadata);
xmp.Put(PdfName.TYPE, PdfName.METADATA);
xmp.Put(PdfName.SUBTYPE, PdfName.XML);
PdfEncryption crypto = writer.Encryption;
if (crypto != null && !crypto.IsMetadataEncrypted()) {
PdfArray ar = new PdfArray();
ar.Add(PdfName.CRYPT);
xmp.Put(PdfName.FILTER, ar);
}
page.Put(PdfName.METADATA, writer.AddToBody(xmp).IndirectReference);
}
// [U3] page actions: transition, duration, additional actions
if (this.transition!=null) {
page.Put(PdfName.TRANS, this.transition.TransitionDictionary);
transition = null;
}
if (this.duration>0) {
page.Put(PdfName.DUR,new PdfNumber(this.duration));
duration = 0;
}
if (pageAA != null) {
page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
pageAA = null;
}
// [U4] we add the thumbs
if (thumb != null) {
page.Put(PdfName.THUMB, thumb);
thumb = null;
}
// [U8] we check if the userunit is defined
if (writer.Userunit > 0f) {
page.Put(PdfName.USERUNIT, new PdfNumber(writer.Userunit));
}
//.........这里部分代码省略.........