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

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
wolfgang.moeser Posted: Friday, May 21, 2021 7:46:18 AM(UTC)
 
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);
        }
Paul Rayman Posted: Wednesday, May 19, 2021 3:11:18 AM(UTC)
 
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.
wolfgang.moeser Posted: Tuesday, May 18, 2021 1:35:10 AM(UTC)
 
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?