當前位置: 首頁>>代碼示例>>C#>>正文


C# Pdf.PdfDictionary類代碼示例

本文整理匯總了C#中PdfSharp.Pdf.PdfDictionary的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary類的具體用法?C# PdfDictionary怎麽用?C# PdfDictionary使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PdfDictionary類屬於PdfSharp.Pdf命名空間,在下文中一共展示了PdfDictionary類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ImageFromDCTDecode

 /// <summary>
 /// Retrieves the specifed dictionary object as an object encoded with DCTDecode filter (JPEG).
 /// </summary>
 /// <param name="dictionary">The dictionary to extract the object from.</param>
 /// <returns>The image retrieve from the dictionary. If not found or an invalid image, then null is returned.</returns>
 private static Image ImageFromDCTDecode(PdfDictionary dictionary)
 {
   // DCTDecode a lossy filter based on the JPEG standard
   // We can just load directly from the stream.
   MemoryStream stream = new MemoryStream(dictionary.Stream.Value);
   return (Bitmap.FromStream(stream));
 }
開發者ID:GorelH,項目名稱:PDFSharp.Extensions,代碼行數:12,代碼來源:PdfDictionaryExtensions.cs

示例2: ExportImage

        static bool ExportImage(PdfDictionary image, ref int count)
        {
            bool ret = false;
            try
            {
                string filter = image.Elements.GetName("/Filter");
            
                switch (filter)
                {
                    case "/DCTDecode":
                        ret = ExportJpegImage(image, ref count);
                        break;
                    /* case "/FlateDecode":
                            ExportAsPngImage(image, ref count);
                            break;*/
                    default:
                        ret = true;
                        break;
                }
            }
            catch (Exception)//in case its an object array so we need first to decompress it
            {
                byte[] stream = image.Stream.Value;

                PdfSharp.Pdf.Filters.FlateDecode aug = new PdfSharp.Pdf.Filters.FlateDecode();
                stream = aug.Decode(stream);
                ret = ExportJpegImage(stream, ref count);
            }

            return ret;
        }
開發者ID:alexisgoncalves,項目名稱:cbr-converter,代碼行數:31,代碼來源:PdfFunctions.cs

示例3: ExportJpegImage

 static void ExportJpegImage(PdfDictionary image, ref int count)
 {
     byte[] stream = image.Stream.Value;
     using (FileStream fs = new FileStream(String.Format("Image{0}.jpg", count++), FileMode.Create, FileAccess.Write))
     {
         fs.Write(stream, 0, stream.Length);
     }
 }
開發者ID:aont,項目名稱:ExportImageFromPDF,代碼行數:8,代碼來源:Program.cs

示例4: PdfContentWriter

 /// <summary>
 /// </summary>
 public PdfContentWriter(DocumentRenderingContext context, PdfDictionary contentDictionary)
 {
   if (!(contentDictionary is IContentStream))
     throw new ArgumentException("contentDictionary must implement IContentStream.");
   this.context = context;
   this.contentDictionary = contentDictionary;
   this.contentStreamDictionary = (IContentStream)contentDictionary;
   this.renderMode = RenderMode.Default;
   //this.colorMode = page.document.Options.ColorMode;
   //this.options = options;
   this.content = new StringBuilder();
   this.graphicsState = new PdfGraphicsState(this);
 }
開發者ID:AnthonyNystrom,項目名稱:Pikling,代碼行數:15,代碼來源:PdfContentWriter.cs

示例5: PdfPage

 internal PdfPage(PdfDictionary dict)
     : base(dict)
 {
     // Set Orientation depending on /Rotate.
     int rotate = Elements.GetInteger(InheritablePageKeys.Rotate);
     if (Math.Abs((rotate / 90)) % 2 == 1)
         _orientation = PageOrientation.Landscape;
 }
開發者ID:Sl0vi,項目名稱:PDFsharp,代碼行數:8,代碼來源:PdfPage.cs

示例6: ExportImage

        static void ExportImage(PdfDictionary image, ref int count)
        {
            string filter = image.Elements.GetName("/Filter");
            switch (filter)
            {
                case "/DCTDecode":
                    ExportJpegImage(image, ref count);
                    break;

                case "/FlateDecode":
                    ExportAsPngImage(image, ref count);
                    break;
            }

        }
開發者ID:alqadasifathi,項目名稱:OfficeTools.Pdf2Image.Word2Image,代碼行數:15,代碼來源:Program.cs

