Esempio n. 1
0
        /// <summary>
        /// Imports pages of <paramref name="sourceDocument"/> into the current <see cref="PdfDocument"/>.
        /// </summary>
        /// <seealso cref="PDFium.FPDF_ImportPages(Types.FPDF_DOCUMENT, Types.FPDF_DOCUMENT, int, int[])"/>
        public bool Insert(int index, PdfDocument sourceDocument, params int[] srcPageIndices)
        {
            bool result;

            if (index <= _pages.Count)
            {
                result = Pdfium.FPDF_ImportPages(_doc.Handle, sourceDocument.Handle, index, srcPageIndices);
                if (result)
                {
                    _pages.InsertRange(index, Enumerable.Repeat <PdfPage>(null, srcPageIndices.Length));
                    for (int i = index; i < _pages.Count; i++)
                    {
                        if (_pages[i] != null)
                        {
                            _pages[i].Index = i;
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            return(result);
        }
Esempio n. 2
0
 public PdfDestination this[string name]
 {
     get
     {
         var handle = Pdfium.FPDF_GetNamedDestByName(_doc.Handle, name);
         return(handle.IsNull ? null : new PdfDestination(_doc, handle, name));
     }
 }
Esempio n. 3
0
 public PdfDestination this[int index]
 {
     get
     {
         if (index < 0 || index >= Count)
         {
             throw new ArgumentOutOfRangeException(nameof(index));
         }
         (var handle, var name) = Pdfium.FPDF_GetNamedDest(_doc.Handle, index);
         return(handle.IsNull ? null : new PdfDestination(_doc, handle, name));
     }
 }
Esempio n. 4
0
        internal PdfPageCollection(PdfDocument doc)
        {
            lock (_lock)
            {
                _doc   = doc;
                _pages = new List <PdfPage>(Pdfium.FPDF_GetPageCount(doc.Handle));

                //Initialize _pages with null entries
                for (int i = 0; i < _pages.Capacity; i++)
                {
                    _pages.Add(null);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Removes the page at <paramref name="index"/>.
 /// </summary>
 public void RemoveAt(int index)
 {
     if (index < _pages.Count)
     {
         ((IDisposable)_pages[index])?.Dispose();
         _pages.RemoveAt(index);
         for (int i = index; i < _pages.Count; i++)
         {
             if (_pages[i] != null)
             {
                 _pages[i].Index = i;
             }
         }
     }
     Pdfium.FPDFPage_Delete(_doc.Handle, index);
 }
Esempio n. 6
0
 protected override void Dispose(FPDF_DOCUMENT handle)
 {
     ((IDisposable)Pages).Dispose();
     Pdfium.FPDF_CloseDocument(handle);
 }
Esempio n. 7
0
 public void CopyViewerPreferencesFrom(PdfDocument srcDoc) => Pdfium.FPDF_CopyViewerPreferences(Handle, srcDoc.Handle);
Esempio n. 8
0
 public string GetMetaText(MetadataTags tag) => Pdfium.FPDF_GetMetaText(Handle, tag);
Esempio n. 9
0
        public PdfBookmark FindBookmark(string title)
        {
            var handle = Pdfium.FPDFBookmark_Find(Handle, title);

            return(handle.IsNull ? null : new PdfBookmark(this, handle));
        }
Esempio n. 10
0
 /// <summary>
 /// Saves the <see cref="PdfDocument"/> to a <paramref name="stream"/>.
 /// </summary>
 /// <param name="version">
 /// The new PDF file version of the saved file.
 /// 14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored.
 /// </param>
 public bool Save(Stream stream, SaveFlags flags = SaveFlags.None, int version = 0)
 {
     return(Pdfium.FPDF_SaveAsCopy(Handle, stream, flags, version));
 }
Esempio n. 11
0
 /// <summary>
 /// Loads a <see cref="PdfDocument"/> from '<paramref name="count"/>' bytes read from a <paramref name="stream"/>.
 /// <see cref="Close"/> must be called in order to free unmanaged resources.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="fileRead"></param>
 /// <param name="count">
 /// The number of bytes to read from the <paramref name="stream"/>.
 /// If the value is equal to or smaller than 0, the stream is read to the end.
 /// </param>
 /// <param name="password"></param>
 public PdfDocument(Stream stream, FPDF_FILEREAD fileRead, int count = 0, string password = null)
     : this(Pdfium.FPDF_LoadDocument(stream, fileRead, count, password))
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Loads a <see cref="PdfDocument"/> from memory.
 /// <see cref="Close"/> must be called in order to free unmanaged resources.
 /// </summary>
 /// <param name="data">Byte array containing the bytes of the PDF document to load.</param>
 /// <param name="index">The index of the first byte to be copied from <paramref name="data"/>.</param>
 /// <param name="count">The number of bytes to copy from <paramref name="data"/> or a negative value to copy all bytes.</param>
 public PdfDocument(byte[] data, int index = 0, int count = -1, string password = null)
     : this(Pdfium.FPDF_LoadDocument(data, index, count, password))
 {
 }
Esempio n. 13
0
 /// <summary>
 /// Fills a rectangle in the <see cref="PdfiumBitmap"/> with <paramref name="color"/>.
 /// The pixel values in the rectangle are replaced and not blended.
 /// </summary>
 public void FillRectangle(int left, int top, int width, int height, FPDF_COLOR color)
 {
     Pdfium.FPDFBitmap_FillRect(Handle, left, top, width, height, color);
 }
Esempio n. 14
0
 /// <summary>
 /// Creates a new <see cref="PdfDocument"/>.
 /// <see cref="Close"/> must be called in order to free unmanaged resources.
 /// </summary>
 public PdfDocument()
     : this(Pdfium.FPDF_CreateNewDocument())
 {
 }
Esempio n. 15
0
 public PdfiumException()
     : base($"PDFium Error: {Pdfium.FPDF_GetLastError().GetDescription()}")
 {
 }
Esempio n. 16
0
 protected override void Dispose(FPDF_BITMAP handle)
 {
     Pdfium.FPDFBitmap_Destroy(handle);
 }
Esempio n. 17
0
 /// <summary>
 /// Creates a new <see cref="PdfiumBitmap"/>. Unmanaged memory is allocated which must
 /// be freed by calling <see cref="Dispose"/>.
 /// </summary>
 /// <param name="width">The width of the new bitmap.</param>
 /// <param name="height">The height of the new bitmap.</param>
 /// <param name="hasAlpha">A value indicating wheter the new bitmap has an alpha channel.</param>
 /// <remarks>
 /// A bitmap created with this overload always uses 4 bytes per pixel.
 /// Depending on <paramref name="hasAlpha"/> the <see cref="Format"/> is then either
 /// <see cref="BitmapFormats.BGRA"/> or <see cref="BitmapFormats.BGRx"/>.
 /// </remarks>
 public PdfiumBitmap(int width, int height, bool hasAlpha, bool forceAlphaChannel = false)
     : this(Pdfium.FPDFBitmap_Create(width, height, hasAlpha))
 {
     _forceAlphaChannel = forceAlphaChannel;
     FillRectangle(0, 0, width, height, 0xFFFFFFFF);
 }
Esempio n. 18
0
 /// <summary>
 /// Loads a <see cref="PdfDocument"/> from the file system.
 /// <see cref="Close"/> must be called in order to free unmanaged resources.
 /// </summary>
 /// <param name="fileName">Filepath of the PDF file to load.</param>
 public PdfDocument(string fileName, string password = null)
     : this(Pdfium.FPDF_LoadDocument(fileName, password))
 {
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new <see cref="PdfiumBitmap"/> using memory allocated by the caller.
 /// The caller is responsible for freeing the memory and that the adress stays
 /// valid during the lifetime of the returned <see cref="PdfiumBitmap"/>. To free
 /// unmanaged resources, <see cref="Dispose"/> must be called.
 /// </summary>
 /// <param name="width">The width of the new bitmap.</param>
 /// <param name="height">The height of the new bitmap.</param>
 /// <param name="format">The format of the new bitmap.</param>
 /// <param name="scan0">The adress of the memory block which holds the pixel values.</param>
 /// <param name="stride">The number of bytes per image row.</param>
 public PdfiumBitmap(int width, int height, BitmapFormats format, IntPtr scan0, int stride)
     : this(Pdfium.FPDFBitmap_CreateEx(width, height, format, scan0, stride))
 {
     FillRectangle(0, 0, width, height, 0xFFFFFFFF);
 }