コード例 #1
1
        public static void Run()
        {
            // ExStart:SetExpiryDate 
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Instantiate Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // Add page to pages collection of PDF file
            doc.Pages.Add();
            // Add text fragment to paragraphs collection of page object
            doc.Pages[1].Paragraphs.Add(new TextFragment("Hello World..."));
            // Create JavaScript object to set PDF expiry date
            JavascriptAction javaScript = new JavascriptAction(
            "var year=2017;"
            + "var month=5;"
            + "today = new Date(); today = new Date(today.getFullYear(), today.getMonth());"
            + "expiry = new Date(year, month);"
            + "if (today.getTime() > expiry.getTime())"
            + "app.alert('The file is expired. You need a new one.');");
            // Set JavaScript as PDF open action
            doc.OpenAction = javaScript;

            dataDir = dataDir + "SetExpiryDate_out.pdf";
            // Save PDF Document
            doc.Save(dataDir);
            // ExEnd:SetExpiryDate 
            Console.WriteLine("\nPDF expiry date setup successfully.\nFile saved at " + dataDir);
        }
コード例 #2
0
        private void GenerateTicket()
        {
            var pdf = new Aspose.Pdf.Document();
            //Add a page to the document
            var pdfTicketPage = pdf.Pages.Add();

            var strBody  = Session["TicketBody"].ToString();
            var fragment = new Aspose.Pdf.Text.TextFragment(strBody.ToString());

            pdfTicketPage.Paragraphs.Add(fragment);

            DirectoryInfo dir      = new DirectoryInfo(@"D:\Images\");
            FileInfo      fileInfo = dir.GetFiles("*.jpg").FirstOrDefault();

            FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open);

            System.Drawing.Image img = new System.Drawing.Bitmap(stream);
            var image = new Aspose.Pdf.Image {
                ImageStream = stream
            };

            image.FixHeight = 125;
            image.FixWidth  = 300;
            image.Margin    = new MarginInfo(5, 5, 5, 5);
            pdfTicketPage.Paragraphs.Add(image);

            pdf.Save(@"D:\Images\Ticket.pdf");
            sendEmail();
        }
コード例 #3
0
ファイル: DocumentsController.cs プロジェクト: Hugoberry/WEB
        private byte[] MergeFile(IList <byte[]> files)
        {
            var mergedDocument = new Document();
            var streams        = new List <MemoryStream>();

            foreach (var fileInfo in files)
            {
                var stream   = new MemoryStream(fileInfo);
                var document = new Document(stream);

                for (var page = 1; page <= document.Pages.Count; page++)
                {
                    mergedDocument.Pages.Add(document.Pages[page]);
                }
                streams.Add(stream);
            }

            //// Save merged document.
            using (MemoryStream output = new MemoryStream())
            {
                mergedDocument.Save(output, SaveFormat.Pdf);


                foreach (var stream in streams)
                {
                    stream.Close();
                    stream.Dispose();
                }

                return(output.ToArray());
            }
        }
コード例 #4
0
        public static void Run()
        {
            // ExStart:EmbedFontWhileDocCreation 
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Instantiate Pdf object by calling its empty constructor
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

            // Create a section in the Pdf object
            Aspose.Pdf.Page page = doc.Pages.Add();

            Aspose.Pdf.Text.TextFragment fragment = new Aspose.Pdf.Text.TextFragment("");

            Aspose.Pdf.Text.TextSegment segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font.");
            Aspose.Pdf.Text.TextState ts = new Aspose.Pdf.Text.TextState();
            ts.Font = FontRepository.FindFont("Arial");
            ts.Font.IsEmbedded = true;
            segment.TextState = ts;
            fragment.Segments.Add(segment);
            page.Paragraphs.Add(fragment);

            dataDir = dataDir + "EmbedFontWhileDocCreation_out.pdf";
            // Save PDF Document
            doc.Save(dataDir);
            // ExEnd:EmbedFontWhileDocCreation 
            Console.WriteLine("\nFont embedded successfully in a PDF file.\nFile saved at " + dataDir);
        }
コード例 #5
0
        private static void CreateTemplate(SkuPdfModel model)
        {
            var pdfDocument = new Document();

            using var imageStore = new ImageStore();
            var page = pdfDocument.Pages.Add();

            // Header Table
            var headerTable = CreateHeaderTable(model, imageStore);

            page.Paragraphs.Add(headerTable);

            // Characteristic Table
            var characteristicTable = CreateCharacteristicTable(model);

            page.Paragraphs.Add(characteristicTable);

            // Classification Table
            var classificationTable = CreateClassificationTable(model);

            page.Paragraphs.Add(classificationTable);

            // Classification Table
            var supplierOffersTable = CreateSupplierOffersTable(model);

            page.Paragraphs.Add(supplierOffersTable);


            using var resultStream = File.Open("D:\\WorkAsposeFiles\\template.pdf", FileMode.Create);
            pdfDocument.Save(resultStream, SaveFormat.Pdf);
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "input.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            // Save updated document containing table object
            doc.Save(dataDir+ "document_with_table.pdf");
        }
コード例 #7
0
        public static void Run()
        {
            // ExStart:AddTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "AddTable.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // Add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // Add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            dataDir = dataDir + "document_with_table_out.pdf";
            // Save updated document containing table object
            doc.Save(dataDir);
            // ExEnd:AddTable
            Console.WriteLine("\nText added successfully to an existing pdf file.\nFile saved at " + dataDir);            
        }
