예제 #1
0
        static void Main(string[] args)
        {
            PdfDocumentView pdfViewer = new PdfDocumentView();

            pdfViewer.Load(@"../../Data/Barcode.pdf");
            pdfViewer.Print();
        }
예제 #2
0
        /// <summary>
        /// Exports the PDF pages as Tiff Images.
        /// </summary>
        /// <param name="fileName">The PDF file name</param>
        private void ExportPDFtoTiff(string fileName)
        {
            PdfDocumentView pdfViewer = new PdfDocumentView();

            //Load the input PDF file
            pdfViewer.Load(fileName);
            //Export the images From the input PDF file at the page range of 0 to 1 .
            BitmapSource[] image = pdfViewer.ExportAsImage(0, pdfViewer.PageCount - 1);
            if (image != null)
            {
                for (int i = 0; i < image.Length; i++)
                {
                    //Initialize the new Tiff bitmap encoder
                    TiffBitmapEncoder encoder = new TiffBitmapEncoder();
                    //Set the compression to zip to reduce the file size.
                    encoder.Compression = TiffCompressOption.Zip;
                    //Create the bitmap frame using the bitmap source and add it to the encoder.
                    encoder.Frames.Add(BitmapFrame.Create(image[i]));
                    //Create the file stream for the output in the desired image format.
                    using (FileStream stream = new FileStream("Image_" + i.ToString() + ".Tiff", FileMode.Create))
                    {
                        //Save the stream, so that the image will be generated in the output location.
                        encoder.Save(stream);
                    }
                }
            }
        }
예제 #3
0
        public string ConvertPdfToImage(string inputFilePath)
        {
            var imgPath = string.Empty;

            using (var viewer = new PdfDocumentView())
            {
                var file = new FileInfo(inputFilePath);
                viewer.Load(file.FullName);
                var images = viewer.ExportAsImage(PageNumber - 1, PageNumber - 1);
                imgPath = Path.Combine(Common.TempStorage, $"{file.Name.Substring(0, file.Name.Length - 4)}.png");
                var resizedPath = Path.Combine(Common.UserCriteriaStorage, $"{file.Name.Substring(0, file.Name.Length - 4)}-R.png");
                var image       = images[0];
                if (File.Exists(imgPath))
                {
                    File.Delete(imgPath);
                }
                image.Save(imgPath);
                double scaleFactor = 0;
                var    resize      = false;
                using (var bmp = Image.FromFile(imgPath))
                {
                    if (bmp.Size.Width > 1428)
                    {
                        scaleFactor = 1428.0 / Convert.ToDouble(bmp.Size.Width);
                        resize      = true;
                    }
                }
                if (resize)
                {
                    Common.Resize(imgPath, resizedPath, scaleFactor);
                }
            }
            return(imgPath);
        }
예제 #4
0
        void PrintButton_Click(object sender, System.EventArgs e)
        {
            PdfDocumentView pdfDocumentView1 = new PdfDocumentView();

            //Create Memory Stream to save pdfdocument.
            MemoryStream pdfstream = new MemoryStream();

            PdfDocument pdfDoc = new PdfDocument();

            pdfDoc = sfDataGrid1.ExportToPdf();

            //Save the PDF file
            pdfDoc.Save(pdfstream);

            //Load the pdfstream to pdfDocumentView
            pdfDocumentView1.Load(pdfstream);

            PrintDialog printdialog = new PrintDialog();
            int         pageCount   = pdfDocumentView1.PageCount;

            printdialog.AllowPrintToFile            = true;
            printdialog.AllowSomePages              = true;
            printdialog.PrinterSettings.FromPage    = 1;
            printdialog.PrinterSettings.ToPage      = pageCount;
            printdialog.PrinterSettings.MaximumPage = pageCount;
            printdialog.PrinterSettings.MinimumPage = 1;

            if (printdialog.ShowDialog() == DialogResult.OK)
            {
                printdialog.Document = pdfDocumentView1.PrintDocument;
                printdialog.Document.Print();
            }
        }
 /// <summary>
 /// Load a PDF document.
 /// </summary>
 private void LoadDocument(PdfDocumentView viewer, string fileName)
 {
     viewer.Load(fileName);
     lblTotalPageCount.Text = viewer.PageCount.ToString();
     EnablePagination();
     pageTimer.Tick += pageTimer_Tick;
     pageTimer.Start();
 }
 // Prints PDF file
 void PrintPDF()
 {
     pdfViewerControl = new PdfDocumentView();
     // Load the PDF document to be printed
     pdfViewerControl.Load(@"../../Data/Barcode.pdf");
     // Print the PDF document silently using the printer name.
     pdfViewerControl.Print("Pass your printer name here...");
 }
