<file_sep>﻿namespace System
{
    using IO;

    public static class StreamExtension
    {
        public static Byte[] ToBytes(this Stream stream)
        {
            var bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);
            return bytes;
        }

        public static Stream ToStream(this Byte[] bytes)
        {
            var stream = new MemoryStream(bytes);
            return stream;
        }

        public static String ToString(this Byte[] bytes)
        {
            return String.Empty;
        }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    #region using directives
    using System;
    using System.Drawing;
    #endregion
    public class WatermarkSetting
    {
        public String Id { get; set; }

        public String Watermark { get; set; }

        public String WatermarkFont { get; set; }

        public String WatermarkFontSize { get; set; }

        public Color WatermarkColor { get; set; }

        public Double Opacity { get; set; }

        public Boolean IsRepeated { get; set; }

        public Int32 Direction { get; set; }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Words;
    using Aspose.Words.Drawing;
    using System;
    using System.Drawing;
    using System.IO;

    public class Program
    {
        public static void Main()
        {
            //ImageScale.Run();
            //Word.Run();
            //ImageOpeation.SetWatermarkForImage();
            //Slides.AddImageWatermarkToSlide();
            //AsposeCell.AddWatermarkImageForCells();
            //AddPDFWatermark.AddImageWatermark();
            //AddPDFWatermark.SplitPdf();
            //ConvertToWord.TestDoc();
            //AddPDFWatermark.AddImageWatermark();
            //ConvertToWord.PdfToDoc();
            //ConvertToWord.DocStreamToDoc();
            //AddMark(); 
            //LoadLicence();
            //Document doc = new Document(@"D:\test.docx");
            //InsertWatermarkText(doc, "AvePoint");
            //doc.Save(@"D:\testImage.docx");
            AsposeCell.AddWatermarkImageForCells();
            //Stream stream = new FileInfo(@"D:\sqlCopy.pdf").OpenRead();
            //ConvertToWord.PdfStreamToDocx(stream);
            //var stream1 = AddPDFWatermark.AddWatermark2(stream);
            //using (var fileStream = File.Create(@"D:\sql07.pdf"))
            //{
            //    stream1.Seek(0, SeekOrigin.Begin);
            //    stream1.CopyTo(fileStream);
            //}
            Console.WriteLine("success");
            Console.ReadKey();
        }

        /// <summary>
        /// Inserts a watermark into a document.
        /// </summary>
        /// <param name="doc">The input document.</param>
        /// <param name="watermarkText">Text of the watermark.</param>
        private static void InsertWatermarkText(Document doc, String watermarkText)
        {
            // Create a watermark shape. This will be a WordArt shape. 
            // You are free to try other shape types as watermarks.
            Shape watermark = new Shape(doc, ShapeType.Image);

            // Set up the text of the watermark.
            //watermark.TextPath.Text = watermarkText;
            watermark.ImageData.ImageBytes = new FileInfo(@"D:\test.jpg").OpenRead().ToBytes();
            watermark.TextPath.FontFamily = "Arial";
            watermark.Width = 500;
            watermark.Height = 100;
            // Text will be directed from the bottom-left to the top-right corner.
            watermark.Rotation = -40;
            // Remove the following two lines if you need a solid black text.
            watermark.Fill.Color = Color.Gray; // Try LightGray to get more Word-style watermark
            watermark.StrokeColor = Color.Gray; // Try LightGray to get more Word-style watermark

            // Place the watermark in the page center.
            watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
            watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
            watermark.WrapType = WrapType.None;
            watermark.VerticalAlignment = VerticalAlignment.Center;
            watermark.HorizontalAlignment = HorizontalAlignment.Center;

            // Create a new paragraph and append the watermark to this paragraph.
            Paragraph watermarkPara = new Paragraph(doc);
            watermarkPara.AppendChild(watermark);

            // Insert the watermark into all headers of each document section.
            foreach (Section sect in doc.Sections)
            {
                // There could be up to three different headers in each section, since we want
                // the watermark to appear on all pages, insert into all headers.
                InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
                InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
                InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);
            }
        }

        private static void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
        {
            HeaderFooter header = sect.HeadersFooters[headerType];

            if (header == null)
            {
                // There is no header of the specified type in the current section, create it.
                header = new HeaderFooter(sect.Document, headerType);
                sect.HeadersFooters.Add(header);
            }

            // Insert a clone of the watermark into the header.
            header.AppendChild(watermarkPara.Clone(true));
        }

        private static void LoadLicence()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
        }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Imaging;
    using Aspose.Imaging.FileFormats.Tiff;
    using Aspose.Imaging.FileFormats.Tiff.Enums;
    using Aspose.Imaging.ImageOptions;
    using Aspose.Imaging.Sources;
    using System.IO;

    public class ImageOpeation
    {
        public static void SetWatermarkForImage()
        {
            TiffOptions outputSettings = new TiffOptions();
            outputSettings.BitsPerSample = new ushort[] { 1 };
            outputSettings.Compression = TiffCompressions.CcittFax3;
            outputSettings.Photometric = TiffPhotometrics.MinIsWhite;
            outputSettings.Source = new StreamSource(new MemoryStream());
            int newWidth = 500;
            int newHeight = 500;
            string path = @"D:\output.jpg";
            using (TiffImage tiffImage = (TiffImage)Image.Create(outputSettings, newWidth, newHeight))
            {
                using (RasterImage ri = (RasterImage)Image.Load(@"D:\test.jpg"))
                {
                    ri.Resize(newWidth, newHeight, ResizeType.NearestNeighbourResample);
                    TiffFrame frame = tiffImage.ActiveFrame;
                   
                        frame = new TiffFrame(new TiffOptions(outputSettings) /*ensure options are cloned for each frame*/,
                            newWidth, newHeight);
                        // If there is a TIFF image loaded you need to enumerate the frames and perform the following
                        // frame = TiffFrame.CreateFrameFrom(sourceFrame, outputSettings);
                    frame.SavePixels(frame.Bounds, ri.LoadPixels(ri.Bounds));
                    tiffImage.AddFrame(frame);
                }

                tiffImage.Save(path);
            }

        }

        private static void LoadLicence()
        {
            Aspose.Imaging.License license = new Aspose.Imaging.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
        }
    }
}
<file_sep># PdfWatermark
Aspose API的学习，通过对API的学习对Pdf文件进行水印的增删操作。

