Esempio n. 1
0
        private void pdf_to_word(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
        {
            Aspose.Pdf.Document document = null;
            int num = 0;

            if (fileType == ".pdf")
            {
                document = this.pdf_doc;
                num      = 0;
            }
            else if ((fileType == ".ppt") || (fileType == ".pptx"))
            {
                document = this.ppt_to_pdf(progress, dlg, 0);
                num      = 50;
            }
            else if ((fileType == ".xls") || (fileType == ".xlsx"))
            {
                document = this.xls_to_pdf(progress, dlg, 0);
                num      = 50;
            }
            Aspose.Words.Document document2 = new Aspose.Words.Document();
            Aspose.Pdf.Document   document3 = new Aspose.Pdf.Document();
            if (progress != null)
            {
                dlg.Invoke(progress, new object[] { num });
            }
            document2.ChildNodes.Clear();
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                try
                {
                    MemoryStream outputStream = new MemoryStream();
                    document3.Pages.Add(document.Pages[i]);
                    document3.Save(outputStream, Aspose.Pdf.SaveFormat.Doc);
                    document2.AppendDocument(new Aspose.Words.Document(outputStream), ImportFormatMode.KeepSourceFormatting);
                    document3.Pages.Delete();
                }
                catch (Exception)
                {
                    break;
                }
                if (progress != null)
                {
                    if (num == 50)
                    {
                        dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                    }
                    else
                    {
                        dlg.Invoke(progress, new object[] { (i * 100) / this.pdf_doc.Pages.Count });
                    }
                }
            }
            document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix());
            if (progress != null)
            {
                dlg.Invoke(progress, new object[] { 100 });
            }
        }
Esempio n. 2
0
        public void AppendAllDocumentsInFolder()
        {
            // Delete the file that was created by the previous run as I don't want to append it again.
            File.Delete(MyDir + "Document.AppendDocumentsFromFolder Out.doc");

            //ExStart
            //ExFor:Document.AppendDocument(Document, ImportFormatMode)
            //ExSummary:Shows how to use the AppendDocument method to combine all the documents in a folder to the end of a template document.
            // Lets start with a simple template and append all the documents in a folder to this document.
            Aspose.Words.Document baseDoc = new Aspose.Words.Document();

            // Add some content to the template.
            DocumentBuilder builder = new DocumentBuilder(baseDoc);
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
            builder.Writeln("Template Document");
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
            builder.Writeln("Some content here");

            // Gather the files which will be appended to our template document.
            // In this case we add the optional parameter to include the search only for files with the ".doc" extension.
            ArrayList files = new ArrayList(Directory.GetFiles(MyDir, "*.doc"));
            // The list of files may come in any order, let's sort the files by name so the documents are enumerated alphabetically.
            files.Sort();

            // Iterate through every file in the directory and append each one to the end of the template document.
            foreach (string fileName in files)
            {
                // We have some encrypted test documents in our directory, Aspose.Words can open encrypted documents
                // but only with the correct password. Let's just skip them here for simplicity.
                FileFormatInfo info = FileFormatUtil.DetectFileFormat(fileName);
                if (info.IsEncrypted)
                    continue;

                Aspose.Words.Document subDoc = new Aspose.Words.Document(fileName);
                baseDoc.AppendDocument(subDoc, ImportFormatMode.UseDestinationStyles);
            }

            // Save the combined document to disk.
            baseDoc.Save(MyDir + "Document.AppendDocumentsFromFolder Out.doc");
            //ExEnd
        }
Esempio n. 3
0
        public void AppendDocumentFromAutomation()
        {
            //ExStart
            //ExId:AppendDocumentFromAutomation
            //ExSummary:Shows how to join multiple documents together.
            // The document that the other documents will be appended to.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            // We should call this method to clear this document of any existing content.
            doc.RemoveAllChildren();

            int recordCount = 5;
            for (int i = 1; i <= recordCount; i++)
            {
                // Open the document to join.
                Aspose.Words.Document srcDoc = new Aspose.Words.Document(@"C:\DetailsList.doc");

                // Append the source document at the end of the destination document.
                doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);

                // In automation you were required to insert a new section break at this point, however in Aspose.Words we
                // don't need to do anything here as the appended document is imported as separate sectons already.

                // If this is the second document or above being appended then unlink all headers footers in this section
                // from the headers and footers of the previous section.
                if (i > 1)
                    doc.Sections[i].HeadersFooters.LinkToPrevious(false);
            }
            //ExEnd
        }
