本文整理匯總了C#中iTextSharp.text.pdf.PdfStream.FlateCompress方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfStream.FlateCompress方法的具體用法?C# PdfStream.FlateCompress怎麽用?C# PdfStream.FlateCompress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfStream
的用法示例。
在下文中一共展示了PdfStream.FlateCompress方法的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: AlterContents
virtual internal protected void AlterContents() {
foreach (PageStamp ps in pagesToContent.Values) {
PdfDictionary pageN = ps.pageN;
MarkUsed(pageN);
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 = new PdfArray((PdfArray)content);
pageN.Put(PdfName.CONTENTS, ar);
}
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 (ps.under != null) {
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(ps.under.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
}
if (ps.over != null)
out_p.Append(PdfContents.SAVESTATE);
PdfStream stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.AddFirst(AddToBody(stream).IndirectReference);
out_p.Reset();
if (ps.over != null) {
out_p.Append(' ');
out_p.Append(PdfContents.RESTORESTATE);
ByteBuffer buf = ps.over.InternalBuffer;
out_p.Append(buf.Buffer, 0, ps.replacePoint);
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(buf.Buffer, ps.replacePoint, buf.Size - ps.replacePoint);
out_p.Append(PdfContents.RESTORESTATE);
stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.Add(AddToBody(stream).IndirectReference);
}
AlterResources(ps);
}
}
示例5: 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);
}
示例6: WriteFont
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams)
{
if (this.writer != writer)
throw new ArgumentException(MessageLocalization.GetComposedMessage("type3.font.used.with.the.wrong.pdfwriter"));
// Get first & lastchar ...
int firstChar = 0;
while( firstChar < usedSlot.Length && !usedSlot[firstChar] ) firstChar++;
if ( firstChar == usedSlot.Length ) {
throw new DocumentException(MessageLocalization.GetComposedMessage("no.glyphs.defined.for.type3.font"));
}
int lastChar = usedSlot.Length - 1;
while( lastChar >= firstChar && !usedSlot[lastChar] ) lastChar--;
int[] widths = new int[lastChar - firstChar + 1];
int[] invOrd = new int[lastChar - firstChar + 1];
int invOrdIndx = 0, w = 0;
for( int u = firstChar; u<=lastChar; u++, w++ ) {
if ( usedSlot[u] ) {
invOrd[invOrdIndx++] = u;
widths[w] = widths3[u];
}
}
PdfArray diffs = new PdfArray();
PdfDictionary charprocs = new PdfDictionary();
int last = -1;
for (int k = 0; k < invOrdIndx; ++k) {
int c = invOrd[k];
if (c > last) {
last = c;
diffs.Add(new PdfNumber(last));
}
++last;
int c2 = invOrd[k];
String s = GlyphList.UnicodeToName(c2);
if (s == null)
s = "a" + c2;
PdfName n = new PdfName(s);
diffs.Add(n);
Type3Glyph glyph;
char2glyph.TryGetValue((char)c2, out glyph);
PdfStream stream = new PdfStream(glyph.ToPdf(null));
stream.FlateCompress(compressionLevel);
PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference;
charprocs.Put(n, refp);
}
PdfDictionary font = new PdfDictionary(PdfName.FONT);
font.Put(PdfName.SUBTYPE, PdfName.TYPE3);
if (colorized)
font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0));
else
font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury));
font.Put(PdfName.FONTMATRIX, new PdfArray(new float[]{0.001f, 0, 0, 0.001f, 0, 0}));
font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference);
PdfDictionary encoding = new PdfDictionary();
encoding.Put(PdfName.DIFFERENCES, diffs);
font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference);
font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar));
font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar));
font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference);
if (pageResources.HasResources())
font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference);
writer.AddToBody(font, piRef);
}
示例7: 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);
}
示例8: WriteFont
internal override void WriteFont(PdfWriter writer, PdfIndirectReference piRef, Object[] oParams)
{
if (this.writer != writer)
throw new ArgumentException("Type3 font used with the wrong PdfWriter");
if (char2byte.Size != widths3.Size)
throw new DocumentException("Not all the glyphs in the Type3 font are defined");
IntHashtable inv = new IntHashtable();
for (IntHashtable.IntHashtableIterator it = char2byte.GetEntryIterator(); it.HasNext();) {
IntHashtable.IntHashtableEntry entry = it.Next();
inv[entry.Value] = entry.Key;
}
int[] invOrd = inv.ToOrderedKeys();
int firstChar = invOrd[0];
int lastChar = invOrd[invOrd.Length - 1];
int[] widths = new int[lastChar - firstChar + 1];
for (int k = 0; k < widths.Length; ++k) {
if (inv.ContainsKey(k + firstChar))
widths[k] = widths3[inv[k + firstChar]];
}
PdfArray diffs = new PdfArray();
PdfDictionary charprocs = new PdfDictionary();
int last = -1;
for (int k = 0; k < invOrd.Length; ++k) {
int c = invOrd[k];
if (c > last) {
last = c;
diffs.Add(new PdfNumber(last));
}
++last;
int c2 = inv[c];
String s = GlyphList.UnicodeToName(c2);
if (s == null)
s = "a" + c2;
PdfName n = new PdfName(s);
diffs.Add(n);
Type3Glyph glyph = (Type3Glyph)char2glyph[(char)c2];
PdfStream stream = new PdfStream(glyph.ToPdf(null));
stream.FlateCompress();
PdfIndirectReference refp = writer.AddToBody(stream).IndirectReference;
charprocs.Put(n, refp);
}
PdfDictionary font = new PdfDictionary(PdfName.FONT);
font.Put(PdfName.SUBTYPE, PdfName.TYPE3);
if (colorized)
font.Put(PdfName.FONTBBOX, new PdfRectangle(0, 0, 0, 0));
else
font.Put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury));
font.Put(PdfName.FONTMATRIX, new PdfArray(new float[]{0.001f, 0, 0, 0.001f, 0, 0}));
font.Put(PdfName.CHARPROCS, writer.AddToBody(charprocs).IndirectReference);
PdfDictionary encoding = new PdfDictionary();
encoding.Put(PdfName.DIFFERENCES, diffs);
font.Put(PdfName.ENCODING, writer.AddToBody(encoding).IndirectReference);
font.Put(PdfName.FIRSTCHAR, new PdfNumber(firstChar));
font.Put(PdfName.LASTCHAR, new PdfNumber(lastChar));
font.Put(PdfName.WIDTHS, writer.AddToBody(new PdfArray(widths)).IndirectReference);
if (pageResources.HasResources())
font.Put(PdfName.RESOURCES, writer.AddToBody(pageResources.Resources).IndirectReference);
writer.AddToBody(font, piRef);
}
示例9: SetXfa
/**
* Sets the XFA key from a byte array. The old XFA is erased.
* @param form the data
* @param reader the reader
* @param writer the writer
* @throws java.io.IOException on error
*/
public static void SetXfa(XfaForm form, PdfReader reader, PdfWriter writer)
{
PdfDictionary af = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
if (af == null) {
return;
}
PdfObject xfa = GetXfaObject(reader);
if (xfa.IsArray()) {
PdfArray ar = (PdfArray)xfa;
int t = -1;
int d = -1;
for (int k = 0; k < ar.Size; k += 2) {
PdfString s = ar.GetAsString(k);
if ("template".Equals(s.ToString())) {
t = k + 1;
}
if ("datasets".Equals(s.ToString())) {
d = k + 1;
}
}
if (t > -1 && d > -1) {
reader.KillXref(ar.GetAsIndirectObject(t));
reader.KillXref(ar.GetAsIndirectObject(d));
PdfStream tStream = new PdfStream(SerializeDoc(form.templateNode));
tStream.FlateCompress(writer.CompressionLevel);
ar[t] = writer.AddToBody(tStream).IndirectReference;
PdfStream dStream = new PdfStream(SerializeDoc(form.datasetsNode));
dStream.FlateCompress(writer.CompressionLevel);
ar[d] = writer.AddToBody(dStream).IndirectReference;
af.Put(PdfName.XFA, new PdfArray(ar));
return;
}
}
reader.KillXref(af.Get(PdfName.XFA));
PdfStream str = new PdfStream(SerializeDoc(form.domDocument));
str.FlateCompress(writer.CompressionLevel);
PdfIndirectReference refe = writer.AddToBody(str).IndirectReference;
af.Put(PdfName.XFA, refe);
}
示例10: WriteCrossReferenceTable
/**
* Returns the CrossReferenceTable of the <CODE>Body</CODE>.
* @param os
* @param root
* @param info
* @param encryption
* @param fileID
* @param prevxref
* @throws IOException
*/
internal void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref)
{
int refNumber = 0;
if (writer.FullCompression) {
FlushObjStm();
refNumber = IndirectReferenceNumber;
xrefs[new PdfCrossReference(refNumber, position)] = null;
}
PdfCrossReference entry = (PdfCrossReference)((DictionaryEntry)xrefs.Begin.Current).Key;
int first = entry.Refnum;
int len = 0;
ArrayList sections = new ArrayList();
for (k_Iterator i = xrefs.Begin.Clone(); i != xrefs.End; i.Next()) {
entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
if (first + len == entry.Refnum)
++len;
else {
sections.Add(first);
sections.Add(len);
first = entry.Refnum;
len = 1;
}
}
sections.Add(first);
sections.Add(len);
if (writer.FullCompression) {
int mid = 4;
uint mask = 0xff000000;
for (; mid > 1; --mid) {
if ((mask & position) != 0)
break;
mask >>= 8;
}
ByteBuffer buf = new ByteBuffer();
for (k_Iterator i = xrefs.Begin.Clone(); i != xrefs.End; i.Next()) {
entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
entry.ToPdf(mid, buf);
}
PdfStream xr = new PdfStream(buf.ToByteArray());
buf = null;
xr.FlateCompress();
xr.Put(PdfName.SIZE, new PdfNumber(Size));
xr.Put(PdfName.ROOT, root);
if (info != null) {
xr.Put(PdfName.INFO, info);
}
if (encryption != null)
xr.Put(PdfName.ENCRYPT, encryption);
if (fileID != null)
xr.Put(PdfName.ID, fileID);
xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2}));
xr.Put(PdfName.TYPE, PdfName.XREF);
PdfArray idx = new PdfArray();
for (int k = 0; k < sections.Count; ++k)
idx.Add(new PdfNumber((int)sections[k]));
xr.Put(PdfName.INDEX, idx);
if (prevxref > 0)
xr.Put(PdfName.PREV, new PdfNumber(prevxref));
PdfEncryption enc = writer.crypto;
writer.crypto = null;
PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer);
indirect.WriteTo(writer.Os);
writer.crypto = enc;
}
else {
byte[] tmp = GetISOBytes("xref\n");
os.Write(tmp, 0, tmp.Length);
k_Iterator i = xrefs.Begin.Clone();
for (int k = 0; k < sections.Count; k += 2) {
first = (int)sections[k];
len = (int)sections[k + 1];
tmp = GetISOBytes(first.ToString());
os.Write(tmp, 0, tmp.Length);
os.WriteByte((byte)' ');
tmp = GetISOBytes(len.ToString());
os.Write(tmp, 0, tmp.Length);
os.WriteByte((byte)'\n');
while (len-- > 0) {
entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
entry.ToPdf(os);
i.Next();
}
}
}
}
示例11: SetOutputIntents
// [C11] Output intents
/**
* Sets the values of the output intent dictionary. Null values are allowed to
* suppress any key.
* @param outputConditionIdentifier a value
* @param outputCondition a value
* @param registryName a value
* @param info a value
* @param destOutputProfile a value
* @throws IOException on error
*/
public void SetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte[] destOutputProfile)
{
PdfDictionary outa = ExtraCatalog; //force the creation
outa = new PdfDictionary(PdfName.OUTPUTINTENT);
if (outputCondition != null)
outa.Put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE));
if (outputConditionIdentifier != null)
outa.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE));
if (registryName != null)
outa.Put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE));
if (info != null)
outa.Put(PdfName.INFO, new PdfString(info, PdfObject.TEXT_UNICODE));
if (destOutputProfile != null) {
PdfStream stream = new PdfStream(destOutputProfile);
stream.FlateCompress();
outa.Put(PdfName.DESTOUTPUTPROFILE, AddToBody(stream).IndirectReference);
}
outa.Put(PdfName.S, PdfName.GTS_PDFX);
extraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outa));
}
示例12: GetToUnicode
/** Creates a ToUnicode CMap to allow copy and paste from Acrobat.
* @param metrics metrics[0] contains the glyph index and metrics[2]
* contains the Unicode code
* @throws DocumentException on error
* @return the stream representing this CMap or <CODE>null</CODE>
*/
private PdfStream GetToUnicode(Object[] metrics)
{
if (metrics.Length == 0)
return null;
StringBuilder buf = new StringBuilder(
"/CIDInit /ProcSet findresource begin\n" +
"12 dict begin\n" +
"begincmap\n" +
"/CIDSystemInfo\n" +
"<< /Registry (Adobe)\n" +
"/Ordering (UCS)\n" +
"/Supplement 0\n" +
">> def\n" +
"/CMapName /Adobe-Identity-UCS def\n" +
"/CMapType 2 def\n" +
"1 begincodespacerange\n" +
"<0000><FFFF>\n" +
"endcodespacerange\n");
int size = 0;
for (int k = 0; k < metrics.Length; ++k) {
if (size == 0) {
if (k != 0) {
buf.Append("endbfrange\n");
}
size = Math.Min(100, metrics.Length - k);
buf.Append(size).Append(" beginbfrange\n");
}
--size;
int[] metric = (int[])metrics[k];
string fromTo = ToHex(metric[0]);
buf.Append(fromTo).Append(fromTo).Append(ToHex(metric[2])).Append('\n');
}
buf.Append(
"endbfrange\n" +
"endcmap\n" +
"CMapName currentdict /CMap defineresource pop\n" +
"end end\n");
string s = buf.ToString();
PdfStream stream = new PdfStream(PdfEncodings.ConvertToBytes(s, null));
stream.FlateCompress();
return stream;
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}