예제 #7
0
 /// <summary>
 /// Load a PDF document.
 /// </summary>
 private void LoadDocument(PdfDocumentView viewer, string fileName)
 {
     viewer.ReferencePath = @"..\..\..\..\..\..\..\..\Common\Data\PDF";
     viewer.Load(fileName);
     lblTotalPageCount.Text = viewer.PageCount.ToString();
     EnablePagination();
     pageTimer.Tick += pageTimer_Tick;
     pageTimer.Start();
 }
예제 #8
0
 /// <summary>
 /// Load a PDF document.
 /// </summary>
 private void LoadDocument(PdfDocumentView viewer, string fileName)
 {
     viewer.RenderingEngine = Syncfusion.Windows.Forms.PdfViewer.PdfRenderingEngine.Pdfium;
     viewer.ReferencePath   = @"..\..\..\..\..\..\..\Common\Data\PDF\";
     viewer.Load(fileName);
     lblTotalPageCount.Text = viewer.PageCount.ToString();
     EnablePagination();
     pageTimer.Tick += pageTimer_Tick;
     pageTimer.Start();
 }
예제 #9
0
        public ViewModel()
        {
            pdfViewer1 = new PdfDocumentView();
            pdfViewer1.Load(GetFullTemplatePath("EmpDetails.pdf", false));
            int pageCount = pdfViewer1.PageCount;

            m_pageNumbers.Clear();
            for (int i = 1; i <= pageCount; i++)
            {
                m_pageNumbers.Add(i);
            }
            if (m_pageNumbers.Count > 0)
            {
                m_startPageNumber = m_pageNumbers[0];
                m_endPageNumber   = m_pageNumbers[m_pageNumbers.Count - 1];
            }
        }
예제 #10
0
        public ExportAsImageViewModel()
        {
            pdfViewer = new PdfDocumentView();
            Uri uriResource = new Uri("/syncfusion.pdfviewerdemos.wpf;component/Assets/EmpDetails.pdf", UriKind.Relative);
            StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uriResource);

            pdfViewer.Load(streamResourceInfo.Stream);
            int pageCount = pdfViewer.PageCount;

            m_pageNumbers.Clear();
            for (int i = 1; i <= pageCount; i++)
            {
                m_pageNumbers.Add(i);
            }
            if (m_pageNumbers.Count > 0)
            {
                m_startPageNumber = m_pageNumbers[0];
                m_endPageNumber   = m_pageNumbers[m_pageNumbers.Count - 1];
            }
        }
        static void Main(string[] args)
        {
            PdfDocumentView viewer = new PdfDocumentView();

            //Load the PDF document
            viewer.Load("../../../Data/Barcode.pdf");

            //Initialize print dialog.
            PrintDialog dialog = new PrintDialog();

            dialog.AllowPrintToFile = true;

            dialog.AllowSomePages = true;

            dialog.AllowCurrentPage = true;

            dialog.Document = viewer.PrintDocument;

            //Print the PDF document
            dialog.Document.Print();

            //Dispose the viewer
            viewer.Dispose();
        }
