Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Mon Aug 12, 2013 8:41 am

Hello,

I'm testing your trial version and I've question for you - How can I set width and height while exporting PDF as Image ?
I work on VS 2010 and WPF.
My application is based on yours demo ...\e-iceblue\Spire.PdfViewer\WPFDemos\CS\WPF\PdfDocumentViewer\Export.

So, please answer my question.

Thanks,
Mike

mike2
 
Posts: 4
Joined: Mon Jul 29, 2013 10:49 pm

Mon Aug 12, 2013 10:12 am

Dear Mike,

Thanks for your inquriy.
For your need, we are doing some researches. We will give you a update tomorrow.

Thanks &Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Tue Aug 13, 2013 4:03 am

Dear Mike,

Thanks for your waiting.
Please try the below code to set width and height of image in WPF.
Code: Select all
 public partial class MainWindow : Window
    {
        public static Dictionary<string, BitmapSource> bitMap = new Dictionary<string, BitmapSource>();
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            pdfDocumentViewer1.LoadFromFile(@"..\..\Sample3.pdf");

            BitmapSource original = pdfDocumentViewer1.SaveAsImage(1);
               
           int maximumWidthOrHeight = 600;

           double scaleFactor = (double)maximumWidthOrHeight /
           Math.Max(original.PixelWidth, original.PixelHeight);
           int width = (int)Math.Round(scaleFactor * original.PixelWidth);
           int height = (int)Math.Round(scaleFactor * original.PixelHeight);

            BitmapSource newImage=CreateResizedImage(original,width,height);
            WriteBitmapSourecToFile(newImage, "sample.png");
        }

        static BitmapSource CreateResizedImage(BitmapSource source, int width, int height)
        {
            // Target Rect for the resize operation
            Rect rect = new Rect(0, 0, width, height);

            // Create a DrawingVisual/Context to render with
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawImage(source, rect);
            }

            // Use RenderTargetBitmap to resize the original image
            RenderTargetBitmap resizedImage = new RenderTargetBitmap(
                (int)rect.Width, (int)rect.Height,  // Resized dimensions
                96, 96,                             // Default DPI values
                PixelFormats.Default);              // Default pixel format
            resizedImage.Render(drawingVisual);

            // Return the resized image
            return resizedImage;
        }
        static void WriteBitmapSourecToFile(BitmapSource bitMapImg, string FullfileName)
        {
            if (bitMapImg != null)
            {             
                System.IO.FileStream fs = new System.IO.FileStream(FullfileName, System.IO.FileMode.Create);
                BitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitMapImg));
                encoder.Save(fs);
                fs.Close();

                bitMap.Add(FullfileName, bitMapImg);
            }
        }
    }


If you have any problem, please contact us.

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Aug 19, 2013 4:01 am

Dear Mike,

Do you try our solution? Does it meet your need?
Our dev team add a new method SaveAsImage(int pageNumber,int width,int height) for Spire.PDFViewer.
You could set the width and height of image via the method directly.
Once the new version of Spire.PDFViewer is released, we will tell you.

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Tue Aug 20, 2013 8:03 am

Hello,

Sorry for the delay.

Yes, I've tried and it's work perfectly but I was thinking about one thing - quality of exported image - why is so poor ? and how I can improve it ? (the quality of source file (PDF) is very good).

And another question how can I change all pages in PDF ?

PS. If it is no problem, maybe You could add new method - SaveAllPagesAsImage(int pagesNumber, int Width, int Height) - I think that this method will solve a lot of problems.

Regards,
Mike

mike2
 
Posts: 4
Joined: Mon Jul 29, 2013 10:49 pm

Tue Aug 20, 2013 8:34 am

Dear Mike,

Thanks for your feedback message and your suggestion.
In new version, the method SaveAsImage(int pageNumber,int width,int height) can get an image with high quality.
For your new need, do you want a method which can save all pages of PDF to a image, or save every page of PDF to a image?

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Thu Aug 22, 2013 7:05 am

Dear Mike,

Our dev team added new methods as below into Spire.PDFViewer.

//Save some pages or all pages to a .tiff image based on vectors, and all pages are zoomed to the same width and height.
public void SaveAsImage(string imageFilePath,int[] pagesNumber,int imageWidth,int imageHeight)

//Save some pages to all pages a .tiff image based on vectors, and every page keeps its original size.
public void SaveAsImage(string imageFilePath,int[] pagesNumber)

If the new methods are not what you want, please telll us.

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Aug 26, 2013 9:04 am

Hi,

It seems to be exactly what I need.

My need is very simply - I have PDF file (30 pages) and I need to convert all of these pages into images.
So from one PDF file I need 30 image files and it could be .tiff.

When will the new version be available ?

Regards,
Mike

mike2
 
Posts: 4
Joined: Mon Jul 29, 2013 10:49 pm

Mon Aug 26, 2013 9:29 am

Dear Mike,

Thanks for your feedback message.
Our new version of Spire.PDFViewer can meet your need. Our dev team is testing the version. Once it is ok, we will release it and tell you.
In case you have further questions, please feel free to contact us.

Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Wed Aug 28, 2013 6:32 am

Dear Mike,

Thanks for your waiting.
The new version has been released, please download and test Spire.PDFViewer Pack(Hotfix) Version:2.0.16.
Downloading link: http://www.e-iceblue.com/Download/download-pdf-viewer-for-net-now.html

The below code as a referance.

Save the specified PDF page as image with specified size in WPF application, SaveAsImage(int pageNumber, int imageWidth, int imageHeight).
Code: Select all
   
          using (FileStream fs = new FileStream("sample.png", FileMode.Create))
            {
               BitmapSource  bs= viewer.SaveAsImage(1, 800, 1000);
               BmpBitmapEncoder encoder = new BmpBitmapEncoder();
               encoder.Frames.Add(BitmapFrame.Create(bs));
               encoder.Save(fs);
            }
       

Save the specified PDF page range as tiff file in WPF application, SaveAsImage(string tiffFilePath, int[] pagesNumbers).
Code: Select all
 
            int[] pageNumbers = {1, 3, 4};
            viewer.SaveAsImage("sample.tiff", pageNumbers);
         

Save the specified PDF page range as tiff file with specified size in WPF application, SaveAsImage(string tiffFilePath, int[] pagesNumbers, int imageWidth, int imageHeight).
Code: Select all
           int[] pageNumbers = {1, 3, 4};
            viewer.SaveAsImage("sample.tiff", pageNumbers,800,1000);
         


Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 02, 2013 8:23 am

Hello,

I've just tested your new hotfix and it's works perfectly fine.

Thanks for helping me out.

Regards,
Mike

mike2
 
Posts: 4
Joined: Mon Jul 29, 2013 10:49 pm

Fri Sep 13, 2013 9:30 am

Dear Mike,

Thanks for your feedback.
Please feel free to contact us in case you have further questions.

Best regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDFViewer

cron