本文整理汇总了C#中PdfDictionary.CreateStream方法的典型用法代码示例。如果您正苦于以下问题:C# PdfDictionary.CreateStream方法的具体用法?C# PdfDictionary.CreateStream怎么用?C# PdfDictionary.CreateStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.CreateStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareForSave
/// <summary>
/// Prepares the object to get saved.
/// </summary>
internal override void PrepareForSave()
{
base.PrepareForSave();
if (FontEmbedding == PdfFontEmbedding.Always || FontEmbedding == PdfFontEmbedding.Automatic)
{
FontData subSet = this.fontDescriptor.descriptor.fontData.CreateFontSubSet(this.cmapInfo.GlyphIndices, false);
byte[] fontData = subSet.Data;
#if DEBUG_
TrueTypeFontSubSet fss = new TrueTypeFontSubSet("", this.cmapInfo.descriptor.fontData, this.cmapInfo.GlyphIndices, 0, true, false);
byte[] fontSubSet = fss.Process();
fss.CompareBytes(fontSubSet, fontProgram);
#endif
PdfDictionary fontStream = new PdfDictionary(this.Owner);
this.Owner.Internals.AddObject(fontStream);
this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;
fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
if (!this.Owner.Options.NoCompression)
{
fontData = Filtering.FlateDecode.Encode(fontData);
fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
}
fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
fontStream.CreateStream(fontData);
}
//if (this.cmapInfo == null)
//{
FirstChar = 0;
LastChar = 255;
PdfArray width = Widths;
//width.Elements.Clear();
for (int idx = 0; idx < 256; idx++)
width.Elements.Add(new PdfInteger(this.fontDescriptor.descriptor.widths[idx]));
//}
//else
//{
// FirstChar = (char)Math.Min(this.cmapInfo.MinChar, 255u);
// LastChar = (char)Math.Min(this.cmapInfo.MaxChar, 255u);
// PdfArray width = Widths;
// Debug.Assert(width.Elements.Count == 0);
// //width.Elements.Clear();
// for (int idx = FirstChar; idx <= LastChar; idx++)
// {
// int charWidth = 0;
// if (this.cmapInfo.Contains((char)idx))
// charWidth = this.fontDescriptor.descriptor.widths[idx];
// width.Elements.Add(new PdfInteger(charWidth));
// }
//}
}
示例2: PrepareForSave
/// <summary>
/// Prepares the object to get saved.
/// </summary>
internal override void PrepareForSave()
{
base.PrepareForSave();
#if DEBUG_
if (FontDescriptor._descriptor.FontFace.loca == null)
{
GetType();
}
#endif
// CID fonts must be always embedded. PDFsharp embedds automatically a subset.
OpenTypeFontface subSet = null;
if (FontDescriptor._descriptor.FontFace.loca == null)
subSet = FontDescriptor._descriptor.FontFace;
else
subSet = FontDescriptor._descriptor.FontFace.CreateFontSubSet(_cmapInfo.GlyphIndices, true);
byte[] fontData = subSet.FontSource.Bytes;
PdfDictionary fontStream = new PdfDictionary(Owner);
Owner.Internals.AddObject(fontStream);
FontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;
fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
if (!Owner.Options.NoCompression)
{
fontData = Filtering.FlateDecode.Encode(fontData, _document.Options.FlateEncodeMode);
fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
}
fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
fontStream.CreateStream(fontData);
}
示例3: ReadIndexedMemoryBitmap
//.........这里部分代码省略.........
isBitonal = 1;
if (paletteColors == 2)
{
if (paletteData[0] == 0 &&
paletteData[1] == 0 &&
paletteData[2] == 0 &&
paletteData[3] == 255 &&
paletteData[4] == 255 &&
paletteData[5] == 255)
isBitonal = 1; // Black on white
if (paletteData[5] == 0 &&
paletteData[4] == 0 &&
paletteData[3] == 0 &&
paletteData[2] == 255 &&
paletteData[1] == 255 &&
paletteData[0] == 255)
isBitonal = -1; // White on black
}
}
// NYI: (no sample found where this was required)
// if (segmentedColorMask = true)
// { ... }
FlateDecode fd = new FlateDecode();
PdfDictionary colorPalette = null;
if (isBitonal == 0 && !isGray)
{
colorPalette = new PdfDictionary(this.document);
byte[] packedPaletteData = paletteData.Length >= 48 ? fd.Encode(paletteData) : null; // don't compress small palettes
if (packedPaletteData != null && packedPaletteData.Length + 20 < paletteData.Length) // +20: compensate for the overhead (estimated value)
{
// Create compressed color palette:
colorPalette.CreateStream(packedPaletteData);
colorPalette.Elements[Keys.Length] = new PdfInteger(packedPaletteData.Length);
colorPalette.Elements[Keys.Filter] = new PdfName("/FlateDecode");
}
else
{
// Create uncompressed color palette:
colorPalette.CreateStream(paletteData);
colorPalette.Elements[Keys.Length] = new PdfInteger(paletteData.Length);
}
Owner.irefTable.Add(colorPalette);
}
bool isFaxEncoding = false;
byte[] imageData = new byte[((width * bits + 7) / 8) * height];
byte[] imageDataFax = null;
int k = 0;
if (bits == 1)
{
// TODO: flag/option?
// We try Group 3 1D and Group 4 (2D) encoding here and keep the smaller byte array.
//byte[] temp = new byte[imageData.Length];
//int ccittSize = DoFaxEncoding(ref temp, imageBits, (uint)bytesFileOffset, (uint)width, (uint)height);
// It seems that Group 3 2D encoding never beats both other encodings, therefore we don't call it here.
//byte[] temp2D = new byte[imageData.Length];
//uint dpiY = (uint)image.VerticalResolution;
//uint kTmp = 0;
//int ccittSize2D = DoFaxEncoding2D((uint)bytesFileOffset, ref temp2D, imageBits, (uint)width, (uint)height, dpiY, out kTmp);
//k = (int) kTmp;
示例4: CreateIndexedMemoryBitmap
//.........这里部分代码省略.........
imageDataFaxCompressed.Length < imageDataCompressed.Length))
{
// /CCITTFaxDecode creates the smaller file (with or without /FlateDecode):
usesCcittEncoding = true;
if (idb.LengthFax < imageDataCompressed.Length)
{
Stream = new PdfStream(idb.DataFax, this);
Elements[PdfStream.Keys.Length] = new PdfInteger(idb.LengthFax);
Elements[PdfStream.Keys.Filter] = new PdfName("/CCITTFaxDecode");
//PdfArray array2 = new PdfArray(_document);
PdfDictionary dictionary = new PdfDictionary();
if (idb.K != 0)
dictionary.Elements.Add("/K", new PdfInteger(idb.K));
if (idb.IsBitonal < 0)
dictionary.Elements.Add("/BlackIs1", new PdfBoolean(true));
dictionary.Elements.Add("/EndOfBlock", new PdfBoolean(false));
dictionary.Elements.Add("/Columns", new PdfInteger((int)ii.Width));
dictionary.Elements.Add("/Rows", new PdfInteger((int)ii.Height));
//array2.Elements.Add(dictionary);
Elements[PdfStream.Keys.DecodeParms] = dictionary; // array2;
}
else
{
Stream = new PdfStream(imageDataFaxCompressed, this);
Elements[PdfStream.Keys.Length] = new PdfInteger(imageDataFaxCompressed.Length);
PdfArray arrayFilters = new PdfArray(_document);
arrayFilters.Elements.Add(new PdfName("/FlateDecode"));
arrayFilters.Elements.Add(new PdfName("/CCITTFaxDecode"));
Elements[PdfStream.Keys.Filter] = arrayFilters;
PdfArray arrayDecodeParms = new PdfArray(_document);
PdfDictionary dictFlateDecodeParms = new PdfDictionary();
//dictFlateDecodeParms.Elements.Add("/Columns", new PdfInteger(1));
PdfDictionary dictCcittFaxDecodeParms = new PdfDictionary();
if (idb.K != 0)
dictCcittFaxDecodeParms.Elements.Add("/K", new PdfInteger(idb.K));
if (idb.IsBitonal < 0)
dictCcittFaxDecodeParms.Elements.Add("/BlackIs1", new PdfBoolean(true));
dictCcittFaxDecodeParms.Elements.Add("/EndOfBlock", new PdfBoolean(false));
dictCcittFaxDecodeParms.Elements.Add("/Columns", new PdfInteger((int)ii.Width));
dictCcittFaxDecodeParms.Elements.Add("/Rows", new PdfInteger((int)ii.Height));
arrayDecodeParms.Elements.Add(dictFlateDecodeParms); // How to add the "null object"?
arrayDecodeParms.Elements.Add(dictCcittFaxDecodeParms);
Elements[PdfStream.Keys.DecodeParms] = arrayDecodeParms;
}
}
else
{
// /FlateDecode creates the smaller file (or no monochrome bitmap):
Stream = new PdfStream(imageDataCompressed, this);
Elements[PdfStream.Keys.Length] = new PdfInteger(imageDataCompressed.Length);
Elements[PdfStream.Keys.Filter] = new PdfName("/FlateDecode");
}
Elements[Keys.Width] = new PdfInteger((int)ii.Width);
Elements[Keys.Height] = new PdfInteger((int)ii.Height);
Elements[Keys.BitsPerComponent] = new PdfInteger(bits);
// TODO: CMYK
// CCITT encoding: we need color palette for isBitonal == 0
// FlateDecode: we need color palette for isBitonal <= 0 unless we have grayscales
if ((usesCcittEncoding && idb.IsBitonal == 0) ||
(!usesCcittEncoding && idb.IsBitonal <= 0 && !idb.IsGray))
{
PdfDictionary colorPalette = null;
colorPalette = new PdfDictionary(_document);
byte[] packedPaletteData = idb.PaletteDataLength >= 48 ? fd.Encode(idb.PaletteData, _document.Options.FlateEncodeMode) : null; // don't compress small palettes
if (packedPaletteData != null && packedPaletteData.Length + 20 < idb.PaletteDataLength) // +20: compensate for the overhead (estimated value)
{
// Create compressed color palette:
colorPalette.CreateStream(packedPaletteData);
colorPalette.Elements[PdfStream.Keys.Length] = new PdfInteger(packedPaletteData.Length);
colorPalette.Elements[PdfStream.Keys.Filter] = new PdfName("/FlateDecode");
}
else
{
// Create uncompressed color palette:
colorPalette.CreateStream(idb.PaletteData);
colorPalette.Elements[PdfStream.Keys.Length] = new PdfInteger(idb.PaletteDataLength);
}
Owner._irefTable.Add(colorPalette);
PdfArray arrayColorSpace = new PdfArray(_document);
arrayColorSpace.Elements.Add(new PdfName("/Indexed"));
arrayColorSpace.Elements.Add(new PdfName("/DeviceRGB"));
arrayColorSpace.Elements.Add(new PdfInteger((int)ii.ColorsUsed - 1));
arrayColorSpace.Elements.Add(colorPalette.Reference);
Elements[Keys.ColorSpace] = arrayColorSpace;
}
else
{
Elements[Keys.ColorSpace] = new PdfName("/DeviceGray");
}
if (_image.Interpolate)
Elements[Keys.Interpolate] = PdfBoolean.True;
}
}
示例5: ReadIndexedMemoryBitmap
//.........这里部分代码省略.........
MonochromeMask mask = new MonochromeMask(width, height);
byte[] paletteData = new byte[3 * paletteColors];
for (int color = 0; color < paletteColors; ++color)
{
paletteData[3 * color] = imageBits[bytesColorPaletteOffset + 4 * color + 2];
paletteData[3 * color + 1] = imageBits[bytesColorPaletteOffset + 4 * color + 1];
paletteData[3 * color + 2] = imageBits[bytesColorPaletteOffset + 4 * color + 0];
if (imageBits[bytesColorPaletteOffset + 4 * color + 3] < 128)
{
// We treat this as transparency:
if (firstMaskColor == -1)
firstMaskColor = color;
if (lastMaskColor == -1 || lastMaskColor == color - 1)
lastMaskColor = color;
if (lastMaskColor != color)
segmentedColorMask = true;
}
else
{
// We treat this as opacity:
}
}
// NYI: (no sample found where this was required)
// if (segmentedColorMask = true)
// { ... }
FlateDecode fd = new FlateDecode();
PdfDictionary colorPalette = new PdfDictionary(this.document);
// TODO: decide at run-time if compression makes sense
#if false
// Create uncompressed color palette:
colorPalette.CreateStream(paletteData);
colorPalette.Elements[Keys.Length] = new PdfInteger(paletteData.Length);
#else
// Create compressed color palette:
byte[] packedPaletteData = fd.Encode(paletteData);
colorPalette.CreateStream(packedPaletteData);
colorPalette.Elements[Keys.Length] = new PdfInteger(packedPaletteData.Length);
colorPalette.Elements[Keys.Filter] = new PdfName("/FlateDecode");
#endif
this.Owner.irefTable.Add(colorPalette);
byte[] imageData = new byte[1 * width * height];
int bytesOffsetRead = 0;
if (bits == 8 || bits == 4 || bits == 1)
{
int bytesPerLine = (width * bits + 7) / 8;
for (int y = 0; y < height; ++y)
{
mask.StartLine(y);
int bytesOffsetWrite = (height - 1 - y) * ((width * bits + 7) / 8);
for (int x = 0; x < bytesPerLine; ++x)
{
imageData[bytesOffsetWrite] = imageBits[bytesFileOffset + bytesOffsetRead];
if (firstMaskColor != -1)
{
int n = imageBits[bytesFileOffset + bytesOffsetRead];
if (bits == 8)
{
// TODO???: segmentedColorMask == true => falsche Maske NYI
mask.AddPel((n >= firstMaskColor) && (n <= lastMaskColor));
}
else if (bits == 4)
示例6: PrepareForSave
/// <summary>
/// Prepares the object to get saved.
/// </summary>
internal override void PrepareForSave()
{
base.PrepareForSave();
// Fonts are always embedded.
OpenTypeFontface subSet = FontDescriptor._descriptor.FontFace.CreateFontSubSet(_cmapInfo.GlyphIndices, false);
byte[] fontData = subSet.FontSource.Bytes;
PdfDictionary fontStream = new PdfDictionary(Owner);
Owner.Internals.AddObject(fontStream);
FontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile2] = fontStream.Reference;
fontStream.Elements["/Length1"] = new PdfInteger(fontData.Length);
if (!Owner.Options.NoCompression)
{
fontData = Filtering.FlateDecode.Encode(fontData, _document.Options.FlateEncodeMode);
fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
}
fontStream.Elements["/Length"] = new PdfInteger(fontData.Length);
fontStream.CreateStream(fontData);
FirstChar = 0;
LastChar = 255;
PdfArray width = Widths;
//width.Elements.Clear();
for (int idx = 0; idx < 256; idx++)
width.Elements.Add(new PdfInteger(FontDescriptor._descriptor.Widths[idx]));
}