logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
wolfgang.moeser  
#1 Posted : Tuesday, May 18, 2021 1:35:10 AM(UTC)
Quote
wolfgang.moeser

Rank: Newbie

Groups: Registered
Joined: 5/17/2021(UTC)
Posts: 2
Germany
Location: Baiersdorf

Thanks: 1 times
Hi,

I have to convert scanned PDF documents to PNG and try to compensate incorrect page orientation from scanning process.
Here is an example of my tries. 'result' is always 'true', but the resulting PNG file always has same orientation like the original page in PDF.


Code:
private static void RotateAndSave(PdfPage pdfPage, float rotation, Int32Size pageSize)
        {
            FS_RECTF fS_RECTF = new(0, 0, pdfPage.Width, pdfPage.Height);
            FS_MATRIX fS_MATRIX = new();
            fS_MATRIX.SetIdentity();
            fS_MATRIX.Rotate(rotation, true);
            bool result = pdfPage.TransformWithClip(fS_MATRIX, fS_RECTF);

            using var bitmap = new PdfBitmap(pageSize.Width, pageSize.Height, true);
            bitmap.FillRect(0, 0, pageSize.Width, pageSize.Height, FS_COLOR.White);
            pdfPage.Render(bitmap, 0, 0, pageSize.Width, pageSize.Height, PageRotate.Normal, RenderFlags.FPDF_LCD_TEXT);
            string pngFilename = @"C:\temp\rotated_pdf.png";

            bitmap.Image.Save(pngFilename, System.Drawing.Imaging.ImageFormat.Png);
        }


Does Lite Edition not support this function? At https://pdfium.patagames...censing_FullAPICalls.htm I found also for Lite:

Quote:
PDF Page objects capability
PDF object access and edit (Get/Set stroke color, Get/Set fill color, transform, copy, clone, bounding box, transparency,…)


Could please anyone help?


Tried also with a demo license of Pdfium FULL and it doesn't work either.
My environment: VS 2019, 16.9.5; WPF with .NET 5.0
Any ideas?

Edited by user Wednesday, May 19, 2021 2:44:52 AM(UTC)  | Reason: Try with FULL Edition also fails.

Paul Rayman  
#2 Posted : Wednesday, May 19, 2021 3:11:18 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Call page.Dispose after TransformClipPath.

But it seems to me that this method is not what is needed for this task. Contact support@patagames.com with a description of the task. They will help you find a solution.
thanks 1 user thanked Paul Rayman for this useful post.
wolfgang.moeser on 5/21/2021(UTC)
wolfgang.moeser  
#3 Posted : Friday, May 21, 2021 7:46:18 AM(UTC)
Quote
wolfgang.moeser

Rank: Newbie

Groups: Registered
Joined: 5/17/2021(UTC)
Posts: 2
Germany
Location: Baiersdorf

Thanks: 1 times
Originally Posted by: Paul Rayman Go to Quoted Post
Call page.Dispose after TransformClipPath.

But it seems to me that this method is not what is needed for this task. Contact support@patagames.com with a description of the task. They will help you find a solution.


With your hint and the help of Patagames support I got the solution:
  • I had to upgrade to version 4.56.2704
  • Correct FS_RECTF creation (coordinates start at bottom not at top...)
  • Set rotation to center of page
  • Call pdfPage.Dispose

Thanks!

Code:
private static void RotateAndSave(PdfPage pdfPage, float rotation, Int32Size pageSize)
        {
            FS_RECTF fS_RECTF = new(0, pdfPage.Height, pdfPage.Width, 0);
            FS_MATRIX fS_MATRIX = new();
            fS_MATRIX.SetIdentity();
            fS_MATRIX.Rotate(rotation, pageSize.Width / 2, pageSize.Height / 2, true);
            bool result = pdfPage.TransformWithClip(fS_MATRIX, fS_RECTF);
            pdfPage.Dispose();

            using var bitmap = new PdfBitmap(pageSize.Width, pageSize.Height, true);
            bitmap.FillRect(0, 0, pageSize.Width, pageSize.Height, FS_COLOR.White);
            pdfPage.Render(bitmap, 0, 0, pageSize.Width, pageSize.Height, PageRotate.Normal, RenderFlags.FPDF_LCD_TEXT);
            string pngFilename = @"C:\temp\rotated_pdf.png";

            bitmap.Image.Save(pngFilename, System.Drawing.Imaging.ImageFormat.Png);
        }
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.