コード例 #1
0
        private void Select_Click(object sender, EventArgs e)
        {
            FileDownloadClient client = new FileDownloadClient();
            string             ext    = "";

            Common.Models.Forms.Form     model;
            Common.Models.Matters.Matter matter;

            model  = (Common.Models.Forms.Form)FormResults.SelectedItem;
            matter = (Common.Models.Matters.Matter)MatterResults.SelectedItem;

            if (Path.HasExtension(model.Path))
            {
                ext = Path.GetExtension(model.Path);
            }

            // Save To
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.FileName        = DateTime.Now.ToString("yyyy-MM-dd") + " " + model.Title + ext;
            dialog.Filter          = "Word (*.docx,*.doc)|*.docx;*.doc|All files (*.*)|*.*";
            dialog.OverwritePrompt = true;
            DialogResult dr = dialog.ShowDialog();

            // Download
            if (dr == DialogResult.OK)
            {
                FileDownloadClient.DownloadFile(Globals.ThisAddIn.Settings.ServerUrl +
                                                "JsonInterface/DownloadForm/" + model.Id.Value, dialog.OpenFile());

                // Open
                Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.Documents.Open(dialog.FileName);


                // Fill
                Microsoft.Office.Core.COMAddIn addin = doc.Application.COMAddIns.Item(@"OpenLawOffice.Word");

                IAddInUtilities utils = (IAddInUtilities)addin.Object;

                utils.DownloadFormDataForMatter(matter.Id.Value);
            }
        }
コード例 #2
0
        internal static string PrintToFileWithPdfMaker(Word.Application app, Microsoft.Office.Core.COMAddIn add_in, string filename)
        {
            // Remove existing files in C:\scratch
            string pattern = @"\.docx*";

            // Create pdf filename
            var   pdfFileName = filename;
            Regex rx          = new Regex(pattern);

            if (rx.IsMatch(pdfFileName))
            {
                pdfFileName = rx.Replace(pdfFileName, @".pdf");
            }
            if (System.IO.File.Exists(pdfFileName))
            {
                System.IO.File.Delete(pdfFileName);
            }

            // Print to PDF, using method from VBA cockle
            try
            {
                // let Acrobat Distiller determine the filename
                PdfMaker.PDFMaker pmkr = null;

                if (!app.ActiveDocument.Saved)
                {
                    // problem: doc needs to be saved first
                }
                foreach (Microsoft.Office.Core.COMAddIn a in app.COMAddIns)
                {
                    if (a.Description.ToLower().Contains("pdfmaker"))
                    {
                        add_in = a;
                        pmkr   = a.Object;
                    }
                }

                object stng = null;
                pmkr.GetCurrentConversionSettings(out stng);
                // error handling here !!!
                var stng2 = (AdobePDFMakerForOffice.ISettings)stng;
                stng2.AddBookmarks             = true;
                stng2.AddLinks                 = true;
                stng2.AddTags                  = false;
                stng2.ConvertAllPages          = true;
                stng2.CreateFootnoteLinks      = false;
                stng2.CreateXrefLinks          = false;
                stng2.OutputPDFFileName        = pdfFileName;
                stng2.PromptForPDFFilename     = false;
                stng2.ShouldShowProgressDialog = false;
                stng2.ViewPDFFile              = false;

                int out_val;
                pmkr.CreatePDFEx(stng2, out out_val);

                while (add_in.Object != null)
                {
                    add_in.Object = null;
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine($"{filename} failed to print");
            }
            return(pdfFileName);
        }