コード例 #8
0
        public bool AddDigitalSignature(Pages PageObj, List <ImageSignParameters> ImgParamObj)
        {
            var pdfDocument = new Aspose.Pdf.Document(PageObj.FilePath);

            foreach (ImageSignParameters obj in ImgParamObj)
            {
                //add image signature parameters to database
                _documentRepository.AddSignatureToDB(obj);


                Stream     stream     = new MemoryStream(obj.ImageStream);
                ImageStamp imageStamp = new ImageStamp(stream);
                imageStamp.Background = true;
                // imageStamp.VerticalAlignment = VerticalAlignment.Top;
                imageStamp.XIndent = obj.XIndent;
                imageStamp.YIndent = obj.YIndent;
                imageStamp.Height  = obj.Height;
                imageStamp.Width   = obj.Width;
                imageStamp.Opacity = obj.Opacity;
                pdfDocument.Pages[obj.PageNumber].AddStamp(imageStamp);
            }
            pdfDocument.Save(string.Format("D:\\ElectronicSignaturesService\\BusinessLogic\\Files\\Sign1{0}.pdf", DateTime.Now.Ticks));

            return(true);
        }
コード例 #9
0
ファイル: Security.cs プロジェクト: killbug2004/WSProf
 internal void Add(string file, string password)
 {
     var document = new AsposePdf.Document(file);
     dynamic permissions = document.Permissions;
     document.Encrypt(password, OptionApi.GetEncrypted("PDFDefaultOwnerPassword", "?|2^&(*$:@!!*"),(AsposePdf.Permissions) permissions, AsposePdf.CryptoAlgorithm.RC4x40);
     document.Save(file);
 }
コード例 #10
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            // Save updated document containing table object
            doc.Save(dataDir + "document_with_table.pdf");
        }
コード例 #11
0
        public PDocument(string fileFullName, HDocument hDocument)
        {
            /*
             * //DEBUG
             * PDocument_debug(fileFullName, hDocument);
             * return;
             */


            bodyNode = hDocument.BodyNode;

            pageTextState = PUtil.TextStateUtil.TextState_Default();
            PUtil.TextStateUtil.TextState_ModifyFromHStyles((bodyNode as HNodeTag).Styles, pageTextState);

            pageMargin     = new MarginInfo(4, 4, 4, 12);
            pageBackground = Aspose.Pdf.Color.FromRgb(1.00, 1.00, 1.00);

            pdfDocument           = new Document();
            pdfPage               = null;
            pdfTextFragment       = null;
            pdfImage              = null;
            hyperlinkNode         = null;
            pdfNewLine            = null;
            inlineParagraphMargin = null;
            pdfFormField          = null;
            pdfRadioButtonFields  = new Dictionary <string, RadioButtonField>();

            updateCurrentPage();
            createBody();

            pdfDocument.Save(fileFullName);
        }
コード例 #12
0
        /// <summary>
        /// Written by Fredio
        /// </summary>
        /// <param name="path"></param>
        /// <param name="phrase"></param>
        /// <returns></returns>
        public System.IO.MemoryStream SearcText(string path, string phrase)
        {
            InjectAsposeLicemse();

            Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
            string searchTextValue       = string.Format("(?i){0}", phrase);
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchTextValue, new TextSearchOptions(true));

            //TextSearchOptions textSearchOptions = new TextSearchOptions(true);
            //textFragmentAbsorber.TextSearchOptions = textSearchOptions;
            document.Pages.Accept(textFragmentAbsorber);
            TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber.TextFragments;

            if (textFragmentCollection1.Count > 0)
            {
                foreach (TextFragment textFragment in textFragmentCollection1)
                {
                    Aspose.Pdf.Annotations.HighlightAnnotation freeText = new Aspose.Pdf.Annotations.HighlightAnnotation(textFragment.Page, new Aspose.Pdf.Rectangle(textFragment.Position.XIndent, textFragment.Position.YIndent, textFragment.Position.XIndent + textFragment.Rectangle.Width, textFragment.Position.YIndent + textFragment.Rectangle.Height));
                    freeText.Opacity = 0.5;
                    //freeText.Color = Aspose.Pdf.Color.FromRgb(0.6, 0.8, 0.98);
                    freeText.Color = Aspose.Pdf.Color.Yellow;
                    textFragment.Page.Annotations.Add(freeText);
                }
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            document.Save(ms);
            return(ms);
        }
コード例 #13
0
        public static void Run()
        {
            // ExStart:PreserveRights
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // Read the source PDF form with FileAccess of Read and Write.
            // We need ReadWrite permission because after modification,
            // we need to save the updated contents in same document/file.
            FileStream fs = new FileStream(dataDir + "input.pdf", FileMode.Open, FileAccess.ReadWrite);

            // Instantiate Document instance
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
            // Get values from all fields
            foreach (Field formField in pdfDocument.Form)
            {
                // If the fullname of field contains A1, perform the operation
                if (formField.FullName.Contains("A1"))
                {
                    // Cast form field as TextBox
                    TextBoxField textBoxField = formField as TextBoxField;
                    // Modify field value
                    textBoxField.Value = "Testing";
                }
            }
            // Save the updated document in save FileStream
            pdfDocument.Save();
            // Close the File Stream object
            fs.Close();
            // ExEnd:PreserveRights
        }
コード例 #14
0
        /// <summary>
        /// 將 PDF 加上 浮水印
        /// </summary>
        /// <param name="pdfStream"></param>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static MemoryStream AddWatermark(MemoryStream pdfStream, WatermarkArg arg)
        {
            var pdfDocument = new Aspose.Pdf.Document(pdfStream);

            if (!string.IsNullOrWhiteSpace(arg.Watermark))
            {
                var text = new FormattedText(arg.Watermark);
                foreach (var page in pdfDocument.Pages)
                {
                    switch (arg.WMStyle)
                    {
                    case WatermarkStyle.FitPage:
                        AddWatermarkFitPage(page, arg);
                        break;

                    case WatermarkStyle.RepeatHorizontal:
                        AddWatermarkRepeatHorizontal(page, arg);
                        break;

                    default:
                        break;
                    }
                }
            }
            var newPdfStream = new MemoryStream();

            pdfDocument.Save(newPdfStream);
            return(newPdfStream);
        }
