예제 #1
0
        public void TestPdfNotEmpty()
        {
            var xpsFilePath = "Resources\\tiger.xps";

            var exception = Assert.Throws <ArgumentNullException>(() => XpsConverter.Convert(xpsFilePath, null));

            StringAssert.Contains("Pdf file path can't be empty. Please, specify a valid pdf file path.", exception.Message);
        }
예제 #2
0
        public void TestFailedToOpenXps()
        {
            var xpsFilePath = "Resources\\wrong.xps";

            var exception = Assert.Throws <XpsConverterException>(() => XpsConverter.Convert(xpsFilePath));

            StringAssert.Contains($"Failed to open file '{xpsFilePath}'", exception.Message);
        }
예제 #3
0
        public void TestConvertFileWithSpacesInPath()
        {
            var xpsFilePath = "Resources\\file with spaces.xps";

            var pdfFilePath = "Resources\\file with spaces.pdf";

            XpsConverter.Convert(xpsFilePath);

            Assert.That(pdfFilePath, Does.Exist);
        }
예제 #4
0
        public void TestConvertWithXpsAndPdf()
        {
            var xpsFilePath = "Resources\\tiger.xps";

            var pdfFilePath = "Resources\\tiger.pdf";

            XpsConverter.Convert(xpsFilePath, pdfFilePath);

            Assert.That(pdfFilePath, Does.Exist);
        }
예제 #5
0
        public void TestConvertWithXpsOnly()
        {
            var xpsFilePath = "Resources\\analysis.xps";

            var pdfFilePath = "Resources\\analysis.pdf";

            XpsConverter.Convert(xpsFilePath);

            Assert.That(pdfFilePath, Does.Exist);
        }
예제 #6
0
        public static void ExportVisualAsPdf(MainWindowViewModel usefulDataVM)
        {
            //Set up the WPF Control to be printed
            UserControl1 controlToPrint;

            controlToPrint             = new UserControl1();
            controlToPrint.DataContext = usefulDataVM;


            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();



            fixedPage.Children.Add(controlToPrint);
            ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);



            SaveFileDialog sfd = new SaveFileDialog
            {
                DefaultExt = ".pdf",
                Filter     = "PDF Documents (.pdf)|*.pdf"
            };

            bool?result = sfd.ShowDialog();

            if (result != true)
            {
                return;
            }



            MemoryStream memoryStream = new MemoryStream();

            System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(memoryStream, FileMode.Create);
            XpsDocument       xpsDocument       = new XpsDocument(package);
            XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

            xpsDocumentWriter.Write(fixedPage);
            xpsDocument.Close();
            package.Close();

            var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(memoryStream);

            //public static void Convert(Stream xpsInStream, Stream pdfOutStream, bool closePdfStream);
            XpsConverter.Convert(pdfXpsDoc, sfd.FileName, 0);
            Process.Start(sfd.FileName);
        }