Esempio n. 4
0
        public void AppendDocument()
        {
            //ExStart
            //ExFor:Document.AppendDocument(Document, ImportFormatMode)
            //ExSummary:Shows how to append a document to the end of another document.
            // The document that the content will be appended to.
            Aspose.Words.Document dstDoc = new Aspose.Words.Document(MyDir + "Document.doc");
            // The document to append.
            Aspose.Words.Document srcDoc = new Aspose.Words.Document(MyDir + "DocumentBuilder.doc");

            // Append the source document to the destination document.
            // Pass format mode to retain the original formatting of the source document when importing it.
            dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

            // Save the document.
            dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");
            //ExEnd
        }
Esempio n. 5
0
        public static Aspose.Words.Document Populate(Aspose.Words.Document doc1, string path, ApplicationForm model)
        {
            DocumentBuilder b = new DocumentBuilder(doc1);

            b.PageSetup.PageStartingNumber = 1;
            b.PageSetup.PageNumberStyle    = NumberStyle.Number;

            b.MoveToDocumentStart();


            b.MoveToMergeField("ISO1");
            b.InsertCheckBox("ISO9001", (bool)model.ISO9001, 0);

            b.MoveToMergeField("ISO2");
            b.InsertCheckBox("ISO22301", (bool)model.ISO22301, 0);

            b.MoveToMergeField("ISO3");
            b.InsertCheckBox("ISO14001", (bool)model.ISO14001, 0);

            b.MoveToMergeField("ISO4");
            b.InsertCheckBox("BSOHSAS18001", (bool)model.BSOHSAS18001, 0);

            b.MoveToMergeField("ISO5");
            b.InsertCheckBox("ISO27001", (bool)model.ISO27001, 0);

            b.MoveToMergeField("OtherIso");
            b.InsertCheckBox("OtherIso", (bool)model.OtherIso, 0);

            b.MoveToMergeField("1");
            b.InsertCheckBox("1", (bool)model.ISO9001_2, 0);

            b.MoveToMergeField("2");
            b.InsertCheckBox("2", (bool)model.ISO22301_2, 0);

            b.MoveToMergeField("3");
            b.InsertCheckBox("3", (bool)model.ISO14001_2, 0);

            b.MoveToMergeField("4");
            b.InsertCheckBox("4", (bool)model.BSOHSAS18001_2, 0);

            b.MoveToMergeField("5");
            b.InsertCheckBox("5", (bool)model.ISO27001_2, 0);

            b.MoveToMergeField("6");
            b.InsertCheckBox("6", (bool)model.OtherIso_2, 0);



            b.MoveToMergeField("CompanyName");
            Aspose.Words.Font font = b.Font;
            font.Size = 14;
            font.Name = "Calibri";
            b.Write(model.CompanyName);

            b.MoveToMergeField("Address");
            b.Write(model.Adress);

            b.MoveToMergeField("Telephone");
            b.Write(model.Telephone);

            b.MoveToMergeField("Email");
            b.Write(model.Email);

            if (model.Extension != null)
            {
                b.MoveToMergeField("Extension");
                b.Write(model.Extension);
            }

            if (model.Other != null)
            {
                b.MoveToMergeField("Other");
                b.Write(model.Other);
            }

            if (model.Other_2 != null)
            {
                b.MoveToMergeField("Other_2");
                b.Write(model.Other_2);
            }


            if (model.CompanyWebsite != null)
            {
                b.MoveToMergeField("CompanyWebsite");
                b.Write(model.CompanyWebsite);
            }

            if (model.PrimaryContactForAuditPurposes != null)
            {
                b.MoveToMergeField("PrimaryContactForAuditPurposes");
                b.Write(model.PrimaryContactForAuditPurposes);
            }

            if (model.PrimaryContactTelephone != null)
            {
                b.MoveToMergeField("PrimaryContactTelephone");
                b.Write(model.PrimaryContactTelephone);
            }
            if (model.NatureOfBusiness != null)
            {
                b.MoveToMergeField("NatureOfBusiness");
                b.Write(model.NatureOfBusiness);
            }

            if (model.NumberOfYearsAtThisSite != null)
            {
                b.MoveToMergeField("NumberOfYearsAtThisSite");
                b.Write(model.NumberOfYearsAtThisSite);
            }

            if (model.ActivitiesOnClientsSites != null)
            {
                b.MoveToMergeField("ActivitiesOnClientsSites");
                b.Write(model.ActivitiesOnClientsSites);
                b.MoveToMergeField("yes");
                b.InsertCheckBox("yes", true, 0);
                b.MoveToMergeField("no");
                b.InsertCheckBox("yes", false, 0);
            }
            else
            {
                b.MoveToMergeField("yes");
                b.InsertCheckBox("yes", false, 0);
                b.MoveToMergeField("no");
                b.InsertCheckBox("yes", true, 0);
            }

            if (model.NameOfPresentCertificationBody != null)
            {
                b.MoveToMergeField("NameOfPresentCertificationBody");
                b.Write(model.NameOfPresentCertificationBody);
            }
            if (model.CertificateExpiryDate != null)
            {
                b.MoveToMergeField("CertificateExpiryDate");
                b.Write(model.CertificateExpiryDate);
            }

            if (model.ManagementRepresentativeName != null)
            {
                b.MoveToMergeField("ManagementRepresentativeName");
                b.Write(model.ManagementRepresentativeName);
            }
            if (model.JobTitle != null)
            {
                b.MoveToMergeField("JobTitle");
                b.Write(model.JobTitle);
            }

            if (model.NameOfConsultant != null)
            {
                b.MoveToMergeField("NameOfConsultant");
                b.Write(model.NameOfConsultant);
            }

            if (model.ConsultantTelephone != null)
            {
                b.MoveToMergeField("ConsultantTelephone");
                b.Write(model.ConsultantTelephone);
            }

            if (model.StandardTransferred != null)
            {
                b.MoveToMergeField("StandardTransferred");
                b.Write(model.StandardTransferred);
            }
            if (model.DateNextCertificationBodyVisit != null)
            {
                b.MoveToMergeField("DateNextCertificationBodyVisit");
                b.Write(model.DateNextCertificationBodyVisit);
            }
            if (model.NumberOfLocations != null)
            {
                b.MoveToMergeField("NumberOfLocations");
                b.Write(model.NumberOfLocations);
            }

            if (model.locationActivities.Count > 0)
            {
                foreach (var item in model.locationActivities)
                {
                    b.MoveToMergeField("location");
                    b.Write(item.location);
                    b.InsertParagraph();
                }
                foreach (var item in model.locationActivities)
                {
                    b.MoveToMergeField("activity");
                    b.Write(item.activity);
                    b.InsertParagraph();
                }
            }


            if (model.Categories.Count > 0)
            {
                foreach (var item in model.Categories)
                {
                    b.MoveToMergeField("Category");
                    if (item.Category != null)
                    {
                        b.Write(item.Category);
                        b.InsertParagraph();
                    }
                }
                foreach (var item in model.Categories)
                {
                    b.MoveToMergeField("TotalPermanent");
                    if (item.TotalPermanent != null)
                    {
                        b.Write(item.TotalPermanent);
                        b.InsertParagraph();
                    }
                }
                foreach (var item in model.Categories)
                {
                    b.MoveToMergeField("TotalTemporary");
                    if (item.TotalTemporary != null)
                    {
                        b.Write(item.TotalTemporary);
                        b.InsertParagraph();
                    }
                }
            }

            if (model.TotalPermanent != null)
            {
                b.MoveToMergeField("TotalP");
                b.Write(model.TotalPermanent);
            }


            if (model.TotalTemporary != null)
            {
                b.MoveToMergeField("TotalT");
                b.Write(model.TotalTemporary);
            }

            b.MoveToDocumentEnd();
            doc1.MailMerge.DeleteFields();



            if (model.ISO22301 == true || model.ISO9001 == true)
            {
                Aspose.Words.Document standardDoc = new Aspose.Words.Document(path + @"Templates\ISO_9001_22301_Template.doc");
                doc1.AppendDocument(standardDoc, ImportFormatMode.KeepSourceFormatting);
            }
            if (model.ISO14001 == true)
            {
                Aspose.Words.Document standardDoc = new Aspose.Words.Document(path + @"Templates\ISO_14001_Template.doc");
                doc1.AppendDocument(standardDoc, ImportFormatMode.KeepSourceFormatting);
            }
            if (model.BSOHSAS18001 == true)
            {
                Aspose.Words.Document standardDoc = new Aspose.Words.Document(path + @"Templates\BS_OHSAS_1800_Template.doc");
                doc1.AppendDocument(standardDoc, ImportFormatMode.KeepSourceFormatting);
            }

            if (model.ISO27001 == true)
            {
                Aspose.Words.Document standardDoc = new Aspose.Words.Document(path + @"Templates\ISO27001_Template.doc");
                doc1.AppendDocument(standardDoc, ImportFormatMode.KeepSourceFormatting);
            }



            return(doc1);
        }