Пример #1
0
 //Todo clean this up and add support for multiple pages
 public byte[] Test(string filepath)
 {
     using (var doc = new PDFiumSharp.PdfDocument(filepath))
     {
         var page = doc.Pages[0];
         using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, false))
         {
             page.Render(bitmap);
             var b = new BmpBitmapDecoder(bitmap.AsBmpStream(), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First();
             JpegBitmapEncoder encoder = new JpegBitmapEncoder();
             encoder.Frames.Add(b);
             using (MemoryStream ms = new MemoryStream())
             {
                 encoder.Save(ms);
                 return(ms.ToArray());
             }
         }
     }
 }
Пример #2
0
    public void RenderPDFAsImages(string Inputfile, string OutputFolder)
    {
        string fileName = Path.GetFileNameWithoutExtension(Inputfile);

        using (PDFiumSharp.PdfDocument doc = new PDFiumSharp.PdfDocument(Inputfile))
        {
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                var page = doc.Pages[i];
                using (var bitmap = new System.Drawing.Bitmap((int)page.Width, (int)page.Height))
                {
                    var grahpics = Graphics.FromImage(bitmap);
                    grahpics.Clear(Color.White);
                    page.Render(bitmap);
                    var targetFile = Path.Combine(OutputFolder, fileName + "_" + i + ".png");
                    bitmap.Save(targetFile);
                }
            }
        }
    }
Пример #3
0
 internal PdfAction(PdfDocument doc, FPDF_ACTION actionHandle)
     : base(actionHandle)
 {
     Document = doc;
 }
Пример #4
0
 public void CopyViewerPreferencesFrom(PdfDocument srcDoc) => PDFium.FPDF_CopyViewerPreferences(Handle, srcDoc.Handle);