Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. ImageOptions for GetPages() method

    You can get image representation of pages of your PDF document by using GetPages method of AnnotationImageHandler class.

    Code Block
    List<PageImage> GetPages(Stream fileStream, ImageOptions options)
    List<PageImage> GetPages(string guid, ImageOptions options)
    List<PageImage> GetPages(string guid)

    Parameter

    Type

    Description

    CountPagesToConvert

    int

    Determines count of pages to convert. PageNumber should be greater than 0.

    PageNumber

    int

    Determines page number (index) to be converted. If PageNumber = 0 (by default) then all pages of document will be converted.

    PageNumbersToConvert

    List<int>

    Determines list of page numbers, that will be converted. For example, if need converted only 3, 5 and 7 pages.

    WithoutAnnotations

    bool

    Determines that image pages will be returned without annotations.

    Priority – it’s what will be happen if all parameters are sets:

    Parameter
    Priority
    Description

    WithoutAnnotations

    1

    If this parameter is true, then document will be returned without annotations.

    PageNumbersToConvert

    2

    If this parameter not null and count of elements > 0, then only page numbers from PageNumbersToConvert parameter will be converted. PageNumber and CountPagesToConvert will be ignored.

    PageNumber

    3

    If this parameter = 0 (by default), then all pages of document will be converted. If parameter > 0, then will converted specified page.

    CountPagesToConvert

    4

    Working only if PageNumber > 0. If CountPagesToConvert = 1, then only one page will be converted (which is defined by PageNumber parameter). If CountPagesToConvert > 1, then will converted from Page number to PageNumber + CountPagesToConvert range.

    ImageOption

    Result

    new ImageOptions()

    All pages of document will be converted.

    new ImageOptions() {WithoutAnnotations = true}

    All pages of document will converted, but without annotations.

    new ImageOptions() {PageNumber = 5}

    Only 5 page of document will be converted.

    List<int> numberList = new List<int>() { 2, 5, 7};

    new ImageOptions()

    { PageNumbersToConvert = numberList }

    Only 2nd, 5th and 7th pages of document will be converted.

    new ImageOptions()

    {PageNumber = 5, CountPagesToConvert = 2}

    Pages 5,6,7 of document will be converted.


    Note:

    Note

    In order to optimize GetPages performance method, we do not check if PageNumber or PageNumbersToConvert elements < number of document pages, because this is additional computing costs per every GetPages method call. So, if PageNumber or PageNumbersToConvert will be > number of document pages, then you will get ArgumentOutOfRange or IndexOutOfRange exception. So, you must control this outside GetPages call.

     

    Following example demonstrates how to use GetPages method:

    Code Block
    titleC#
    using System.Collections.Generic;
    using System.IO;
    using GroupDocs.Annotation.Config;
    using GroupDocs.Annotation.Domain.Image;
    using GroupDocs.Annotation.Domain.Options;
    using GroupDocs.Annotation.Handler;
     
     
    namespace GetPagesSample
    {
        class Program
        {
            static void Main(string[] args)
            {
                Stream document = new FileStream("../../Clear.pdf", FileMode.Open);
                AnnotationConfig cfg = new AnnotationConfig();
                cfg.StoragePath = "StorageFolder";
     
                AnnotationImageHandler annotationHandler = new AnnotationImageHandler(cfg);
     
                List<PageImage> images = annotationHandler.GetPages(document, new ImageOptions());
     
                // Save result stream to file.
                using(FileStream fileStream = new FileStream("../../image.png", FileMode.Create))
                {
                    byte[] buffer = new byte[images[0].Stream.Length];
                    images[0].Stream.Seek(0, SeekOrigin.Begin);
                    images[0].Stream.Read(buffer, 0, buffer.Length);
                    fileStream.Write(buffer, 0, buffer.Length);
                    fileStream.Close();        
                }
            }
        }
    }
  2. Enabling caching for opening same document pages

    Code Block
    ImageOptions imageOptions = new ImageOptions();
    imageOptions.CacheStoragePath = AnnotationImageHandler.GetFileDataStore().TempPath;
    imageOptions.EnableCaching = true;