예제 #1
0
        private void export_Click(object sender, System.EventArgs e)
        {
            bool     EmbedSource = cbEmbed.Checked;
            TPdfType PdfType     = GetPdfType();
            TTagMode TagMode     = GetTagMode();

            if (EmbedSource)
            {
                if (PdfType != TPdfType.PDFA3 && PdfType != TPdfType.Standard)
                {
                    MessageBox.Show("To embed a file, you need to use standard PDF or PDF/A3");
                    return;
                }
            }

            if (exportDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            CreateFile(exportDialog.FileName, EmbedSource, PdfType, TagMode);

            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Process.Start(exportDialog.FileName);
            }
        }
예제 #2
0
        private void CreateFile(string FileName, bool EmbedSource, TPdfType PdfType, TTagMode TagMode)
        {
            ExcelFile xls = CreateSourceFile();

            using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
            {
                pdf.PdfType = PdfType;
                pdf.TagMode = TagMode;
                if (EmbedSource)
                {
                    pdf.AttachFile("Report.xlsx", StandardMimeType.Xlsx, "This is the source file used to create the PDF", DateTime.Now, TPdfAttachmentKind.Source,
                                   delegate(TPdfAttachmentWriter attachWriter)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            xls.Save(ms, TFileFormats.Xlsx);
                            ms.Position = 0;
                            attachWriter.Write(ms);
                        }
                    });
                }
                pdf.Export(FileName);
            }
        }