示例7: ExportJpegImage

        static void ExportJpegImage(PdfDictionary image, ref int count)
        {

            // Fortunately JPEG has native support in PDF and exporting an image is just writing the stream to a file.

            byte[] stream = image.Stream.Value;

            FileStream fs = new FileStream(String.Format("F:\\Image{0}.jpeg", count++), FileMode.Create, FileAccess.Write);
            
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(stream);

            bw.Close();

        }
開發者ID:alqadasifathi,項目名稱:OfficeTools.Pdf2Image.Word2Image,代碼行數:16,代碼來源:Program.cs

示例8: PdfCIDFont

    public PdfCIDFont(PdfDocument document, PdfFontDescriptor fontDescriptor, byte[] fontData)
      : base(document)
    {
      Elements.SetName(Keys.Type, "/Font");
      Elements.SetName(Keys.Subtype, "/CIDFontType2");
      PdfDictionary cid = new PdfDictionary();
      cid.Elements.SetString("/Ordering", "Identity");
      cid.Elements.SetString("/Registry", "Adobe");
      cid.Elements.SetInteger("/Supplement", 0);
      Elements.SetValue(Keys.CIDSystemInfo, cid);

      this.fontDescriptor = fontDescriptor;
      Owner.irefTable.Add(fontDescriptor);
      Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

      FontEncoding = PdfFontEncoding.Unicode;
      FontEmbedding = PdfFontEmbedding.Always;
    }
開發者ID:DavidS,項目名稱:MigraDoc,代碼行數:18,代碼來源:PdfCIDFont.cs

示例9: ExportImage

        static void ExportImage(PdfDictionary image, ref int count)
        {
            string filter = image.Elements.GetName(PdfImage.Keys.Filter);
            switch (filter)
            {
                case "/DCTDecode":
                    ExportJpegImage(image, ref count);
                    break;

                case "":
                case "/FlateDecode":
                    ExportUnfilterableImage(image, ref count);
                    break;

                case "/CCITTFaxDecode":
                case "/RunLengthDecode,":
                default:
                    throw new NotSupportedException();
            }
        }
開發者ID:aont,項目名稱:ExportImageFromPDF,代碼行數:20,代碼來源:Program.cs

示例10: CreateDictionary

 PdfDictionary CreateDictionary(Type type, PdfDictionary oldDictionary)
 {
   ConstructorInfo ctorInfo;
   PdfDictionary dict;
   if (oldDictionary == null)
   {
     // Use contstructor with signature 'Ctor(PdfDocument owner)'.
     ctorInfo = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
       null, new Type[] { typeof(PdfDocument) }, null);
     Debug.Assert(ctorInfo != null, "No appropriate constructor found for type: " + type.Name);
     dict = ctorInfo.Invoke(new object[] { this.owner.Owner }) as PdfDictionary;
   }
   else
   {
     // Use contstructor with signature 'Ctor(PdfDictionary dict)'.
     ctorInfo = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
       null, new Type[] { typeof(PdfDictionary) }, null);
     Debug.Assert(ctorInfo != null, "No appropriate constructor found for type: " + type.Name);
     dict = ctorInfo.Invoke(new object[] { oldDictionary }) as PdfDictionary;
   }
   return dict;
 }
開發者ID:AnthonyNystrom,項目名稱:Pikling,代碼行數:22,代碼來源:PdfDictionary.cs

示例11: InheritValues

        /// <summary>
        /// Add all inheritable values from the specified page to the specified values structure.
        /// </summary>
        internal static void InheritValues(PdfDictionary page, ref InheritedValues values)
        {
            PdfItem item = page.Elements[InheritablePageKeys.Resources];
            if (item != null)
            {
                PdfReference reference = item as PdfReference;
                if (reference != null)
                    values.Resources = (PdfDictionary)(reference.Value);
                else
                    values.Resources = (PdfDictionary)item;
            }

            item = page.Elements[InheritablePageKeys.MediaBox];
            if (item != null)
                values.MediaBox = new PdfRectangle(item);

            item = page.Elements[InheritablePageKeys.CropBox];
            if (item != null)
                values.CropBox = new PdfRectangle(item);

            item = page.Elements[InheritablePageKeys.Rotate];
            if (item != null)
            {
                if (item is PdfReference)
                    item = ((PdfReference)item).Value;
                values.Rotate = (PdfInteger)item;
            }
        }
開發者ID:Sl0vi,項目名稱:PDFsharp,代碼行數:31,代碼來源:PdfPage.cs

示例12: PdfOutline

 /// <summary>
 /// Initializes a new instance from an existing dictionary. Used for object type transformation.
 /// </summary>
 public PdfOutline(PdfDictionary dict)
     : base(dict)
 {
     Initialize();
 }
開發者ID:Core2D,項目名稱:PDFsharp,代碼行數:8,代碼來源:PdfOutline.cs