コード例 #15
0
        //
        // Debug methods
        // for testing functionality Aspose.PDF
        //

        public void PDocument_debug(string fileFullName, HDocument hDocument)
        {
            //throw new PException("file " + fileFullName + " is busy.");

            //debug_helloWorld(fileFullName);
            //debug_createImage(fileFullName);
            //debug_createText(fileFullName);

            //debug_createP(fileFullName);



            pdfDocument = new Document();


            //PExample.Form1(pdfDocument);

            //PExample.Text1(pdfDocument);
            //PExample.Text2(pdfDocument);
            //PExample.Text3(pdfDocument);
            PExample.Text4(pdfDocument);

            //pdfPage = pdfDocument.Pages.Add();
            //PExample.Graph1(pdfPage);
            //PExample.Graph2(pdfPage);
            //PExample.Graph3(pdfPage);
            //PExample.Graph4(pdfPage);


            pdfDocument.Save(fileFullName);
        }
コード例 #16
0
        public string Converter(string path, string extension)
        {
            string reuturnString = string.Empty;
            // Save the document to a MemoryStream object.
            MemoryStream stream = new MemoryStream();


            switch (extension)
            {
            case ".pdf":

                Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);
                pdfDoc.Save(HttpContext.Current.Server.MapPath("Input/input.html"), Aspose.Pdf.SaveFormat.Html);
                break;

            case ".doc":
            case ".docx":
            case ".txt":
            case ".rtf":
            {
                //// Load in the document
                Aspose.Words.Document doc = new Aspose.Words.Document(path);
                doc.Save(HttpContext.Current.Server.MapPath("Input/input.html"), Aspose.Words.SaveFormat.Html);
                break;
            }
            }

            reuturnString = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("Input/input.html"));
            return(reuturnString);
        }
コード例 #17
0
        public static void Run()
        {
            // ExStart:EmbedFontWhileDocCreation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Instantiate Pdf object by calling its empty constructor
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

            // Create a section in the Pdf object
            Aspose.Pdf.Page page = doc.Pages.Add();

            Aspose.Pdf.Text.TextFragment fragment = new Aspose.Pdf.Text.TextFragment("");

            Aspose.Pdf.Text.TextSegment segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font.");
            Aspose.Pdf.Text.TextState   ts      = new Aspose.Pdf.Text.TextState();
            ts.Font            = FontRepository.FindFont("Arial");
            ts.Font.IsEmbedded = true;
            segment.TextState  = ts;
            fragment.Segments.Add(segment);
            page.Paragraphs.Add(fragment);

            dataDir = dataDir + "EmbedFontWhileDocCreation_out_.pdf";
            // Save PDF Document
            doc.Save(dataDir);
            // ExEnd:EmbedFontWhileDocCreation
            Console.WriteLine("\nFont embedded successfully in a PDF file.\nFile saved at " + dataDir);
        }
コード例 #18
0
        public static void Run()
        {
            // ExStart:AddTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Load source PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "AddTable.pdf");
            // Initializes a new instance of the Table
            Aspose.Pdf.Table table = new Aspose.Pdf.Table();
            // Set the table border color as LightGray
            table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Set the border for table cells
            table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Create a loop to add 10 rows
            for (int row_count = 1; row_count < 10; row_count++)
            {
                // Add row to table
                Aspose.Pdf.Row row = table.Rows.Add();
                // Add table cells
                row.Cells.Add("Column (" + row_count + ", 1)");
                row.Cells.Add("Column (" + row_count + ", 2)");
                row.Cells.Add("Column (" + row_count + ", 3)");
            }
            // Add table object to first page of input document
            doc.Pages[1].Paragraphs.Add(table);
            dataDir = dataDir + "document_with_table_out.pdf";
            // Save updated document containing table object
            doc.Save(dataDir);
            // ExEnd:AddTable
            Console.WriteLine("\nText added successfully to an existing pdf file.\nFile saved at " + dataDir);
        }
コード例 #19
0
        public static void Run()
        {
            // ExStart:SetExpiryDate
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Instantiate Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // Add page to pages collection of PDF file
            doc.Pages.Add();
            // Add text fragment to paragraphs collection of page object
            doc.Pages[1].Paragraphs.Add(new TextFragment("Hello World..."));
            // Create JavaScript object to set PDF expiry date
            JavascriptAction javaScript = new JavascriptAction(
                "var year=2017;"
                + "var month=5;"
                + "today = new Date(); today = new Date(today.getFullYear(), today.getMonth());"
                + "expiry = new Date(year, month);"
                + "if (today.getTime() > expiry.getTime())"
                + "app.alert('The file is expired. You need a new one.');");

            // Set JavaScript as PDF open action
            doc.OpenAction = javaScript;

            dataDir = dataDir + "SetExpiryDate_out.pdf";
            // Save PDF Document
            doc.Save(dataDir);
            // ExEnd:SetExpiryDate
            Console.WriteLine("\nPDF expiry date setup successfully.\nFile saved at " + dataDir);
        }