예제 #12
0
 public static Task <Dictionary <string, string> > ConvertPdfsToImagesAsync(IEnumerable <string> pdfFiles, IProgress <TaskProgress> prog = null, EtaCalculator eta = null)
 {
     return(Task.Run(() =>
     {
         var pdfImages = new Dictionary <string, string>();
         var files = new List <FileInfo>();
         pdfFiles.ForEach(c => files.Add(new FileInfo(c)));
         var pdfFilesList = files.Where(c => c.Extension == ".pdf").ToList();
         var currentFile = 0;
         var fileCount = pdfFilesList.Count;
         Parallel.ForEach(pdfFilesList, (file) =>
         {
             try
             {
                 using (var viewer = new PdfDocumentView())
                 {
                     viewer.Load(file.FullName);
                     var images = viewer.LoadedDocument.ExportAsImage(0, viewer.PageCount - 1, new SizeF(1428, 1848), true);
                     var imgCount = 1;
                     foreach (var image in images)
                     {
                         var imgPath = Path.Combine(TempStorage, $"{file.Name.Substring(0, file.Name.Length - 4)}.{imgCount}.png");
                         pdfImages.Add(imgPath, file.FullName);
                         image.Save(imgPath);
                         imgCount++;
                     }
                 }
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message.Trim());
                 System.Diagnostics.Debug.WriteLine(ex.Message.Trim());
             }
             finally
             {
                 if (prog != null || eta != null)
                 {
                     lock (prog)
                     {
                         currentFile++;
                         var rawProgress = (Convert.ToDouble(currentFile) / Convert.ToDouble(fileCount));
                         var progress = rawProgress * 100;
                         var progressFloat = (float)rawProgress;
                         eta.Update(progressFloat);
                         if (eta.ETAIsAvailable)
                         {
                             var timeRemaining = eta.ETR.ToString(@"dd\.hh\:mm\:ss");
                             prog.Report(new TaskProgress
                             {
                                 ProgressText = file.Name,
                                 ProgressPercentage = progress,
                                 ProgressText2 = timeRemaining
                             });
                         }
                         else
                         {
                             prog.Report(new TaskProgress
                             {
                                 ProgressText = file.Name,
                                 ProgressPercentage = progress,
                                 ProgressText2 = "Calculating..."
                             });
                         }
                     }
                 }
             }
         });
         return pdfImages;
     }));
 }
예제 #13
0
        public static void PrintPDF(string filePath, string Printer = null)
        {
#if ( Print_Using_Adobe_Reader )
            // Define or otherwise determine the path of the Adobe reader
            PdfFilePrinter.AdobeReaderPath = @Properties.Settings.Default.AdobeReader;

            if (string.IsNullOrWhiteSpace(printerName))
            {
                // Present a Printer settings dialogue to the user so that they may select the printer
                // to use.
                PrinterSettings settings = new PrinterSettings();
                settings.Collate = false;

                PrintDialog printerDialog = new PrintDialog();
                printerDialog.AllowSomePages              = false;
                printerDialog.ShowHelp                    = false;
                printerDialog.PrinterSettings             = settings;
                printerDialog.AllowPrintToFile            = true;
                printerDialog.PrinterSettings.PrintToFile = true;

                DialogResult result = printerDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    printerName = settings.PrinterName;
                }
                else
                {
                    return;
                }
            }

            // Print the document on the selected printer (We are ignoring all other print
            // options here

            PdfFilePrinter printer = new PdfFilePrinter(filePath, printerName);

            try
            {
                printer.Print();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
#else
            if (!File.Exists(filePath))
            {
                return;
            }
            // This is a massive bodge!
            ((App)App.Current).EventPage.Dispatcher.Invoke(delegate()
            {
                PdfDocumentView pdfViewer1 = new PdfDocumentView();


                pdfViewer1.Load(filePath);

                //if ( !string.IsNullOrWhiteSpace ( Printer ) )
                //    pdfViewer1.Print ( Printer );
                //else
                //    pdfViewer1.Print ( );

                PrintDialog print = new PrintDialog();

                if (!string.IsNullOrWhiteSpace(Printer))
                {
                    PrintQueue t = print.PrintQueue;
                    try
                    {
                        PrintServer server = new PrintServer();
                        print.PrintQueue   = server.GetPrintQueue(Printer);
                    }
                    catch (Exception)
                    {
                        System.Diagnostics.Debug.WriteLine("Failed to find printer");
                        print.PrintQueue = t;
                    }
                }

                //BitmapSource img = pdfViewer1.ExportAsImage ( 1 );


                print.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Championship Solutions");
            });
#endif
        }