예제 #1
0
        private void DumpMetas(string mask)
        {
            Cursor = Cursors.WaitCursor;

            _c1pdf.Clear();
            _c1pdf.Compression = C1.C1Pdf.CompressionEnum.None;
            //_c1pdf.Compression = C1.C1Pdf.CompressionEnum.BestCompression;
            Random rnd  = new Random();
            Font   font = new Font("Courier New", 9, FontStyle.Bold);

            // look for emf files in the executable directory
            string path  = Path.GetDirectoryName(Application.ExecutablePath);
            bool   first = true;

            string[] files = Directory.GetFiles(path, mask);
            foreach (string fileName in files)
            {
                statusBar1.Text = string.Format("Exporting {0}...", Path.GetFileName(fileName));
                Application.DoEvents();

                // new page
                if (!first)
                {
                    _c1pdf.NewPage();
                }
                first = false;

                // load metafile
                Metafile meta = (Metafile)Metafile.FromFile(fileName);

                // get metafile size in points
                SizeF szPage = GetImageSizeInPoints(meta);
                Console.WriteLine("Adding page {0:f2}\" x {1:f2}\"", szPage.Width / 72f, szPage.Height / 72f);

                // size page to metafile
                _c1pdf.PageSize = szPage;

                // draw metafile on the page
                RectangleF rc = _c1pdf.PageRectangle;
                _c1pdf.FillRectangle(Brushes.AntiqueWhite, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawString(fileName, font, Brushes.Black, rc);

                // draw thumbnail at random place
                rc.Width  /= 5;
                rc.Height /= 5;
                rc.X       = rnd.Next((int)(szPage.Width - rc.Width));
                rc.Y       = rnd.Next((int)(szPage.Height - rc.Height));
                _c1pdf.FillRectangle(Brushes.White, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawRectangle(Pens.Black, rc);

                // add outline entry if there's more than one page
                if (files.Length > 1)
                {
                    _c1pdf.AddBookmark(Path.GetFileName(fileName), 0, 0);
                }
            }

            // show the result
            statusBar1.Text = "Saving...";
            SaveAndShow(@"c:\temp\test\metas.pdf");
            Cursor          = Cursors.Default;
            statusBar1.Text = "Ready";
        }