コード例 #20
0
        public static void Run()
        {
            // ExStart:PreserveRights
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // Read the source PDF form with FileAccess of Read and Write.
            // We need ReadWrite permission because after modification,
            // We need to save the updated contents in same document/file.
            FileStream fs = new FileStream(dataDir + "input.pdf", FileMode.Open, FileAccess.ReadWrite);
            // Instantiate Document instance
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
            // Get values from all fields
            foreach (Field formField in pdfDocument.Form)
            {
                // If the fullname of field contains A1, perform the operation
                if (formField.FullName.Contains("A1"))
                {
                    // Cast form field as TextBox
                    TextBoxField textBoxField = formField as TextBoxField;
                    // Modify field value
                    textBoxField.Value = "Testing";
                }
            }
            // Save the updated document in save FileStream
            pdfDocument.Save();
            // Close the File Stream object
            fs.Close();
            // ExEnd:PreserveRights            
        }
コード例 #21
0
ファイル: Convert.cs プロジェクト: vaginessa/open
        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 });
            }
        }
コード例 #22
0
        public int Process(string sourcePath, string targetPath, int currentPage, string originalDocumentName)
        {
            var pdfDocument = new Aspose.Pdf.Document(sourcePath);
            var docFileName = targetPath.Split('\\');
            pdfDocument.Save(targetPath.Replace(docFileName[docFileName.Length - 1], docFileName[docFileName.Length - 1].ToLower().Replace(".pdf", ".docx")), SaveFormat.DocX);

            return pdfDocument.Pages.Count;
        }
コード例 #23
0
        //===================================================================================================== Generate documents

        protected Stream GetPreviewImagesPdfStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Pdf);

            try
            {
                var ms       = new MemoryStream();
                var pdf      = new Pdf();
                var document = new Aspose.Pdf.Document(pdf);
                var index    = 1;

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, restrictionType: restrictionType))
                    {
                        int newWidth;
                        int newHeight;

                        ComputeResizedDimensions((int)previewImage["Width"], (int)previewImage["Height"], PREVIEW_PDF_WIDTH, PREVIEW_PDF_HEIGHT, out newWidth, out newHeight);

                        var imageStamp = new ImageStamp(imgStream)
                        {
                            TopMargin           = 10,
                            HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
                            VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top,
                            Width  = newWidth,
                            Height = newHeight
                        };

                        try
                        {
                            var page = index == 1 ? document.Pages[1] : document.Pages.Add();
                            page.AddStamp(imageStamp);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            Logger.WriteException(new Exception("Error during pdf generation. Path: " + previewImage.Path, ex));
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }

            return(null);
        }
コード例 #24
0
ファイル: Convert.cs プロジェクト: vaginessa/open
        private void pdf_to_excel(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
        {
            Aspose.Pdf.Document document = null;
            int num = 0;

            try
            {
                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 == ".doc") || (fileType == ".docx"))
                {
                    document = this.doc_to_pdf(progress, dlg, 0);
                    num      = 50;
                }
                Workbook            workbook  = new Workbook();
                Aspose.Pdf.Document document2 = new Aspose.Pdf.Document();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
                workbook.Worksheets.Clear();
                for (int i = 1; i <= document.Pages.Count; i++)
                {
                    MemoryStream outputStream = new MemoryStream();
                    document2.Pages.Add(document.Pages[i]);
                    document2.Save(outputStream, Aspose.Pdf.SaveFormat.Excel);
                    Workbook workbook2 = new Workbook(outputStream);
                    workbook.Worksheets.Add(i.ToString());
                    workbook.Worksheets[i - 1].Copy(workbook2.Worksheets[0]);
                    document2.Pages.Delete();
                    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 });
                        }
                    }
                }
                workbook.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".xls");
            }
            catch (Exception)
            {
            }
        }
コード例 #25
0
        public IActionResult AsposePDF()
        {
            using (var stream = new MemoryStream())
            {
                var pdf = new Aspose.Pdf.Document(stream);
                pdf.Save("", SaveFormat.Html);
            }

            return(View());
        }
コード例 #26
0
        public static void Run()
        {
            // ExStart:AddingDifferentHeaders
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open source document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "AddingDifferentHeaders.pdf");

            // Create three stamps
            Aspose.Pdf.TextStamp stamp1 = new Aspose.Pdf.TextStamp("Header 1");
            Aspose.Pdf.TextStamp stamp2 = new Aspose.Pdf.TextStamp("Header 2");
            Aspose.Pdf.TextStamp stamp3 = new Aspose.Pdf.TextStamp("Header 3");

            // Set stamp alignment (place stamp on page top, centered horiznotally)
            stamp1.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            stamp1.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Specify the font style as Bold
            stamp1.TextState.FontStyle = FontStyles.Bold;
            // Set the text fore ground color information as red
            stamp1.TextState.ForegroundColor = Color.Red;
            // Specify the font size as 14
            stamp1.TextState.FontSize = 14;

            // Now we need to set the vertical alignment of 2nd stamp object as Top
            stamp2.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // Set Horizontal alignment information for stamp as Center aligned
            stamp2.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Set the zooming factor for stamp object
            stamp2.Zoom = 10;

            // Set the formatting of 3rd stamp object
            // Specify the Vertical alignment information for stamp object as TOP
            stamp3.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // Set the Horizontal alignment inforamtion for stamp object as Center aligned
            stamp3.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Set the rotation angle for stamp object
            stamp3.RotateAngle = 35;
            // Set pink as background color for stamp
            stamp3.TextState.BackgroundColor = Color.Pink;
            // Change the font face information for stamp to Verdana
            stamp3.TextState.Font = FontRepository.FindFont("Verdana");
            // First stamp is added on first page;
            doc.Pages[1].AddStamp(stamp1);
            // Second stamp is added on second page;
            doc.Pages[2].AddStamp(stamp2);
            // Third stamp is added on third page.
            doc.Pages[3].AddStamp(stamp3);
            dataDir = dataDir + "multiheader_out.pdf";
            // Save the updated document
            doc.Save(dataDir);
            // ExEnd:AddingDifferentHeaders 
            Console.WriteLine("\nDifferent headers added successfully.\nFile saved at " + dataDir);
        }
