Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

is there a way to create an image based from pdf using rectangle?

im using syncfusion pdfviewer(using the Unlimited Flat-Fee License). and this is how i create an image from pdf using c#

private void ScreenCapture(string fileName, int x, int y, int width, int height)
        {
            try
            {

                if (x != 0 && y != 0 && width != 0 && height != 0)
                {
                    Rectangle rect = new Rectangle(x, y, width, height);
                    Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
                    Graphics g = Graphics.FromImage(bmp);
                    g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
                    bmp.Save(fileName, ImageFormat.Jpeg);
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
            finally
            {

            }
        }

and this is my additional code

on declaration

Point startPoint;

on mouse down

Control control = (Control)sender;

            startPoint = control.PointToScreen(new Point(e.X, e.Y));

on my mouse up

Point endPoint = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
            int width = endPoint.X - startPoint.X;
            int height = endPoint.Y - startPoint.Y;
            theRectangle = new Rectangle(startPoint.X ,
                startPoint.Y, width, height );

the problem with my code is im capturing my screen. so when i resized my program. it will capture the screen and will result to wrong image

so is there a way to get or convert the pdf page that has a rectangle into image using c#? thank you

enter image description here

update:

im sorry if my question is not clear.

example. i draw a rectangle to the pdf using pdfviewer of syncfusion

enter image description here

the output will be something like this

https://drive.google.com/open?id=0B45rDxvaXzsmcTZIVVVSUU9Zc0E
https://drive.google.com/open?id=0B45rDxvaXzsmc1cxNTV4UUdOMUE
https://drive.google.com/open?id=0B45rDxvaXzsmSWtDRWhXYkpDT2c
https://drive.google.com/open?id=0B45rDxvaXzsmS214WmJnN3BvcUk

im verry sorry if my question is not clear

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
197 views
Welcome To Ask or Share your Answers For Others

1 Answer

After analyzed the attached screenshot, we found that you are using PdfViewerControl in WPF platform. As per your requirement, we have created a sample to convert the pdf page that has a rectangle to image using PDF Viewer. ?

Steps for using the sample:?

  1. Draw the rectangle in an area using Shape Annotation as you have used in your screenshot.?

  2. Save the changes in PDF document using “SAVE” button of PdfViewerControl.?

  3. Click the button “Open PDF and ExportAsImage” for exporting the page that has a rectangle to image.

Please find the code snippet used convert the PDF page that has a rectangle into image:

PdfLoadedDocument ldoc = new PdfLoadedDocument(fileName);?

ldoc.Pages[0].Annotations.Flatten = true;
?

ldoc.Save();?

Bitmap bmp = ldoc.ExportAsImage(0);
?

bmp.Save("outputImage.jpeg");

You can download the sample from the below link.?

Sample link: http://www.syncfusion.com/downloads/support/directtrac/166006/ze/SampleWPF734738560? ?

We have also create a video demo for using the sample and it will be available in the below link.?

Video link: http://www.syncfusion.com/downloads/support/directtrac/166006/ze/ExportAsImage1083458687?

Please try this sample and let us know whether it meets your requirement.

Otherwise kindly provide the specific details to us such as screenshot of your required output, sample you have used and other details (if any). It will be helpful for us to analyze more and to provide you better resolution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...