Beispiel #1
0
		static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			using (new WsActivationContext())
			{
				try
				{
					CommandLineParser parser = parser = new CommandLineParser(args);

					if (string.IsNullOrEmpty(parser.OutputFile))
					{
						Application.Run(new PdfSelectionDialog(parser.SelectedFiles.ToArray()));
					}
					else
					{
						List<WorkbookItem> items = Utilities.ConvertStringArrayToWorkbookItemListEx(parser.SelectedFiles.ToArray(), false);
						if (items.Count > 0)
						{
							PdfCombiner combiner = new PdfCombiner();
							combiner.SavePdf(items, parser.OutputFile, null);
						}
					}

				}
				catch (SystemException e)
				{
					WsMessage.ShowMessage(IntPtr.Zero, "Failed to combine documents: " + Environment.NewLine + "[" + e.Message + "]", MessageButtons.WsOK, MessageBranding.WsDefault, MessageType.WsErrorIcon, "", -1);
				}
			}
		}
Beispiel #2
0
        public void Combine()
        {
            List<WorkbookItem> items = new List<WorkbookItem>()
            {
                GetWorkbookItem("All.pdf", PageSelectionType.All),
                GetWorkbookItem("Even.pdf", PageSelectionType.Even),
                GetWorkbookItem("Odd.pdf", PageSelectionType.Odd),
                GetWorkbookItem("Range.pdf", PageSelectionType.All, "3,7-11, 20-25,26,29,33")
            };
            Assert.IsTrue(items.Count == 4);
            
            Dictionary<string, PageSelection> results;
            using (PdfCombiner combiner = new PdfCombiner())
            {
                results = combiner.CreateInterimPdfs(items, null);
            }
            Assert.IsTrue(results.Count == 4);

            Assert.IsTrue(Workshare.Pdf.Edit.PageCount(items[0].Pdf) == 33); // All
            Assert.IsTrue(Workshare.Pdf.Edit.PageCount(items[1].Pdf) == 16); // Even
            Assert.IsTrue(Workshare.Pdf.Edit.PageCount(items[2].Pdf) == 17); // Odd
            Assert.IsTrue(Workshare.Pdf.Edit.PageCount(items[3].Pdf) == 15); // Range = "3,7-11, 20-25,26,29,33"
            
            var target = Path.Combine(_path, "SavePdfResult.pdf");
            File.Delete(target);
            Assert.IsFalse(File.Exists(target));

            Dictionary<string, WorkbookItemInfo> source = new Dictionary<string, WorkbookItemInfo>();
            source.Add(items[0].Pdf, GetWorkbookItemInfo(items[0]));
            source.Add(items[1].Pdf, GetWorkbookItemInfo(items[1]));
            source.Add(items[2].Pdf, GetWorkbookItemInfo(items[2]));
            source.Add(items[3].Pdf, GetWorkbookItemInfo(items[3]));
                        
            using (PdfCombiner combiner = new PdfCombiner())
            {
                Assert.True(combiner.CreateFinalPdf(source, target, null));
            }

            Assert.IsTrue(Workshare.Pdf.Edit.PageCount(target) == (33 + 16 + 17 + 15));
        }
        public PdfSelectionDialog(string[] selectedFiles)
        {
            InitializeComponent();

            if ((selectedFiles != null) && (selectedFiles.Length > 0))
            {
                AddWorkbookItems(Utilities.ConvertStringArrayToWorkbookItemListEx(selectedFiles, true));

                Logger.LogTrace("Function:PdfSelectionDialog, File:PdfSelectionDialog.cs, Error: Cannot open .wwb file as length is ! > 0 or is null");
            }

            m_progressCallback = new ProgressCallback();
            m_progressCallback.ProgressUpdate += new OnProgressUpdate(m_progressCallback_ProgressUpdate);
            m_pdfCombine = new PdfCombiner(this);
            this.OnShowDialog += PdfSelectionDialog_OnShowDialog;
			cbPdfVersion.SelectedIndex = IsPDFAEnabled() ? (int) SaveAs.PDFA : (int) SaveAs.PDF;
        }