コード例 #27
0
        public static void Run()
        {
            // ExStart:AddingDifferentHeaders
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open source document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "AddingDifferentHeaders.pdf");

            // Create three stamps
            Aspose.Pdf.TextStamp stamp1 = new Aspose.Pdf.TextStamp("Header 1");
            Aspose.Pdf.TextStamp stamp2 = new Aspose.Pdf.TextStamp("Header 2");
            Aspose.Pdf.TextStamp stamp3 = new Aspose.Pdf.TextStamp("Header 3");

            // Set stamp alignment (place stamp on page top, centered horiznotally)
            stamp1.VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top;
            stamp1.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Specify the font style as Bold
            stamp1.TextState.FontStyle = FontStyles.Bold;
            // Set the text fore ground color information as red
            stamp1.TextState.ForegroundColor = Color.Red;
            // Specify the font size as 14
            stamp1.TextState.FontSize = 14;

            // Now we need to set the vertical alignment of 2nd stamp object as Top
            stamp2.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // Set Horizontal alignment information for stamp as Center aligned
            stamp2.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Set the zooming factor for stamp object
            stamp2.Zoom = 10;

            // Set the formatting of 3rd stamp object
            // Specify the Vertical alignment information for stamp object as TOP
            stamp3.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // Set the Horizontal alignment inforamtion for stamp object as Center aligned
            stamp3.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // Set the rotation angle for stamp object
            stamp3.RotateAngle = 35;
            // Set pink as background color for stamp
            stamp3.TextState.BackgroundColor = Color.Pink;
            // Change the font face information for stamp to Verdana
            stamp3.TextState.Font = FontRepository.FindFont("Verdana");
            // First stamp is added on first page;
            doc.Pages[1].AddStamp(stamp1);
            // Second stamp is added on second page;
            doc.Pages[2].AddStamp(stamp2);
            // Third stamp is added on third page.
            doc.Pages[3].AddStamp(stamp3);
            dataDir = dataDir + "multiheader_out_.pdf";
            // Save the updated document
            doc.Save(dataDir);
            // ExEnd:AddingDifferentHeaders
            Console.WriteLine("\nDifferent headers added successfully.\nFile saved at " + dataDir);
        }
コード例 #28
0
ファイル: AsposePdfComponent.cs プロジェクト: wingfay/studio
        public void FromXps(string absoluteFilePath, string outputPath)
        {
            // Instantiate LoadOption object using XPS load option
            Aspose.Pdf.LoadOptions options = new XpsLoadOptions();

            // Create document object
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(absoluteFilePath, options);

            // Save the resultant PDF document
            document.Save(outputPath);
        }
コード例 #29
0
        public static string TestReadGAC(string path)
        {
            List <string> l           = new List <string>();
            Document      pdfDocument = new Aspose.Pdf.Document(path);

            // Get particular page
            Page pdfPage = (Page)pdfDocument.Pages[1];

            // Create text fragment
            TextFragment textFragment = new TextFragment("I------------------I");

            textFragment.Position = new Position(20, 585);

            // Set text properties
            textFragment.TextState.FontSize        = 12;
            textFragment.TextState.Font            = FontRepository.FindFont("TimesNewRoman");
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);

            // Create TextBuilder object
            TextBuilder textBuilder = new TextBuilder(pdfPage);

            // Append the text fragment to the PDF page
            textBuilder.AppendText(textFragment);



            #region

            // Create text fragment
            textFragment = new TextFragment("O------------------O");
            // textFragment.Position = new Position(20, 554);
            textFragment.Position = new Position(20, 556);

            // Set text properties
            textFragment.TextState.FontSize        = 12;
            textFragment.TextState.Font            = FontRepository.FindFont("TimesNewRoman");
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);

            // Create TextBuilder object
            textBuilder = new TextBuilder(pdfPage);

            // Append the text fragment to the PDF page
            textBuilder.AppendText(textFragment);

            #endregion

            var outPutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "testAspose{0}.pdf".FormatWith(DateTime.Now.ToString("HHmmss")));
            pdfDocument.Save(outPutPath);

            return(string.Empty);
        }
コード例 #30
0
        public static void Run()
        {
            // ExStart:RemoveFilesFromPortfolio
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();

            // Load source PDF Portfolio
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "PDFPortfolio.pdf");
            pdfDocument.Collection.Delete();
            pdfDocument.Save(dataDir + "No_PortFolio_out.pdf");
            // ExEnd:RemoveFilesFromPortfolio                      
        }
コード例 #31
0
        public static void Run()
        {
            // ExStart:RemoveFilesFromPortfolio
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();

            // Load source PDF Portfolio
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "PDFPortfolio.pdf");
            pdfDocument.Collection.Delete();
            pdfDocument.Save(dataDir + "No_PortFolio_out.pdf");
            // ExEnd:RemoveFilesFromPortfolio
        }
コード例 #32
0
 public static void Run()
 {
     // ExStart:PDFToPPT
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
     // Load PDF document
     Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");
     // Instantiate PptxSaveOptions instance
     Aspose.Pdf.PptxSaveOptions pptx_save = new Aspose.Pdf.PptxSaveOptions();
     // Save the output in PPTX format
     doc.Save(dataDir + "PDFToPPT_out.pptx", pptx_save);
     // ExEnd:PDFToPPT
 }        