示例13: PdfAnnotation

 /// <summary>
 /// Initializes a new instance of the <see cref="PdfAnnotation"/> class.
 /// </summary>
 internal PdfAnnotation(PdfDictionary dict)
   : base(dict)
 {
 }
開發者ID:bossaia,項目名稱:alexandrialibrary,代碼行數:7,代碼來源:PdfAnnotation.cs

示例14: Initialize

      /// <summary>
      /// Initializes the item based on the specified PdfDictionary.
      /// </summary>
      /// <param name="dictionary">The dictionary to use for initialization.</param>
      private void Initialize(PdfDictionary dictionary)
      {
        if (dictionary == null) throw new ArgumentNullException("dictionary", "The PDF dictionary item to extract image meta data from was null.");
        if (!dictionary.IsImage()) throw new ArgumentException("The specified dictionary does not represent an image.", "dictionary");

        Height = dictionary.Elements.GetInteger("/Height");
        Width = dictionary.Elements.GetInteger("/Width");
        BitsPerPixel = dictionary.Elements.GetInteger("/BitsPerComponent");
        Length = dictionary.Elements.GetInteger("/Length");

        PdfItem colorSpace = null;
        if (dictionary.Elements.TryGetValue("/ColorSpace", out colorSpace)) {
          ColorSpace = PdfDictionaryColorSpace.Parse(colorSpace);
        }
        else ColorSpace = new PdfRGBColorSpace(); // Default to RGB Color Space
      }
開發者ID:GorelH,項目名稱:PDFSharp.Extensions,代碼行數:20,代碼來源:PdfDictionaryExtensions.cs

示例15: ImageFromFlateDecode

    /// <summary>
    /// Retrieves the specifed dictionary object as an object encoded with FlateDecode filter.
    /// </summary>
    /// <remarks>
    /// FlateDecode a commonly used filter based on the zlib/deflate algorithm (a.k.a. gzip, but not zip) 
    /// defined in RFC 1950 and RFC 1951; introduced in PDF 1.2; it can use one of two groups of predictor 
    /// functions for more compact zlib/deflate compression: Predictor 2 from the TIFF 6.0 specification 
    /// and predictors (filters) from the PNG specification (RFC 2083)
    /// </remarks>
    /// <param name="dictionary">The dictionary to extract the object from.</param>
    /// <returns>The image retrieve from the dictionary. If not found or an invalid image, then null is returned.</returns>
    private static Image ImageFromFlateDecode(PdfDictionary dictionary)
    {
      PdfDictionaryImageMetaData imageData = new PdfDictionaryImageMetaData(dictionary);

      // FlateDecode can be either indexed or a traditional ColorSpace
      bool isIndexed = imageData.ColorSpace.IsIndexed;
      PixelFormat format = GetPixelFormat(imageData.ColorSpace, imageData.BitsPerPixel, isIndexed);

      Bitmap bitmap = new Bitmap(imageData.Width, imageData.Height, format);

      // If indexed, retrieve and assign the color palette for the item.
      if ((isIndexed) && (imageData.ColorSpace.IsRGB)) bitmap.Palette = ((PdfIndexedRGBColorSpace) imageData.ColorSpace).ToColorPalette();
      else if (imageData.ColorSpace is PdfGrayColorSpace) bitmap.Palette = ((PdfGrayColorSpace)imageData.ColorSpace).ToColorPalette(imageData.BitsPerPixel);

      // If not an indexed color, the .NET image component expects pixels to be in BGR order. However, our PDF stream is in RGB order.
      byte[] stream = (format == PixelFormat.Format24bppRgb) ? ConvertRGBStreamToBGR(dictionary.Stream.UnfilteredValue) : dictionary.Stream.UnfilteredValue;

      BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, imageData.Width, imageData.Height), ImageLockMode.WriteOnly, format);
      // We can't just copy the bytes directly; the BitmapData .NET class has a stride (padding) associated with it. 
      int bitsPerPixel = ((((int)format >> 8) & 0xFF));
      int length = (int)Math.Ceiling(bitmapData.Width * bitsPerPixel / 8.0);
      for (int y = 0, height = bitmapData.Height; y < height; y++) {
        int offset = y * length;
        Marshal.Copy(stream, offset, bitmapData.Scan0 + (y * bitmapData.Stride), length);
      }
      bitmap.UnlockBits(bitmapData);

      return (bitmap);
    }
開發者ID:GorelH,項目名稱:PDFSharp.Extensions,代碼行數:40,代碼來源:PdfDictionaryExtensions.cs


注:本文中的PdfSharp.Pdf.PdfDictionary類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。