<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Pdf;
    using Aspose.Pdf.Text;
    using System;
    using System.IO;

    public class AddPDFWatermark
    {
        public static void AddWatermark()
        {
            //open document
            string pdffile = @"D:\book\sqlCopy.pdf";
            Document pdfDocument = new Document(pdffile);

            //set coordinates
            int lowerLeftX = 400;
            int lowerLeftY = 75;
            int upperRightX = 550;
            int upperRightY = 100;

            //get the page where image needs to be added
            Page page = pdfDocument.Pages[1];
            //load image into stream
            FileStream imageStream = new FileStream(@"D:\book\test.jpg", FileMode.Open);
            //add image to Images collection of Page Resources
            page.Resources.Images.Add(imageStream);
            //using GSave operator: this operator saves current graphics state
            page.Contents.Add(new Operator.GSave());
            //create Rectangle and Matrix objects
            Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
            Aspose.Pdf.DOM.Matrix matrix =
                new Aspose.Pdf.DOM.Matrix(new double[]
                {rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY});
            //using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
            page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
            XImage ximage = page.Resources.Images[page.Resources.Images.Count];
            //using Do operator: this operator draws image
            page.Contents.Add(new Operator.Do(ximage.Name));
            //using GRestore operator: this operator restores graphics state
            page.Contents.Add(new Operator.GRestore());

            TextStamp textStamp = new TextStamp("my text stamp goes here!");
            textStamp.Rotate = Rotation.on90;
            textStamp.Background = true;
            textStamp.TextState.FontSize = 5.0F;
            textStamp.TextState.FontStyle = FontStyles.Bold;
            textStamp.TextState.FontStyle = FontStyles.Italic;
            pdfDocument.Pages[1].AddStamp(textStamp);
            //pdfDocument.Pages[pdfDocument.Pages.Count].Watermark.Image.Save("mywatermark.jpg");

            //save updated document
            //string newpdf_file = signedfolder + "\\" + filename.Substring(0, filename.IndexOf(".pdf")) + "_SIGNED.pdf";
            pdfDocument.Save(@"D:\sqloutput.pdf");
            imageStream.Close();
        }


        public static void AddWatermark1()
        {
            //Stream stream = new FileInfo(@"D:\Program Files (x86)\sqlCopy.pdf").OpenRead();
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            Document pdfDocument = new Document(@"D:\sqlCopy.pdf");
            //create text stamp
            TextStamp textStamp = new TextStamp("AvePoint");
            TextStamp headStamp = new TextStamp("AvePoint In Head");
            headStamp.TopMargin = 10;
            headStamp.HorizontalAlignment = HorizontalAlignment.Center;
            textStamp.HorizontalAlignment = HorizontalAlignment.Center;
            headStamp.VerticalAlignment = VerticalAlignment.Top;
            textStamp.VerticalAlignment = VerticalAlignment.Center;
            //set origin
            textStamp.XIndent = 80;
            textStamp.YIndent = 80;
            textStamp.Width = 100F;
            textStamp.Height = 50F;
            //set whether stamp is background
            textStamp.Background = true;
            //rotate stamp
            textStamp.RotateAngle = 45;
            textStamp.Opacity = 0.2;
            //set text properties
            textStamp.TextState.Font = FontRepository.FindFont("Arial");
            textStamp.TextState.FontSize = 14.0F;
            textStamp.TextState.FontStyle = FontStyles.Bold;
            textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
            //textStamp.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Brown);
            //add stamp to particular page
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(headStamp);
                page.AddStamp(textStamp);
            }
            //save output document
            //var stream1 = new MemoryStream();
            //pdfDocument.Save(stream1);
            //using (var fileStream = File.Create(@"D:\sql03.pdf"))
            //{
            //    stream1.Seek(0, SeekOrigin.Begin);
            //    stream1.CopyTo(fileStream);
            //}

            pdfDocument.Save(@"D:\sql04.pdf");
        }

        public static Stream AddWatermark2(Stream pdfStream)
        {
            Document pdfDocument = new Document(pdfStream);
            //create text stamp
            TextStamp textStamp = new TextStamp("AvePoint2016猴年");
            TextStamp headStamp = new TextStamp("AvePoint In Head");
            headStamp.TopMargin = 10;
            headStamp.HorizontalAlignment = HorizontalAlignment.Center;
            headStamp.VerticalAlignment = VerticalAlignment.Top;
            //set origin
            textStamp.XIndent = 80;
            textStamp.YIndent = 80;
            textStamp.Width = 400F;
            textStamp.Height = 50F;
            //set whether stamp is background
            textStamp.Background = true;
            //rotate stamp
            textStamp.Rotate = Rotation.None;
            //set text properties
            textStamp.TextState.Font = FontRepository.FindFont("Arial");
            textStamp.TextState.FontSize = 14.0F;
            textStamp.TextState.FontStyle = FontStyles.Bold;
            textStamp.TextState.FontStyle = FontStyles.Italic;
            textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
            textStamp.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Brown);
            //add stamp to particular page
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(headStamp);
                page.AddStamp(textStamp);
            }
            //save output document
            var stream1 = new MemoryStream();
            pdfDocument.Save(stream1);
            return stream1;
        }

        public static void AddMark()
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            //Add a section to the Pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1, "This is text in section1.")
            {
                Left = 30,
                Top = 100
            };
            sec1.Paragraphs.Add(text1);
            Aspose.Pdf.Generator.Section sec2 = pdf1.Sections.Add();
            Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(sec2, "This is text in section2.")
            {
                Left = 30,
                Top = 100
            };
            sec2.Paragraphs.Add(text2);
            //setting image watermark
            Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image();
            image1.ImageInfo.File = @"D:\book\test.jpg";
            image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
            image1.ImageScale = 0.1f;
            Aspose.Pdf.Generator.FloatingBox watermark1 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark1.BoxHorizontalAlignment = Aspose.Pdf.Generator.BoxHorizontalAlignmentType.Center;
            watermark1.BoxVerticalPositioning = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;
            watermark1.BoxVerticalAlignment = Aspose.Pdf.Generator.BoxVerticalAlignmentType.Center;
            watermark1.Paragraphs.Add(image1);
            //graph watermark
            Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(100, 400);
            float[] posArr = new float[] {0, 0, 200, 80, 300, 40, 350, 90};
            Aspose.Pdf.Generator.Curve curve1 = new Aspose.Pdf.Generator.Curve(graph1, posArr);
            graph1.Shapes.Add(curve1);
            Aspose.Pdf.Generator.FloatingBox watermark2 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark2.Paragraphs.Add(graph1);
            //text watermark
            Aspose.Pdf.Generator.Text text3 = new Aspose.Pdf.Generator.Text("Text Watermark");
            Aspose.Pdf.Generator.FloatingBox watermark3 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark3.Left = 50;
            watermark3.Top = 500;
            watermark3.Paragraphs.Add(text3);
            pdf1.Watermarks.Add(watermark1);
            pdf1.Watermarks.Add(watermark2);
            pdf1.Watermarks.Add(watermark3);
            pdf1.Save(@"D:\sql2.pdf");
        }

        public static void AddImageWatermark()
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            Document pdfDocument = new Document(@"D:\pdfDocument.pdf");
            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(@"D:\book\test.jpg");
            imageStamp.Background = true;
            imageStamp.XIndent = 100;
            imageStamp.YIndent = 100;
            imageStamp.Height = 300;
            imageStamp.Width = 300;
            imageStamp.RotateAngle = 45;
            imageStamp.Opacity = 0.5;
            //Add stamp to particular page
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }
            //Save output document
            pdfDocument.Save(@"D:\sqlimage.pdf");
        }

        public static void SplitPdf()
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            Document pdfDocument = new Document();
            using (Stream stream = new FileInfo(@"D:\pdfDocument.pdf").OpenRead())
            {
                stream.Seek(0, SeekOrigin.Begin);
                var bs = stream.ToBytes();
                var bytes = ConvertPdfToDocX(bs);
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(ms);
                    doc.Save(@"D:\ttt.docx");
                }
            }
           
            //var newDoc = new Document();
            //newDoc.Pages.Add(pdfDocument.Pages[1]);
            //newDoc.Pages.Add(pdfDocument.Pages[2]);
            //newDoc.Save(@"D:\tt.pdf", SaveFormat.Pdf);
        }

        public static Byte[] ConvertPdfToDocX(Byte[] bytes)
        {
            Byte[] docxBytes = null;
            MemoryStream docStream = new MemoryStream();
            try
            {
                using (var stream = new MemoryStream(bytes))
                {
                    Document pdfDocument = new Document(stream);
                    pdfDocument.Save(docStream, SaveFormat.DocX);
                    docStream.Seek(0, SeekOrigin.Begin);
                    docxBytes = new byte[docStream.Length];
                    docStream.Read(docxBytes, 0, docxBytes.Length);
                    docStream.Seek(0, SeekOrigin.Begin);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (docStream != null)
                {
                    docStream.Close();
                }
            }
            return docxBytes;
        }
    }
} ;
<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Cells;
    using Aspose.Cells.Drawing;
    using System.IO;

    public class AsposeCell
    {
        public static void AddWatermarkForCells()
        {
            LoadLicence();
            //Instantiate a new Workbook
            Workbook workbook = new Workbook(@"D:\test.xlsx");

            //Get the first default sheet
            //Worksheet sheet = workbook.Worksheets[0];

            //Add Watermark
            foreach (Worksheet sheet in workbook.Worksheets)
            {
                Aspose.Cells.Drawing.Shape wordart = sheet.Shapes.AddTextEffect(MsoPresetTextEffect.TextEffect20,
           "AvePoint", "Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800);
                //Get the fill format of the word art
                MsoFillFormat wordArtFormat = wordart.FillFormat;
                //Set the color
                wordArtFormat.ForeColor = System.Drawing.Color.Red;
                //Set the transparency
                wordArtFormat.Transparency = 0.9;
                //Make the line invisible
                MsoLineFormat lineFormat = wordart.LineFormat;
                lineFormat.IsVisible = false;
            }
            //Save the file
            workbook.Save(@"D:\testWatermarkText.xlsx");
        }

        public static void AddWatermarkImageForCells()
        {
            LoadLicence();
            //Instantiate a new Workbook
            Workbook workbook = new Workbook(@"D:\test.xlsx");

            //Add Watermark
            foreach (Worksheet sheet in workbook.Worksheets)
            {
                Aspose.Cells.Drawing.Shape wordart = sheet.Shapes.AddPicture(0, 0, new FileInfo(@"D:\test.jpg").OpenRead(), 10, 20);
                //Get the fill format of the word art
                wordart.TextDirection = TextDirectionType.Context;
                var fillformat = wordart.Fill;
                var format = wordart.FillFormat;
                fillformat.Scale = 0.2;
                //Set the transparency
                format.Transparency = 0.2;
                //Make the line invisible
                MsoLineFormat lineFormat = wordart.LineFormat;

                lineFormat.IsVisible = false;
            }
            //Save the workbook
            workbook.Save(@"D:\testWatermarkImage.xlsx", Aspose.Cells.SaveFormat.Xlsx);
        }

        public static void LoadLicence()
        {
            Aspose.Cells.License license = new Aspose.Cells.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
        }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Slides;
    using Aspose.Slides.Export;
    using System.Drawing;

    public class Slides
    {
        public static void AddImageWatermarkToSlide()
        {
            //using (Presentation pres = new Presentation())
            //{

            //    //Get the first slide
            //    ISlide sld = pres.Slides[0];

            //    //Add an AutoShape of Rectangle type
            //    IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);

            //    //Add TextFrame to the Rectangle
            //    ashp.AddTextFrame(" ");

            //    //Accessing the text frame
            //    ITextFrame txtFrame = ashp.TextFrame;

            //    //Create the Paragraph object for text frame
            //    IParagraph para = txtFrame.Paragraphs[0];

            //    //Create Portion object for paragraph
            //    IPortion portion = para.Portions[0];

            //    //Set Text
            //    portion.Text = "Aspose TextBox";

            //    //Save the presentation to disk
            //    pres.Save("TextBox.pptx", SaveFormat.Pptx);
            //}
            LoadLicence();
            using (Presentation pres = new Presentation(@"D:\test.pptx"))
            {
                foreach (ISlide slide in pres.Slides)
                {
                    ////Set the background with Image
                    //slide.Background.Type = BackgroundType.OwnBackground;
                    //slide.Background.FillFormat.FillType = FillType.Picture;
                    //slide.Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

                    ////Set the picture
                    //System.Drawing.Image img = (System.Drawing.Image)new Bitmap(@"D:\book\test.jpg");

                    ////Add image to presentation's images collection
                    //IPPImage imgx = pres.Images.AddImage(img);
                    //slide.Background.FillFormat.PictureFillFormat.Picture.Image = imgx;

                    //Add autoshape of rectangle type
                    IShape shp = slide.Shapes.AddAutoShape(ShapeType.OrFlow, 150, 150, 75, 150);
                    //Set the fill type to Picture
                    shp.FillFormat.FillType = FillType.Picture;
                    shp.FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCorner2;

                    //Set the picture fill mode
                    shp.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;

                    //Set the picture
                    System.Drawing.Image img = (System.Drawing.Image)new Bitmap(@"D:\book\test.jpg");
                    IPPImage imgx = pres.Images.AddImage(img);
                    shp.FillFormat.PictureFillFormat.Picture.Image = imgx;
                }


                //Write the presentation to disk
                pres.Save(@"D:\RectShpPic1.pptx", SaveFormat.Pptx);
            }
        }
        private static void LoadLicence()
        {
            Aspose.Slides.License license = new Aspose.Slides.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
        }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;

    public class ImageScale
    {
        public static void Run()
        {
            var image = Image.FromFile(@"D:\test.jpg");
            var scaleImageBytes = ScaleImage(image,1600,1600);
            var scaleImage = Image.FromStream(scaleImageBytes.ToStream());
            scaleImage.Save(@"D:\testScale.jpg", ImageFormat.Bmp);
        }

        public static Byte[] ScaleImage(Image image, Int32 width, Int32 height)
        {
            var scaledWidth = width;
            var scaledHeight = height;
            var format = image.RawFormat;
            var saveImage = new Bitmap(scaledWidth, scaledHeight);
            var g = Graphics.FromImage(saveImage);
            g.Clear(System.Drawing.Color.White);
            Int32 IntWidth;
            Int32 IntHeight;
            if (image.Width > scaledWidth && image.Height <= scaledHeight)
            {
                IntWidth = scaledWidth;
                IntHeight = (IntWidth * image.Height) / image.Width;
            }
            else if (image.Width <= scaledWidth && image.Height > scaledHeight)
            {
                IntHeight = scaledHeight;
                IntWidth = (IntHeight * image.Width) / image.Height;
            }
            else if (image.Width <= scaledWidth && image.Height <= scaledHeight)
            {
                IntHeight = image.Width;
                IntWidth = image.Height;
            }
            else
            {
                IntWidth = scaledWidth;
                IntHeight = (IntWidth * image.Height) / image.Width;
                if (IntHeight > scaledHeight)
                {
                    IntHeight = scaledHeight;
                    IntWidth = (IntHeight * image.Width) / image.Height;
                }
            }
            g.DrawImage(image, (scaledWidth - IntWidth) / 2, (scaledHeight - IntHeight) / 2, IntWidth, IntHeight);
            using (var stream = new MemoryStream())
            {
                saveImage.Save(stream, ImageFormat.Jpeg);
                stream.Seek(0, SeekOrigin.Begin);
                return stream.ToBytes();
            }
        }
    }
}
<file_sep>﻿namespace PdfWatermark
{
    using Aspose.Pdf;
    using System;
    using System.IO;
    using Document = Aspose.Pdf.Document;
    using SaveFormat = Aspose.Pdf.SaveFormat;

    public class ConvertToWord
    {

        public static void PdfToDoc()
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            //open the source PDF document
            Document pdfDocument = new Document(@"D:\sqlCopy.pdf");

            // 1.
            // saving using direct method
            // save the file into MS document format
            pdfDocument.Save("simpleOutput.doc", SaveFormat.Doc);

            // 2.
            // save using save options
            // create DocSaveOptions object
            DocSaveOptions saveOptions = new DocSaveOptions();

            // set the recognition mode as Flow
            saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow;

            // set the Horizontal proximity as 2.5
            saveOptions.RelativeHorizontalProximity = 2.5f;

            // enable the value to recognize bullets during conversion process
            saveOptions.RecognizeBullets = true;

            // save the resultant DOC file
            pdfDocument.Save(@"D:\Output.doc", saveOptions);
        }

        public static void PdfToDocx()
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            //open the source PDF document
            Document pdfDocument = new Document(@"D:\sqlCopy.pdf");

            // 1.
            // saving using direct method
            // save the file into MS document format
            pdfDocument.Save("simpleOutput.doc", SaveFormat.Doc);

            // 2.
            // save using save options
            // create DocSaveOptions object
            DocSaveOptions saveOptions = new DocSaveOptions();

            // set the recognition mode as Flow
            saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow;

            // Specify the output format as DOCX, 默认为Doc
            saveOptions.Format = DocSaveOptions.DocFormat.DocX;

            // set the Horizontal proximity as 2.5
            saveOptions.RelativeHorizontalProximity = 2.5f;

            // enable the value to recognize bullets during conversion process
            saveOptions.RecognizeBullets = true;

            // save the resultant DOC file
            pdfDocument.Save(@"D:\Output.docx", saveOptions);
        }

        public static Stream PdfStreamToDocStream(Stream stream)
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            var doc = new Document(stream);
            var ms = new MemoryStream();
            doc.Save(ms,SaveFormat.Doc);
            return ms;
        }

        public static void PdfStreamToDocx(Stream stream)
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            var doc = new Document(stream);
            doc.Save(@"D:\test.docx", SaveFormat.DocX);
        }

        public static void DocStreamToDoc()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            Stream stream = new FileInfo(@"D:\sqlCopy.pdf").OpenRead();
            var ms = PdfStreamToDocStream(stream);
            var doc = new Aspose.Words.Document(ms);
            doc.Save(@"D:\test.doc");
        }

        public static void TestDoc()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("D:/WorkCopy/GitProject/PdfWatermarkTest/PdfWatermark/Aspose.Total.lic");
            var doc = new Aspose.Words.Document(@"D:\test.docx");
            //foreach (Section sec in doc.Sections)
            //{
            //    var i = sec.GetText().Length;
            //    Console.WriteLine(sec.GetText());
            //    Console.WriteLine(i);             
            //}
            Console.WriteLine(doc.Sections.Count);
            Console.WriteLine(doc.PageCount);
            Console.WriteLine(doc);
        }
    }
}