コード例 #33
0
        public static MemoryStream AddFooterAndWatermark(MemoryStream pdfStream, WatermarkArg arg)
        {
            var pdfDocument = new Aspose.Pdf.Document(pdfStream);
            var pdfLastPage = pdfDocument.Pages[pdfDocument.Pages.Count];
            var footer      = new Aspose.Pdf.HeaderFooter();

            //Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            tab1.HorizontalAlignment = HorizontalAlignment.Center;
            //設定預設的文字格式
            var defaultTextState = new TextState("MingLiU", 8);

            footer.Paragraphs.Add(tab1);
            tab1.DefaultColumnWidth   = "180";
            tab1.DefaultCellTextState = defaultTextState;
            //Create rows in the table and then cells in the rows
            var row1  = tab1.Rows.Add();
            var cellL = row1.Cells.Add("信用資訊查詢主管");

            //cellL.DefaultCellTextState = defaultTextState;
            cellL.Alignment = HorizontalAlignment.Left;
            var cellR = row1.Cells.Add("經辦");

            cellR.Alignment    = HorizontalAlignment.Right;
            pdfLastPage.Footer = footer;

            if (!string.IsNullOrWhiteSpace(arg.Watermark))
            {
                var text = new FormattedText(arg.Watermark);
                foreach (var page in pdfDocument.Pages)
                {
                    switch (arg.WMStyle)
                    {
                    case WatermarkStyle.FitPage:
                        AddWatermarkFitPage(page, arg);
                        break;

                    case WatermarkStyle.RepeatHorizontal:
                        AddWatermarkRepeatHorizontal(page, arg);
                        break;

                    default:
                        break;
                    }
                }
            }
            var newPdfStream = new MemoryStream();

            pdfDocument.Save(newPdfStream);
            return(newPdfStream);
        }
コード例 #34
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open source document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");

            //create three stamps
            Aspose.Pdf.TextStamp stamp1 = new Aspose.Pdf.TextStamp("Header 1");
            Aspose.Pdf.TextStamp stamp2 = new Aspose.Pdf.TextStamp("Header 2");
            Aspose.Pdf.TextStamp stamp3 = new Aspose.Pdf.TextStamp("Header 3");

            //set stamp alignment (place stamp on page top, centered horiznotally)
            stamp1.VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top;
            stamp1.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // specify the font style as Bold
            stamp1.TextState.FontStyle = FontStyles.Bold;
            // set the text fore ground color information as red
            stamp1.TextState.ForegroundColor = Color.Red;
            // specify the font size as 14
            stamp1.TextState.FontSize = 14;

            // now we need to set the vertical alignment of 2nd stamp object as Top
            stamp2.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // set Horizontal alignment information for stamp as Center aligned
            stamp2.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // set the zooming factor for stamp object
            stamp2.Zoom = 10;

            // set the formatting of 3rd stamp object
            // specify the Vertical alignment information for stamp object as TOP
            stamp3.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
            // Set the Horizontal alignment inforamtion for stamp object as Center aligned
            stamp3.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
            // set the rotation angle for stamp object
            stamp3.RotateAngle = 35;
            // set pink as background color for stamp
            stamp3.TextState.BackgroundColor = Color.Pink;
            // change the font face information for stamp to Verdana
            stamp3.TextState.Font = FontRepository.FindFont("Verdana");

            //first stamp is added on first page;
            doc.Pages[1].AddStamp(stamp1);
            //second stamp is added on second page;
            doc.Pages[2].AddStamp(stamp2);
            //third stamp is added on third page.
            doc.Pages[3].AddStamp(stamp3);
            // save the updated document
            doc.Save(dataDir + "multiheader.pdf");
        }
コード例 #35
0
ファイル: XPSToPDF.cs プロジェクト: joyang1/Aspose_Pdf_NET
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // instantiate LoadOption object using XPS load option
            Aspose.Pdf.LoadOptions options = new XpsLoadOptions();
            
            // create document object 
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "test.xps", options);
            
            // save the resultant PDF document
            document.Save(dataDir + "resultant.pdf");
        }
コード例 #36
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Instantiate LoadOption object using SVG load option
            Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.SvgLoadOptions();

            // Create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "example.svg", loadopt);

            // Save the resultant PDF document
            doc.Save(dataDir + "converted.pdf");
        }
コード例 #37
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // Instantiate LoadOption object using SVG load option
            Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.SvgLoadOptions();

            // Create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "example.svg", loadopt);

            // Save the resultant PDF document
            doc.Save(dataDir + "converted.pdf");
        }
コード例 #38
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // instantiate LoadOption object using PCL load option
            Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.PclLoadOptions();

            // create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "test.pcl", loadopt);

            // save the resultant PDF document
            doc.Save(dataDir + "test-converted.pdf");
        }
コード例 #39
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Instantiate LoadOption object using EPUB load option
            EpubLoadOptions epubload = new EpubLoadOptions();

            // Create Document object
            Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(dataDir + "Sample.epub", epubload);

            // Save the resultant PDF document
            pdf.Save(dataDir + "output.pdf");
        }
コード例 #40
0
ファイル: EPUBToPDF.cs プロジェクト: joyang1/Aspose_Pdf_NET
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // Instantiate LoadOption object using EPUB load option
            EpubLoadOptions epubload = new EpubLoadOptions();

            // Create Document object
            Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(dataDir + "Sample.epub", epubload);
            
            // Save the resultant PDF document
            pdf.Save(dataDir + "EPUBToPDF_out.pdf");
        }
コード例 #41
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // instantiate LoadOption object using PCL load option
            Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.PclLoadOptions();

            // create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "test.pcl", loadopt);

            // save the resultant PDF document
            doc.Save(dataDir + "test-converted.pdf");
        }
コード例 #42
0
ファイル: PCLToPDF.cs プロジェクト: joyang1/Aspose_Pdf_NET
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // instantiate LoadOption object using PCL load option
            Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.PclLoadOptions();
            
            // create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "test.pcl", loadopt);
            
            // save the resultant PDF document
            doc.Save(dataDir + "test-converted.pdf");
        }
