public void CopyDocumentTo(ViewModels.DocumentViewModel source, ViewModels.DocumentViewModel target) { if (source == null || target == null) { return; } foreach (ViewModels.PageViewModel page in source.Pages) { target.Pages.Add(PageViewModel.MakeCopy(page)); } }
private ViewModels.DocumentViewModel CreateViewModelDocument(Models.Document document) { var documentViewModel = new ViewModels.DocumentViewModel(); documentViewModel.Id = document.Id; documentViewModel.Title = document.Title; documentViewModel.Link = document.Link; documentViewModel.Description = document.Description; documentViewModel.IconStyle = IconsList.GetIconTypeName(document.Type); return(documentViewModel); }
public void MovePageToDoc(ViewModels.PageViewModel page, ViewModels.DocumentViewModel oldDoc, ViewModels.DocumentViewModel newDoc) { if (!oldDoc.Pages.Contains(page)) { throw new KeyNotFoundException(page + " not contained within " + oldDoc.Pages); } if (null == oldDoc) { throw new NullReferenceException("oldDoc"); } if (null == newDoc) { throw new NullReferenceException("newDoc"); } oldDoc.Pages.Remove(page); newDoc.Pages.Add(page); }
public void SplitDocument(ViewModels.DocumentViewModel docVM, int splitInterval) { ViewModels.DocumentViewModel newDocVM; Models.Document newDoc; int docCount = 0; if (docVM == null || splitInterval <= 0) { return; } newDocVM = docVM; //newDoc = new Models.Document(); //newDocVM = new DocumentViewModel(newDoc); while (docVM.PageCount > splitInterval) { // current doc VM reached its goal page-count - start the next one... if (newDocVM.PageCount >= splitInterval) { newDoc = new Models.Document(); newDoc.fName = docVM.DocName; //newDoc.Rename("-" + (++docCount), true); newDoc.Rename("." + (++docCount) + "-" + (newDoc.id), true); newDoc.image = docVM.Pages[0].Image; newDocVM = new DocumentViewModel(newDoc); //RenameDoc(newDocVM, docVM.DocName, true); Documents.Add(newDocVM); //docCount++; } else { newDocVM.Pages.Add(docVM.Pages[splitInterval]); docVM.Pages.RemoveAt(splitInterval); } } }
public static void SaveDocument(ViewModels.DocumentViewModel document) { if (document == null) { return; } // Default file type is 'PDF' if none provided in docName (ext was omited) string ext = ""; if (string.IsNullOrEmpty(ParseExtension(document.DocName))) { ext = ".PDF"; } BaseFileIOStrategy strategy = GetValidIOStrategy(document.DocName + ext); if (strategy == null) { return; } strategy.SaveDocument(document); }
public void Handle(ActivateDocumentEvent message) { _activeDocument = message.Document; }
public override void SaveDocument(ViewModels.DocumentViewModel document) { string srcDocPath; string targetFilePath = SafeFilePath(document.DocName); Stream stream; iTextSharp.text.Image image; PdfDictionary pageDict; PdfImportedPage importedPage; PdfContentByte contentByte; //iTextSharp.text.Paragraph para; PdfCopy targetPdf; iTextSharp.text.Document doc; //iTextSharp.text.pdf.BaseFont baseFont; //iTextSharp.text.Font font; PdfReader srcReader; //ColumnText ct; PdfCopy.PageStamp pageStamp; try { if (!Directory.Exists(Path.GetDirectoryName(targetFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetFilePath)); } stream = new FileStream(targetFilePath, FileMode.Create); doc = new iTextSharp.text.Document(); targetPdf = new PdfCopy(doc, stream); doc.Open(); //baseFont = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.TIMES_ROMAN, iTextSharp.text.pdf.BaseFont.CP1252, false); //font = new iTextSharp.text.Font(baseFont, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); foreach (ViewModels.PageViewModel vm in document.Pages) { srcDocPath = FileIO.ToTempFileName(vm.DocName); // Copy pageDict from source... if (Path.GetExtension(srcDocPath).ToUpperInvariant() == ".PDF") { srcReader = new iTextSharp.text.pdf.PdfReader(srcDocPath); pageDict = srcReader.GetPageN(vm.Number); importedPage = targetPdf.GetImportedPage(srcReader, vm.Number); pageStamp = targetPdf.CreatePageStamp(importedPage); //add any strings foreach (Common.UIString str in vm.Strings) { ColumnText.ShowTextAligned(pageStamp.GetOverContent(), iTextSharp.text.Element.ALIGN_LEFT, new iTextSharp.text.Phrase(str.String), (float)str.X, (float)(importedPage.Height - str.Y - (str.Height * 0.75)), 0); } // apply any added rotation pageDict.Put(PdfName.ROTATE, new PdfNumber((vm.FlatRotation) % 360f)); pageStamp.AlterContents(); targetPdf.AddPage(importedPage); targetPdf.FreeReader(srcReader); srcReader.Close(); } if (vm.ImageStream != null && targetPdf.NewPage()) { contentByte = new PdfContentByte(targetPdf); image = iTextSharp.text.Image.GetInstance(vm.ImageStream); image.ScalePercent(72f / image.DpiX * 100); image.SetAbsolutePosition(0, 0); contentByte.AddImage(image); contentByte.ToPdf(targetPdf); } } targetPdf.Close(); doc.Close(); stream.Close(); } catch (System.IO.IOException e) { Toolbox.MessageBox(e.Message); } catch (Exception e) { Toolbox.MessageBoxException(e); } finally { //if (targetPdf != null) // targetPdf.Close(); //doc.Close(); //memStream.Close(); } }
public override void SaveDocument(ViewModels.DocumentViewModel document) { throw new NotImplementedException(); }
public abstract void SaveDocument(ViewModels.DocumentViewModel document);
private ViewModels.DocumentViewModel CreateViewModelDocument(Models.Document document) { var documentViewModel = new ViewModels.DocumentViewModel(); documentViewModel.Id = document.Id; documentViewModel.Title = document.Title; documentViewModel.Link = document.Link; documentViewModel.Description = document.Description; documentViewModel.IconStyle = IconsList.GetIconTypeName(document.Type); return documentViewModel; }