private void saveBtn_Click(object sender, EventArgs e) { string outputFile = outputTB.Text; if (pageList.Items.Count == 0) { MessageBox.Show("No pages were found to stitch. Please don't remove all pages from the list.", "No Pages To Stitch", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(outputFile)) { MessageBox.Show("Output File is missing.\n\nPlease specify the file you want to save before continuing.", "Output File Missing", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } loadBtn.Enabled = false; saveBtn.Enabled = false; saveBtn.Text = "Stitching..."; topBtn.Enabled = false; upBtn.Enabled = false; downBtn.Enabled = false; bottomBtn.Enabled = false; pageList.Enabled = false; removeBtn.Enabled = false; progressBar.Maximum = pageList.Items.Count; // was going to do this in a thread, but: // - backgroundworker conflicts with the shockwave activex object (backgroundworker isnt STA) // - thread was giving me grief // so yeah. might flicker a little, but it works PdfDocument doc = new PdfDocument(); // these worked for the book I was doing, might want to play with them double ratio = (658 / 568); int imageWidth = 1000; int imageHeight = (int)(imageWidth * ratio); // create new conversion form - we load the swf into an off-screen form // and return raw image data in a Bitmap using (ConvertForm cf = new ConvertForm()) { cf.SetOutputSize(imageWidth, imageHeight); cf.SetScalingMode(ConvertForm.ScalingModes.ExactFit); for (int i = 0; i < pageList.Items.Count; i++) { progressBar.Value = i + 1; // create full path to file string inputFile = inputTB.Text + Path.DirectorySeparatorChar + pageList.Items[i].ToString() + ".swf"; previewFlash.Movie = inputFile; previewFlash.Refresh(); // create new page PdfPage page = doc.AddPage(); page.Size = PdfSharp.PageSize.Letter; // GetBitmap does the actual conversion using (XGraphics gfx = XGraphics.FromPdfPage(page)) using (XImage ximage = XImage.FromGdiPlusImage(cf.GetBitmap(inputFile))) { // draw our image on the pdf page gfx.DrawImage(ximage, 0, 0, page.Width, page.Height); } } } // write pdf to outputFile doc.Save(outputFile); loadBtn.Enabled = true; saveBtn.Enabled = true; saveBtn.Text = "Save PDF"; topBtn.Enabled = true; upBtn.Enabled = true; downBtn.Enabled = true; bottomBtn.Enabled = true; pageList.Enabled = true; removeBtn.Enabled = true; if (MessageBox.Show("Processing finished! PDF file created:\n" + outputTB.Text + "\n\nOpen output file?", "Done!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Process.Start(outputFile); } }