コード例 #1
0
 //Getting the Designer to Export the Report on Menu Item "Export" click
 private void OnExport(object sender, EventArgs e)
 {
     if (ConfirmSaveChanges())
     {
         fileName = SaveFile("pdf files|*.pdf", ".pdf");
         SectionReport rpt = new SectionReport();
         XmlTextReader xtr = new XmlTextReader(reportName);
         rpt.LoadLayout(xtr);
         rpt.Run();
         Export.Pdf.Section.PdfExport PdfExport1 = new Export.Pdf.Section.PdfExport();
         PdfExport1.Export(rpt.Document, fileName);
         System.Diagnostics.Process.Start(fileName);
     }
 }
コード例 #2
0
        private void pdfExportButton_Click(object sender, EventArgs e)
        {
            Export.Pdf.Section.PdfExport oPDFExport = new Export.Pdf.Section.PdfExport();
            SaveFileDialog sfd       = new SaveFileDialog();
            Cursor         tmpCursor = Cursor;
            string         tempPath  = string.Empty;

            // Display the save dialog.

            sfd.Title = "PDF files should be saved with electronic signature"; //Title

            sfd.FileName = "DigitalSignature.pdf";                             // Name of the file for initial display
            sfd.Filter   = "PDF|*.pdf";                                        // Filter
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            try
            {
                // Change the cursor.
                Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                // Sets the type of signature.
                oPDFExport.Signature.VisibilityType = (VisibilityType)cmbVisibilityType.SelectedIndex;
                // Set the signature display area.
                oPDFExport.Signature.Stamp.Bounds = new RectangleF(0.05F, 0.05F, 4.0F, 0.9F);
                // Sets the character position of the signature text
                oPDFExport.Signature.Stamp.TextAlignment = Alignment.Left;

                oPDFExport.Signature.Stamp.Font = new Font("MS PGothic", 9, FontStyle.Regular, GraphicsUnit.Point, 128);

                // Set the rectangle in which the text is placed in the area that displays the signature.
                //  The coordinate specified in this property starts with the top left point, relative to the rectangular signature.
                oPDFExport.Signature.Stamp.TextRectangle = new RectangleF(1.2F, 0.0F, 2.8F, 0.9F);
                // Set the signature image.
                FileStream fs = new FileStream(Application.StartupPath + "..//..//..//Image//gc.bmp", FileMode.Open, FileAccess.Read);
                oPDFExport.Signature.Stamp.Image = new Bitmap(Image.FromStream(fs));
                fs.Close();
                // Set the display position of the signature image.
                oPDFExport.Signature.Stamp.ImageAlignment = Alignment.Center;
                // Set the rectangle image so that it is placed in the area that displays the signature.
                // The coordinate specified in this property starts with the top left point, relative to the rectangular signature.
                oPDFExport.Signature.Stamp.ImageRectangle = new RectangleF(0.0f, 0.0f, 1.0f, 0.9f);
                // Sets the password for the certificate and digital signature.
                // For X509Certificate2 class, etc. Please refer to the site of Microsoft.
                //  [X509Certificate2 クラス(System.Security.Cryptography.X509Certificates)]
                //  http://msdn.microsoft.com/ja-jp/library/system.security.cryptography.x509certificates.x509certificate2.aspx
                oPDFExport.Signature.Certificate = new X509Certificate2(Application.StartupPath + "..//..//..//GrapeCity.pfx", "password");
                //
                if (chkTimeStamp.Checked)
                {
                    oPDFExport.Signature.TimeStamp = new TimeStamp("http://tsa.safecreative.org:80", "", "");
                }
                // Sets the time stamp.
                oPDFExport.Signature.SignDate = new SignatureField <DateTime>(DateTime.Now, true);                       // Signing time
                oPDFExport.Signature.DistinguishedName.Visible = false;                                                  // Display whether or not the distinguished name
                oPDFExport.Signature.Contact = new SignatureField <string>("*****@*****.**", true); // Contact

                oPDFExport.Signature.Reason = new SignatureField <string>("Approval", true);

                // Reason

                oPDFExport.Signature.Location = new SignatureField <string>("Pittsburg", true);

                // Location
                tempPath = Path.GetTempFileName();
                // Export the file.
                oPDFExport.Export(arvMain.Document, tempPath);
                File.Move(tempPath, sfd.FileName);
                //Start the output file (Open)
                System.Diagnostics.Process.Start(sfd.FileName);
                // Display the notification message.
                MessageBox.Show(Resource.FinishExportMessage, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (PdfSigningException)
            {
                File.Delete(tempPath);
                MessageBox.Show(Resource.LimitMessage, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                // Replace the cursor
                Cursor = tmpCursor;
                Application.DoEvents();
                // End processing
                sfd.Dispose();
                oPDFExport.Dispose();
            }
        }