static void Main(string[] args) { //using (var doc = new PdfDocument("TestDoc.pdf", "password")) using (var doc = new PdfDocument(@"C:\Users\rafae\Downloads\EN-US-CNTNT-eBook-Build a Competitive Edge With SaaS Apps.pdf")) { int pageNumber = 0; foreach (var page in doc.Pages) { using (page) { using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) using (var stream = new FileStream($"{pageNumber}.bmp", FileMode.Create)) { page.Render(bitmap); bitmap.Save(stream); } using (var text = PdfText.Load(page)) { File.WriteAllText($"{pageNumber}.txt", text.GetText()); var parts = text.GetSegmentedText(); File.WriteAllLines($"{pageNumber}.bti.txt", parts.Select(ti => ti.Text)); } } pageNumber++; } } }
static void Main(string[] args) { using (var doc = new PdfDocument("TestDoc.pdf", "password")) { var page = doc.Pages[0]; using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) { page.Render(bitmap); bitmap.Save("Page1.bmp"); } } }
public void OnGet() { // pdf extraction here using (var doc = new PdfDocument("c:\\test.pdf")) { int i = 0; foreach (var page in doc.Pages) { using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) using (var stream = new FileStream($"{i++}.bmp", FileMode.Create)) { page.Render(bitmap); bitmap.Save(stream); } } } }
static void Main(string[] args) { using (var doc = new PdfDocument("TestDoc.pdf", "password")) { int i = 0; foreach (var page in doc.Pages) { using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) using (var stream = new FileStream($"{i++}.bmp", FileMode.Create)) { page.Render(bitmap); bitmap.Save(stream); } } } Console.ReadKey(); }
static void Main(string[] args) { using (var doc = new PdfDocument(@"C:\temp\80d4e54f-8064-4c7f-b924-c196dbe2a087.pdf")) { var test = doc.InitFormFillEnvironment(); int i = 0; foreach (var page in doc.Pages) { using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, true)) using (var stream = new FileStream($"{i++}.bmp", FileMode.Create)) { page.Render(bitmap); page.RenderForm(test, bitmap); bitmap.Save(stream, 72, 72); } } } }
static void Main() { Application.Initialize(); Window window = new Window(); window.Closed += (sender, e) => Application.Exit(); using (var doc = new PdfDocument("TestDoc.pdf", "password")) { var page = doc.Pages[0]; using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, false)) { page.Render(bitmap, PageOrientations.Normal); bitmap.Save("Page0.bmp"); window.Content = new ImageView(Image.FromStream(bitmap.AsBmpStream())); } } window.Show(); Application.Run(); }
static void Main(string[] args) { using (var doc = new PdfDocument("TestDoc.pdf")) { int i = 0; foreach (var page in doc.Pages) { using (page) { //var textInfo = page.Text.GetTextInfo(0, page.Text.CountChars); var pageObjects = page.PageObjects; List <PdfPageObject> pageObjs = new List <PdfPageObject>(); List <string> str = new List <string>(); for (int j = 0, len = pageObjects.Count; j < len; j++) { pageObjs.Add(pageObjects[j]); if (pageObjects[j].ObjectType == PDFiumSharp.Enums.PageObjTypes.Text) { var txtPageObj = (PdfTextObject)pageObjects[j]; str.Add(txtPageObj.TextUnicode); var deviceRect = doc.RectangleFromPdf(page, txtPageObj.BoundingBox); } } var rects = page.Text.GetTextInfo(0, page.Text.CountChars).Rects; List <string> fontName = new List <string>(); int charIndex = 0; /*foreach (var rect in rects) * { * var txtContent = page.Text.GetBoundedText(rect); * str.Add( txtContent ); * fontName.Add(page.Text.GetFontNameInfo(charIndex)); * * //var point = page.PageToDevice(0, 0, (int)(rect.Right - rect.Left), (int)(rect.Bottom - rect.Top), rect.Left, rect.Top, page.Orientation); * var deviceRect = doc.RectangleFromPdf(page, rect); * charIndex += txtContent.Length; * }*/ //var font = page.Text.Font; //textInfo.Rects int width = (int)(page.Width); int height = (int)(page.Height); float dpiX = 72f; float dpiY = 72f; var thumbWidth = 800; var thumbHeight = 800; var ratio = 1f; var memStream = new MemoryStream(); // Get correct width/height for new DPI var pdfBitmapWidth = width * (int)dpiX / 72; var pdfBitmapHeight = height * (int)dpiY / 72; try { using (var pdfBitmap = new PDFiumBitmap(pdfBitmapWidth, pdfBitmapHeight, false)) { Console.WriteLine("Rendering page " + i.ToString()); pdfBitmap.FillRectangle(0, 0, pdfBitmapWidth, pdfBitmapHeight, new PDFiumSharp.Types.FPDF_COLOR(255, 255, 255)); page.Render(pdfBitmap, rectDest: (0, 0, pdfBitmapWidth, pdfBitmapHeight), orientation: PDFiumSharp.Enums.PageOrientations.Normal, flags: PDFiumSharp.Enums.RenderingFlags.None); pdfBitmap.Save(memStream); } //memStream.Seek(0, SeekOrigin.Begin); using (var img = Image.FromStream(memStream)) using (var bitmap = new Bitmap(img)) using (var fileStream = new FileStream($"{i}.png", FileMode.Create)) { bitmap.SetResolution(dpiX, dpiY); bitmap.Save(fileStream, ImageFormat.Png); } /*ratio = Math.Min((float)thumbWidth / (float)width, (float)thumbHeight / (float)height); * * thumbWidth = (int)(width * ratio); * thumbHeight = (int)(height * ratio); * * var originalImage = Bitmap.FromStream(memStream); * memStream.Dispose(); * * using (var thumbImage = new Bitmap(thumbWidth, thumbHeight)) * using (var graphics = Graphics.FromImage(thumbImage)) * using (var fileStream = new FileStream($"thumb_{i}.png", FileMode.Create)) * { * //graphics.CompositingQuality = CompositingQuality.HighQuality; * graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; * //graphics.SmoothingMode = SmoothingMode.HighQuality; * graphics.DrawImage(originalImage, 0, 0, thumbWidth, thumbHeight); * graphics.Save(); * * thumbImage.SetResolution(dpiX, dpiY); * thumbImage.Save(fileStream, ImageFormat.Png); * } */ } finally { //memStream.Dispose(); } var textInfo = page.Text.GetTextInfo(0, page.Text.CountChars); //Console.WriteLine("=================================================="); //Console.WriteLine("Rendering page " + i.ToString()); //using (var image = page.Render(width, height, dpiX, dpiY, PDFiumSharp.Enums.RenderingFlags.CorrectFromDpi)) //{ // image.Save($"page-{i}.png"); //} } i++; } } Console.ReadKey(); }