コード例 #43
0
        private void CovertToPdf(string Destpath, string Sourcepath, Dictionary <GSS.FBU.CMAspose.DomainObject.DomainEnum.CMCustomStyleEnum, string> styles)
        {
            string fileName  = FileFrom.Text.Trim().Split('\\').Last().Split('.')[1];
            string extension = string.Empty;

            extension = fileName.Split('.').Last().ToLower();

            switch (extension)
            {
            case "xls":
            case "xlsx":
                FileStream      fsExcel   = new FileStream(Sourcepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                ExcelProcessing pdfStream = new ExcelProcessing(fsExcel);
                //底層設定客製化樣式
                pdfStream.SetCustomStyleProperty(styles);
                pdfStream.Convert2Pdf(Destpath);

                /* Workbook excelDocument = new Workbook(Sourcepath);
                 * excelDocument.Save(Destpath , Aspose.Cells.SaveFormat.Pdf);*/
                break;

            case "doc":
            case "docx":
                Aspose.Words.Document lDocDocument = new Aspose.Words.Document(Sourcepath);
                lDocDocument.Save(Destpath, Aspose.Words.SaveFormat.Pdf);
                break;

            case "tiff":
            case "tif":
            case "png":
            case "gif":
            case "jpeg":
            case "jpg":
            case "xpm":
                // Initialize new PDF document
                Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
                // Add empty page in empty document
                Page             page  = doc.Pages.Add();
                Aspose.Pdf.Image image = new Aspose.Pdf.Image();
                image.File = (Sourcepath);
                // Add image on a page
                page.Paragraphs.Add(image);
                // Save output PDF file
                doc.Save(Destpath);
                break;

            default:
                break;
            }
        }
コード例 #44
0
ファイル: AsposePdfComponent.cs プロジェクト: wingfay/studio
        public void InsertPage(string absoluteFilePath, string outputPath)
        {
            var insertPageImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DefaultResource", "insertPage.jpeg");

            using (var pdfDocument = new Aspose.Pdf.Document(absoluteFilePath))
                using (BackgroundArtifact background = new BackgroundArtifact())
                {
                    // Add a new page to document object
                    Page page = pdfDocument.Pages.Insert(2);
                    page.AddImage(insertPageImgPath, page.Rect);

                    pdfDocument.Save(outputPath);
                }
        }
コード例 #45
0
ファイル: AsposePdfComponent.cs プロジェクト: wingfay/studio
        public void ToHtml(string absoluteFilePath, string outputPath)
        {
            // Instantiate LoadOption object using XPS load option


            using (var pdfDocument = new Aspose.Pdf.Document(absoluteFilePath))
            {
                Aspose.Pdf.HtmlSaveOptions saveOptions = new Aspose.Pdf.HtmlSaveOptions();
                saveOptions.FixedLayout            = true;
                saveOptions.SplitIntoPages         = false;
                saveOptions.RasterImagesSavingMode = Aspose.Pdf.HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
                pdfDocument.Save(outputPath, saveOptions);
            }
        }
コード例 #46
0
        public static void Run()
        {
            // ExStart:PDFToPPT
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // Load PDF document
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");
            // Instantiate PptxSaveOptions instance
            Aspose.Pdf.PptxSaveOptions pptx_save = new Aspose.Pdf.PptxSaveOptions();
            // Save the output in PPTX format
            doc.Save(dataDir + "PDFToPPT_out.pptx", pptx_save);
            // ExEnd:PDFToPPT
        }
コード例 #47
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // instantiate LoadOption object using XPS load option
            Aspose.Pdf.LoadOptions options = new XpsLoadOptions();

            // create document object
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "test.xps", options);

            // save the resultant PDF document
            document.Save(dataDir + "resultant.pdf");
        }
コード例 #48
0
 public static void Run()
 {
     try
     {
         // ExStart:TeXToPDF
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
         // Instantiate Latex Load option object
         LatexLoadOptions Latexoptions = new LatexLoadOptions();
         // Create Document object
         Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "samplefile.tex", Latexoptions);
         // Save the output in PDF file
         doc.Save(dataDir + "TeXToPDF_out.pdf");
         // ExEnd:TeXToPDF
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #49
0
ファイル: PDFToTeX.cs プロジェクト: joyang1/Aspose_Pdf_NET
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "PDFToTeX.pdf");

            // instantiate LaTex save option            
            LaTeXSaveOptions saveOptions = new LaTeXSaveOptions();

            // specify the output directory 
            string pathToOutputDirectory = dataDir;

            // set the output directory path for save option object
            saveOptions.OutDirectoryPath = pathToOutputDirectory;

            // save PDF file into LaTex format            
            doc.Save(dataDir + "Output.tex", saveOptions);
        }
コード例 #50
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // create Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");

            // instantiate LaTex save option
            LaTeXSaveOptions saveOptions = new LaTeXSaveOptions();

            // specify the output directory
            string pathToOutputDirectory = dataDir;

            // set the output directory path for save option object
            saveOptions.OutDirectoryPath = pathToOutputDirectory;

            // save PDF file into LaTex format
            doc.Save(dataDir + "Output.tex", saveOptions);
        }
