Ejemplo n.º 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());
             }
         }
     }
 }
Ejemplo n.º 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);
                }
            }
        }
    }
Ejemplo n.º 3
0
 internal PdfAction(PdfDocument doc, FPDF_ACTION actionHandle)
     : base(actionHandle)
 {
     Document = doc;
 }
Ejemplo n.º 4
0
 public void CopyViewerPreferencesFrom(PdfDocument srcDoc) => PDFium.FPDF_CopyViewerPreferences(Handle, srcDoc.Handle);