예제 #7
0
        //enum Page
        //{
        //    Next = 0,
        //    Back = 1
        //}
        //private void otherPage(Page page)
        //{
        //    if (page == Page.Back)
        //    {
        //        if (index > 0)
        //            index--;
        //        else
        //            index = tempPagesToShow.ToArray().Length - 1;
        //    }
        //    else if (page == Page.Next)
        //    {
        //        if (index < tempPagesToShow.ToArray().Length - 1)
        //            index++;
        //        else
        //            index = 0;
        //    }
        //    openthisinviewer(index);

        //}

        //private void button_Left_Click(object sender, RoutedEventArgs e)
        //{
        //    otherPage(Page.Back);
        //}

        //private void button_Right_Click(object sender, RoutedEventArgs e)
        //{
        //    otherPage(Page.Next);

        //}

        public void PrintPDF()
        {

            PdfDocument output = new PdfDocument();

            for (int i = 0; i < tempPagesToShow.Count(); i++)
            {

                FileStream fs = new FileStream(_pageurls[i],FileMode.Open);

                var pdfxpsdoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(fs);

                XpsConverter.Convert(pdfxpsdoc, pdfpath + _pagename[i] + ".pdf", 0);

                _pdfurls.Add(pdfpath + _pagename[i] + ".pdf");



                //File.Copy(_pageurls[i], xpspath + "topdf" + (i + 1).ToString() + ".xps", true);

                //var pdfxpsdoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(xpspath + "topdf" + (i + 1).ToString() + ".xps");

                //XpsConverter.Convert(pdfxpsdoc, pdfpath + _pagename[i] + ".pdf", 0);

                //_pdfurls.Add(pdfpath + _pagename[i] + ".pdf");


                pdfxpsdoc.Close();
                fs.Close();
                
            }

            foreach (string _pdfurl in _pdfurls)
            {
                using (PdfDocument input = PdfSharp.Pdf.IO.PdfReader.Open(_pdfurl, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import))
                {
                    output.Version = input.Version;
                    foreach (PdfPage page in input.Pages)
                    {
                        output.AddPage(page);  
                    }
                }

                System.IO.FileInfo oldpdf = new System.IO.FileInfo(_pdfurl);
                oldpdf.Delete();

            }

            System.IO.FileInfo[] files = new System.IO.DirectoryInfo(pdfpath).GetFiles("*" + pdfoutname + "*.pdf");

            string outputpath = "";

            if (files.Length > 0 && saveas)
            {

                outputpath = pdfpath + pdfoutname + "_" + files.Length + ".pdf";

            }
            else
            {
                outputpath = pdfpath + pdfoutname + ".pdf";
            }

            output.Save(outputpath);
            output.Dispose();




            //System.IO.FileInfo info = new System.IO.FileInfo(outputpath);

            /////pdfFileSize << 요놈
            //long pdfFileSize = info.Length;
            //Rhino.RhinoApp.WriteLine(pdfoutname + "size = " + pdfFileSize.ToString() + "bytes");




            ///서버업로드용 path 등록
            ///
            var dictionaryTempIndex = TuringAndCorbusierPlugIn.InstanceClass.turing.MainPanel_reportspaths[TuringAndCorbusierPlugIn.InstanceClass.turing.tempIndex];
            if (dictionaryTempIndex.ContainsKey("REPORT") == true)
            {
                var result = MessageBox.Show("이미 등록된 설계 보고서가 있습니다. 새 보고서를 서버에 저장하시겠습니까?", "설계 보고서 덮어쓰기", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    dictionaryTempIndex.Remove("REPORT");
                    dictionaryTempIndex.Add("REPORT", outputpath);
                    Rhino.RhinoApp.WriteLine("덮어쓰기 완료" + Environment.NewLine + "파일 경로 = " + outputpath);
                }
            }
            else
            { 
                dictionaryTempIndex.Add("REPORT", outputpath);
                Rhino.RhinoApp.WriteLine("등록 완료" + Environment.NewLine + "파일 경로 = " + outputpath);
            }

            //var result = MessageBox.Show("출력 끝  파일열기 / 경로열기 / 닫기 ", "PDF로 보고서 출력", MessageBoxButton.YesNoCancel);

            //if (result == MessageBoxResult.Yes)
            //{
            //    System.Diagnostics.Process ps = new System.Diagnostics.Process();
            //    ps.StartInfo.FileName = pdfoutname + ".pdf";
            //    ps.StartInfo.WorkingDirectory = pdfpath;
            //    ps.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

            //    ps.Start();
            //}
            //else if (result == MessageBoxResult.No)
            //{
            //    System.Diagnostics.Process.Start("explorer.exe", pdfpath);

            //}

            this.documentViewer.Document = null;

            //System.IO.File.OpenRead(outputpath);

            //foreach (string xpss in _pageurls)
            //{
            //    System.IO.File.Delete(xpss);
            //}

            //foreach (string pdfs in _pdfurls)
            //{
            //    System.IO.File.Delete(pdfs);
            //}





            //UIManager.getInstance().HideWindow(TuringAndCorbusierPlugIn.InstanceClass.showmewindow, UIManager.WindowType.Print);
            string filename = "";
            dictionaryTempIndex.TryGetValue("REPORT",out filename);

            System.Diagnostics.Process ps = new System.Diagnostics.Process();
            
            ps.StartInfo.WorkingDirectory = pdfpath;

            ps.StartInfo.FileName = filename.Replace(pdfpath, "");

            //MessageBox.Show(ps.StartInfo.FileName);


            ps.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
            ps.EnableRaisingEvents = true;
            ps.Start();

            return;

            Close();
            //MessageBox.Show(tempPagesToShow[index].ActualHeight.ToString() + " , " + tempPagesToShow[index].Height.ToString());

            
        }