コード例 #51
0
        public static void Run()
        {
            // ExStart:ArabicTextFilling
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // Load PDF form contents
            FileStream fs = new FileStream(dataDir + "FillFormField.pdf", FileMode.Open, FileAccess.ReadWrite);
            // Instantiate Document instance with stream holding form file
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
            // Get referecne of particuarl TextBoxField
            TextBoxField txtFld = pdfDocument.Form["textbox1"] as TextBoxField;
            // Fill form field with arabic text
            txtFld.Value = "يولد جميع الناس أحراراً متساوين في";

            dataDir = dataDir + "ArabicTextFilling_out.pdf";
            // Save updated document
            pdfDocument.Save(dataDir);
            // ExEnd:ArabicTextFilling
            Console.WriteLine("\nArabic text filled successfully in form field.\nFile saved at " + dataDir);
        }
コード例 #52
0
        public static void Run()
        {
            try
            {
                // ExStart:EPUBToPDF
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

                // Instantiate LoadOption object using EPUB load option
                EpubLoadOptions epubload = new EpubLoadOptions();

                // Create Document object
                Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(dataDir + "EPUBToPDF.epub", epubload);

                // Save the resultant PDF document
                pdf.Save(dataDir + "EPUBToPDF_out.pdf");
                // ExEnd:EPUBToPDF
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #53
0
        public static void Run()
        {
            try
            {
                // ExStart:PCLToPDF
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

                // Instantiate LoadOption object using PCL load option
                Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.PclLoadOptions();

                // Create Document object
                Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "hidetext.pcl", loadopt);

                // Save the resultant PDF document
                doc.Save(dataDir + "PCLToPDF_out.pdf");
                // ExEnd:PCLToPDF
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #54
0
        public static void Run()
        {
            // ExStart:RenderingReplaceableSymbols
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document();
            Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add();

            // Initialize new TextFragment with text containing required newline markers
            Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe");

            // Set text fragment properties if necessary
            textFragment.TextState.FontSize = 12;
            textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman");
            textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
            textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

            // Create TextParagraph object
            TextParagraph par = new TextParagraph();

            // Add new TextFragment to paragraph
            par.AppendLine(textFragment);

            // Set paragraph position
            par.Position = new Aspose.Pdf.Text.Position(100, 600);

            // Create TextBuilder object
            TextBuilder textBuilder = new TextBuilder(applicationFirstPage);
            // Add the TextParagraph using TextBuilder
            textBuilder.AppendParagraph(par);

            dataDir = dataDir + "RenderingReplaceableSymbols_out.pdf";
            pdfApplicationDoc.Save(dataDir);
            // ExEnd:RenderingReplaceableSymbols            
            Console.WriteLine("\nReplaceable symbols render successfully duing pdf creation.\nFile saved at " + dataDir);
        }
コード例 #55
0
        public static void Run()
        {
            try
            {
                // ExStart:XPSToPDF
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

                // Instantiate LoadOption object using XPS load option
                Aspose.Pdf.LoadOptions options = new XpsLoadOptions();

                // Create document object 
                Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "XPSToPDF.xps", options);

                // Save the resultant PDF document
                document.Save(dataDir + "XPSToPDF_out.pdf");
                // ExEnd:XPSToPDF
            }
            catch(Exception ex)
               
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #56
0
        //method for pagewatermarkings and stamping
        private static void WaterMarkDocument(string pdfDocumentPath, string hflDocumentPath, string stampText, List<string> watermarkingValues)
        {
            try
            {
                Aspose.Pdf.Document document = new Aspose.Pdf.Document(pdfDocumentPath);
                Aspose.Pdf.Document hfl = new Aspose.Pdf.Document(hflDocumentPath);
                //create page stamp
                PdfPageStamp pageStamp = null;

                foreach (var value in watermarkingValues)
                {
                    string[] waterMark = value.Split('=');

                    string hflDocPageNo = waterMark[waterMark.Length - 1];
                    string docPageNo = waterMark[waterMark.Length - 2];

                    //Console.WriteLine(hflDocPageNo + " " + docPageNo);
                    //Console.ReadKey();
                    int hflDocPageNumber = Convert.ToInt32(hflDocPageNo);

                    if (docPageNo == "[ALL]")
                    {
                        //create page stamp
                        pageStamp = new PdfPageStamp(hfl.Pages[hflDocPageNumber]);

                        //add stamp to all pages
                        for (int pageCount = 1; pageCount <= document.Pages.Count; pageCount++)
                        {
                            //add stamp to particular page
                            document.Pages[pageCount].AddStamp(pageStamp);
                        }
                    }
                    else
                    {
                        int docPageNumber = Convert.ToInt32(docPageNo);

                        //create page stamp
                        pageStamp = new PdfPageStamp(hfl.Pages[hflDocPageNumber]);

                        if (docPageNumber <= document.Pages.Count)
                        {
                            //add stamp to particular page
                            document.Pages[docPageNumber].AddStamp(pageStamp);
                        }

                    }
                }

                if (stampText.Length > 0)
                {
                    //Create text stamp
                    TextStamp textStamp = new TextStamp(stampText);
                    //set whether stamp is background
                    textStamp.Background = true;
                    //set origin
                    textStamp.XIndent = 420;
                    textStamp.YIndent = 825;
                    textStamp.TextState.FontSize = 8.0F;
                    pageStamp.Background = true;
                    //add stamp to particular page
                    document.Pages[1].AddStamp(textStamp);
                }

                //finally save the pdf document
                document.Save(pdfDocumentPath);
                writeToLog("Final document " + document.FileName.ToString() + " Produced");

            }
            catch (Exception e)
            {
                Console.WriteLine("Application PDBOT failed with error: " + e.Message + "." + e.StackTrace);
                writeToLog("Error saving final document " + e.StackTrace);
                Console.ReadKey();

            }
        }
コード例 #57
0
ファイル: Security.cs プロジェクト: killbug2004/WSProf
 internal void Remove(string file, string password)
 {
     AsposePdf.Document document = new AsposePdf.Document(file, password);
     document.Decrypt();
     document.Save(file);
 }