Exemplo n.º 1
0
        /// <summary>
        /// Create a new <see cref="MuPDFPage"/> object from the specified document.
        /// </summary>
        /// <param name="context">The context that owns the document.</param>
        /// <param name="document">The document from which the page should be extracted.</param>
        /// <param name="number">The number of the page that should be extracted (starting at 0).</param>
        internal MuPDFPage(MuPDFContext context, MuPDFDocument document, int number)
        {
            this.OwnerContext  = context;
            this.OwnerDocument = document;
            this.PageNumber    = number;

            float x = 0;
            float y = 0;
            float w = 0;
            float h = 0;

            ExitCodes result = (ExitCodes)NativeMethods.LoadPage(context.NativeContext, document.NativeDocument, number, ref NativePage, ref x, ref y, ref w, ref h);

            this.Bounds         = new Rectangle(Math.Round(x * document.ImageXRes / 72.0 * 1000) / 1000, Math.Round(y * document.ImageYRes / 72.0 * 1000) / 1000, Math.Round(w * document.ImageXRes / 72.0 * 1000) / 1000, Math.Round(h * document.ImageYRes / 72.0 * 1000) / 1000);
            this.OriginalBounds = new Rectangle(x, y, w, h);

            switch (result)
            {
            case ExitCodes.EXIT_SUCCESS:
                break;

            case ExitCodes.ERR_CANNOT_LOAD_PAGE:
                throw new MuPDFException("Cannot load page", result);

            case ExitCodes.ERR_CANNOT_COMPUTE_BOUNDS:
                throw new MuPDFException("Cannot compute bounds", result);

            default:
                throw new MuPDFException("Unknown error", result);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Render (part of) a page to an array of bytes.
        /// </summary>
        /// <param name="pageNumber">The number of the page to render (starting at 0).</param>
        /// <param name="region">The region of the page to render in page units.</param>
        /// <param name="zoom">The scale at which the page will be rendered. This will determine the size in pixel of the image.</param>
        /// <param name="pixelFormat">The format of the pixel data.</param>
        /// <param name="includeAnnotations">If this is <see langword="true" />, annotations (e.g. signatures) are included in the display list that is generated. Otherwise, only the page contents are included.</param>
        /// <returns>A byte array containing the raw values for the pixels of the rendered image.</returns>
        public byte[] Render(int pageNumber, Rectangle region, double zoom, PixelFormats pixelFormat, bool includeAnnotations = true)
        {
            int bufferSize = MuPDFDocument.GetRenderedSize(region, zoom, pixelFormat);

            byte[] buffer = new byte[bufferSize];

            GCHandle bufferHandle  = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr   bufferPointer = bufferHandle.AddrOfPinnedObject();

            try
            {
                Render(pageNumber, region, zoom, pixelFormat, bufferPointer, includeAnnotations);
            }
            finally
            {
                bufferHandle.Free();
            }

            return(buffer);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new <see cref="MuPDFPageCollection"/> from the specified document, containing the specified number of pages.
 /// </summary>
 /// <param name="context">The context that owns the document.</param>
 /// <param name="document">The document from which the pages should be extracted.</param>
 /// <param name="length">The number of pages in the document.</param>
 internal MuPDFPageCollection(MuPDFContext context, MuPDFDocument document, int length)
 {
     Pages         = new MuPDFPage[length];
     OwnerContext  = context;
     OwnerDocument = document;
 }