Exemplo n.º 1
0
        private void ButtonGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                string               inputPath  = this.textBoxInputPath.Text;
                string               outputPath = this.textBoxOutputPath.Text;
                int                  page       = (int)this.numericUpDownPage.Value;
                int                  resolution = (int)this.numericUpDownResolution.Value;
                GhostscriptDevices   device     = (GhostscriptDevices)this.comboBoxDevice.SelectedItem;
                GhostscriptPageSizes pageSize   = (GhostscriptPageSizes)this.comboBoxPageSize.SelectedItem;

                GhostscriptSettings ghostscriptSettings = new GhostscriptSettings
                {
                    Page = new GhostscriptPages {
                        Start = page, End = page
                    },
                    Device     = device,
                    Resolution = new Size(resolution, resolution),
                    Size       = new GhostscriptPageSize {
                        Native = pageSize
                    }
                };
                GhostscriptWrapper.GenerateOutput(inputPath, outputPath, ghostscriptSettings);

                Process.Start(outputPath);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Exemplo n.º 2
0
 public static void GetPdfThumbnail(string sourcePdfFilePath, string destinationPngFilePath, int StartPage = 1, int EndPage = 1, GhostscriptPageSizes PageSize = GhostscriptPageSizes.a4)
 {
     // Use GhostscriptSharp to convert the pdf to a png
     GhostscriptWrapper.GenerateOutput(sourcePdfFilePath, destinationPngFilePath,
                                       new GhostscriptSettings
     {
         Device = GhostscriptDevices.pngalpha,
         Page   = new GhostscriptPages
         {
             // Only make a thumbnail of the first page
             Start    = StartPage,
             End      = EndPage,
             AllPages = false
         },
         Resolution = new Size
         {
             // Render at 72x72 dpi
             Height = 300,
             Width  = 300
         },
         Size = new GhostscriptPageSize
         {
             // The dimensions of the incoming PDF must be
             // specified. The example PDF is US Letter sized.
             Native = PageSize
         }
     }
                                       );
 }
Exemplo n.º 3
0
        private static void PdfToJpg(string path, string fileName, GhostscriptDevices devise, GhostscriptPageSizes pageFormat, int qualityX, int qualityY)
        {
            var settingsForConvert = new GhostscriptSettings {
                Device = devise
            };
            var pageSize = new GhostscriptPageSize {
                Native = pageFormat
            };

            settingsForConvert.Size       = pageSize;
            settingsForConvert.Resolution = new System.Drawing.Size(qualityX, qualityY);

            GhostscriptWrapper.GenerateOutput(path, @"C:\YR\Receipt\" + fileName + "_" + ".jpg", settingsForConvert); // here you could set path and name for out put file.
        }