working on it ...

Filters

Explore Public Snippets

Sort by

Found 9,377 snippets matching: document

    public by johansonkatherine modified May 8, 2014  219391  1  6  2

    C# Code Sample to Replace Multiple Texts inside PDF File Using Cloud API

    The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
    AsposeApp.AppSID  = "77***********************************";
    AsposeApp.AppKey = "9a*******************************";
    
    //build URI
    stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";
    
    //sign URI
    stringsignedURI = Utils.Sign(strURI);
    
    //build JSON to post
    TextReplace textReplace1 = new TextReplace();
    textReplace1.OldValue = "[!firm!]";
    textReplace1.NewValue = "Aspose";
    textReplace1.Regex = "false";
    
    //build JSON to post
    TextReplace textReplace2 = new TextReplace();
    textReplace2.OldValue = "[!client!]";
    textReplace2.NewValue = "Mark";
    textReplace2.Regex = "false";
    
    MultipleTextReplacestextReplaces = new MultipleTextReplaces();
    textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
    stringstrJSON = JsonConvert.SerializeObject(textReplaces);
    Console.Write(strJSON);
    Utils.ProcessCommand(signedURI, "POST", strJSON);
    
    //build URI
    strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";
    
    //sign URI
    signedURI = Utils.Sign(strURI);
    
    Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
    using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
    {
    Utils.CopyStream(responseStream, fileStream);
    }
    responseStream.Close();
    
    //Following are required classes
    public class MultipleTextReplaces
        {
    publicTextReplace[] TextReplaces { get; set; }
        }
    public class TextReplace
        {
    publicTextReplace() { }
    
    public string OldValue { get; set; }
    public string NewValue { get; set; }
    public string Regex { get; set; }
    
        }
    

    public by fromano modified Jun 26, 2013  269589  2  4  0

    Useful commands for math in LaTeX

    If in your document you use a lot of partial derivatives, matrices, etc.. these commands can be useful
    \newcommand{\fratop}[2]{\genfrac{}{}{0pt}{}{#1}{#2}}
    \newcommand{\mx}[1]{\mathbf{\bm{#1}}} 				% Matrix symbol
    \newcommand{\vc}[1]{\mathbf{\bm{#1}}} 					% Vector symbol
    \newcommand{\degree}{\ensuremath{^\circ}}				% define the degree symbol
    \newcommand{\pder}[2]{\frac{\partial#1}{\partial#2}}		% partial derivative
    \newcommand{\refframe}[1]{\mbox{\textless#1\textgreater}}	% to denote a reference frame
    \DeclareMathOperator*{\argmin}{\arg\!\min}				% argmin
    \DeclareMathOperator*{\argmax}{\arg\!\max}				% argmax
    \DeclareMathOperator*{\dif}{\mathrm{d}}					% d
    \DeclareMathOperator*{\half}{\frac{1}{2}}					% one half
    \newcommand{\mat}[1]{\ensuremath{\begin{bmatrix}#1\end{bmatrix}}}	% matrix
    \newcommand{\rank}[1]{\text{rank}(#1)}							% rank
    \newcommand{\diag}[1]{\text{diag}(#1)}							% diag
    \newcommand{\x}{\ensuremath{\times}}

    public by bfranzoi modified Aug 3, 2016  145459  0  5  0

    document.ready

    $(document).ready(function() {
    
    
    
    
    });

    public by sherazam modified Mar 16, 2016  2686  0  5  0

    How to Insert Clone of an Existing Table in a Word Document inside .NET Apps

    // Enter here the actual content of the snippet.  
    
    //Code samples Shows how to insert a table using the constructors of nodes
    
    //[C# Code Sample]
     
    
    // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Document doc = new Document(dataDir + "Table.SimpleTable.doc");
    
    // Retrieve the first table in the document.
    
    Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
    
    // Create a clone of the table.
    
    Table tableClone = (Table)table.Clone(true);
    
    // Insert the cloned table into the document after the original
    
    table.ParentNode.InsertAfter(tableClone, table);
    
    // Insert an empty paragraph between the two tables or else they will be combined into one
    
    // upon save. This has to do with document validation.
    
    table.ParentNode.InsertAfter(new Paragraph(doc), table);
    
    dataDir = dataDir + "Table.CloneTableAndInsert_out_.doc";
    
    // Save the document to disk.
    
    doc.Save(dataDir);
    
    
    // [Visual Basic Code Sample]
     
    
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    
    Dim doc As New Document(dataDir & Convert.ToString("Table.SimpleTable.doc"))
    
    
    ' Retrieve the first table in the document.
    
    
    Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
    
    ' Create a clone of the table.
    
    
    Dim tableClone As Table = DirectCast(table.Clone(True), Table)
    
    
    ' Insert the cloned table into the document after the original
    
    
    table.ParentNode.InsertAfter(tableClone, table)
    
    
    ' Insert an empty paragraph between the two tables or else they will be combined into one
    
    
    ' upon save. This has to do with document validation.
    
    
    table.ParentNode.InsertAfter(New Paragraph(doc), table)
    
    
    dataDir = dataDir & Convert.ToString("Table.CloneTableAndInsert_out_.doc")
    
    ' Save the document to disk.
    
    doc.Save(dataDir)
    
    // Code sample Shows how to make a clone of the last row of a table and append it to the table.
    
    //[C# Code Sample]
     
    // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Document doc = new Document(dataDir + "Table.SimpleTable.doc");
    
    // Retrieve the first table in the document.
    
    Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
    
    // Clone the last row in the table.
    
    Row clonedRow = (Row)table.LastRow.Clone(true);
    
    // Remove all content from the cloned row's cells. This makes the row ready for
    
    // new content to be inserted into.
    
    foreach (Cell cell in clonedRow.Cells)
    
    cell.RemoveAllChildren();
    
    // Add the row to the end of the table.
    
    table.AppendChild(clonedRow);
    
    dataDir = dataDir + "Table.AddCloneRowToTable_out_.doc";
    
    // Save the document to disk.
    
    doc.Save(dataDir);
    
    // [Visual Basic Code Sample]
    
    // [Visual Basic Code Sample]
     
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Dim doc As New Document(dataDir & Convert.ToString("Table.SimpleTable.doc"))
    
    ' Retrieve the first table in the document.
    
    Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
    
    ' Clone the last row in the table.
    
    Dim clonedRow As Row = DirectCast(table.LastRow.Clone(True), Row)
    
    ' Remove all content from the cloned row's cells. This makes the row ready for
    
    ' new content to be inserted into.
    
    For Each cell As Cell In clonedRow.Cells
    
    cell.RemoveAllChildren()
    
    Next
    
    ' Add the row to the end of the table.
    
    
    table.AppendChild(clonedRow)
    
    dataDir = dataDir & Convert.ToString("Table.AddCloneRowToTable_out_.doc")
    
    
    ' Save the document to disk.
    
    doc.Save(dataDir)
    
    

    public by lbottaro modified Aug 18, 2014  21403  129  9  3

    How to programmatically create a Microsoft Word document in csharp

    This code shows how to simply create a doc using csharp and Microsoft Office Word library. 1) You need to add a reference to Microsoft.Office.Interop library in your project solution. 2) Add the following line to the end of the list of using directives: using Word = Microsoft.Office.Interop.Word; using System.Reflection; 3) Now you are
    private void button1_Click(object sender, EventArgs e)
            {
              object oMissing = System.Reflection.Missing.Value;
               object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
    
               //Start Word and create a new document.
               Word._Application oWord;
               Word._Document oDoc;
               oWord = new Word.Application();
               oWord.Visible = true;
               oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing);
    
               //Insert a paragraph at the beginning of the document.
               Word.Paragraph oPara1;
               oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
               oPara1.Range.Text = "Heading 1";
               oPara1.Range.Font.Bold = 1;
               oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
               oPara1.Range.InsertParagraphAfter();
    
               //Insert a paragraph at the end of the document.
               Word.Paragraph oPara2;
               object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara2.Range.Text = "Heading 2";
               oPara2.Format.SpaceAfter = 6;
               oPara2.Range.InsertParagraphAfter();
    
               //Insert another paragraph.
               Word.Paragraph oPara3;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
               oPara3.Range.Font.Bold = 0;
               oPara3.Format.SpaceAfter = 24;
               oPara3.Range.InsertParagraphAfter();
    
               //Insert a 3 x 5 table, fill it with data, and make the first row
               //bold and italic.
               Word.Table oTable;
               Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               int r, c;
               string strText;
               for (r = 1; r <= 3; r++)
                   for (c = 1; c <= 5; c++)
                   {
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
                   }
               oTable.Rows[1].Range.Font.Bold = 1;
               oTable.Rows[1].Range.Font.Italic = 1;
    
               //Add some text after the table.
               Word.Paragraph oPara4;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara4.Range.InsertParagraphBefore();
               oPara4.Range.Text = "And here's another table:";
               oPara4.Format.SpaceAfter = 24;
               oPara4.Range.InsertParagraphAfter();
    
               //Insert a 5 x 2 table, fill it with data, and change the column widths.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               for (r = 1; r <= 5; r++)
                   for (c = 1; c <= 2; c++)
                   {
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
                   }
               oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
               oTable.Columns[2].Width = oWord.InchesToPoints(3);
    
               //Keep inserting text. When you get to 7 inches from top of the
               //document, insert a hard page break.
               object oPos;
               double dPos = oWord.InchesToPoints(7);
               oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
               do
               {
                   wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                   wrdRng.ParagraphFormat.SpaceAfter = 6;
                   wrdRng.InsertAfter("A line of text");
                   wrdRng.InsertParagraphAfter();
                   oPos = wrdRng.get_Information
                                  (Word.WdInformation.wdVerticalPositionRelativeToPage);
               }
               while (dPos >= Convert.ToDouble(oPos));
               object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
               object oPageBreak = Word.WdBreakType.wdPageBreak;
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertBreak(ref oPageBreak);
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
               wrdRng.InsertParagraphAfter();
    
               //Insert a chart.
               Word.InlineShape oShape;
               object oClassType = "MSGraph.Chart.8";
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing);
    
               //Demonstrate use of late bound oChart and oChartApp objects to
               //manipulate the chart object with MSGraph.
               object oChart;
               object oChartApp;
               oChart = oShape.OLEFormat.Object;
               oChartApp = oChart.GetType().InvokeMember("Application",
                   BindingFlags.GetProperty, null, oChart, null);
    
               //Change the chart type to Line.
               object[] Parameters = new Object[1];
               Parameters[0] = 4; //xlLine = 4
               oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                   null, oChart, Parameters);
    
               //Update the chart image and quit MSGraph.
               oChartApp.GetType().InvokeMember("Update",
                   BindingFlags.InvokeMethod, null, oChartApp, null);
               oChartApp.GetType().InvokeMember("Quit",
                   BindingFlags.InvokeMethod, null, oChartApp, null);
               //... If desired, you can proceed from here using the Microsoft Graph 
               //Object model on the oChart and oChartApp objects to make additional
               //changes to the chart.
    
               //Set the width of the chart.
               oShape.Width = oWord.InchesToPoints(6.25f);
               oShape.Height = oWord.InchesToPoints(3.57f);
    
               //Add text after the chart.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               wrdRng.InsertParagraphAfter();
               wrdRng.InsertAfter("THE END.");
    
               //Close this form.
               this.Close();
    }
    

    public by lbottaro modified Jan 24, 2013  7211  9  6  0

    How to set a conditional formatting in a cell of Excel document in C#

    This c# code allows to set a conditional formatting for cells in a sheet for a Microsoft Excel document (xls). Conditional formatting allows to set some property to a cell based on the cell value.
    /// <summary>
    /// This method creates a Excel Conditional Formatting for cell
    /// </summary>
    /// <param name="ws">Worksheet to use</param>
    /// <param name="excelList_firstCell">First cell</param>
    /// <param name="excelList_lastCell">Last cell</param>
    /// <param name="condOperator">Operator to use for validation</param>
    /// <param name="condValidation">String to use for validation</param>
    /// <param name="c">Color to use when validating</param>
    private void Excel_createCellFormatValidation(Worksheet ws, string excelList_firstCell, string excelList_lastCell, XlFormatConditionOperator condOperator, string condValidation, Color c)
    {
    	FormatCondition cf = (FormatCondition)ws.get_Range(excelList_firstCell, excelList_lastCell).FormatConditions.Add(XlFormatConditionType.xlCellValue, condOperator, condValidation, Type.Missing);
    	cf.Interior.PatternColorIndex = Constants.xlAutomatic;
    	cf.Interior.Color = ColorTranslator.ToWin32(c);
    	cf.Font.Bold = true;
    }
    
    
    //Example of usage
    
    //cond_passed is a string which value must be present in the cell range to trigger the conditional formatting.
    string cond_passed = "SUCCESS";
    this.Excel_createCellFormatValidation(ws, "C1", "C19", XlFormatConditionOperator.xlEqual, cond_passed, Color.Green);
    

    public by johansonkatherine modified Mar 11, 2014  6331  1  10  5

    Save Microsoft OneNote (.one) file as an image (.PNG, .BMP, .JPEG, .GIF) file in C#/.NET

    The Aspose.Note for .NET API allows developers to open files & manipulate elements of OneNote books & export them to PNG, GIF, JPEG, BMP and PDF formats. The following code sample shows developers how to save OneNote File as an image in C#/.NET
    // Load the document into Aspose.Note.
        Document oneFile = new Document(@"FullFileName.one");
        // Save the document as GIF.
        oneFile.Save("FullFileName.gif", SaveFormat.Gif);
    	
        OR
    
        // Load the document into Aspose.Note.
        Document oneFile = new Document(@"FullFileName.one");
        // Initialize ImageSaveOptions object 
        ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png);
        // Set page index
        opts.PageIndex = 1;
        // Save the document as PNG.
        oneFile.Save(@"FullFileName.png", opts);
    

    public by johansonkatherine modified Apr 16, 2014  4569  0  6  3

    Java code for Changing Color Space of PDF Document

    This code shows how java developers can change color space of PDF document from RGB color to CMYK and vice versa by using Aspose.PDF for Java Library. The following methods have been implemented in the Operator class for changing colors. Use it to change some specific RGB/CMYK colors to CMYK/RGB color space, keeping the remaining PDF document as it
    Document doc = new Document(myDir + "input_color.pdf");
    OperatorCollection contents = doc.getPages().get_Item(1).getContents();
    System.out.println("Values of RGB color operators in the pdf document");
    for (int j = 1; j <= contents.size(); j++)
        {
    	Operator oper = contents.get_Item(j);
    	if (oper instanceof Operator.SetRGBColor || oper instanceof Operator.SetRGBColorStroke)
    	try {
    	    //Converting RGB to CMYK color
    	    System.out.println(oper.toString());
    
    	    double[] rgbFloatArray = new double[]
    	        {
    		    	Double.valueOf(oper.getParameters().get(0).toString()),
    		    	Double.valueOf(oper.getParameters().get(1).toString()),
    		    	Double.valueOf(oper.getParameters().get(2).toString()),
    	        };
    	    double[] cmyk = new double[4];
    	    if (oper instanceof Operator.SetRGBColor)
    	    {
    		((Operator.SetRGBColor)oper).getCMYKColor(rgbFloatArray, cmyk);
    		contents.set_Item(j, new Operator.SetCMYKColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
    		}
    		else if (oper instanceof Operator.SetRGBColorStroke)
    		{
    		    ((Operator.SetRGBColorStroke)oper).getCMYKColor(rgbFloatArray, cmyk);
    		   contents.set_Item(j, new Operator.SetCMYKColorStroke(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
    		}
    		    else
    throw new java.lang.Throwable("Unsupported command");
    
    	} catch (Throwable e) {
    	    e.printStackTrace();
    	}
    		        }
    doc.save(myDir + "input_colorout.pdf");
    
    //Testing the result
    System.out.println("Values of converted CMYK color operators in the result pdf document");
    doc = new Document(myDir + "input_colorout.pdf");
    contents = doc.getPages().get_Item(1).getContents();
    for (int j = 1; j <= contents.size(); j++)
        {
    	Operator oper = contents.get_Item(j);
    	if (oper instanceof Operator.SetCMYKColor || oper instanceof Operator.SetCMYKColorStroke)
    	{
    	   System.out.println(oper.toString());
    	}
       }
    

    public by sherazam modified Feb 17, 2016  2781  0  6  0

    How to Convert OneNote File or Specific Page of OneNote Document into Image using .NET

    // Enter here the actual content of the snippet.            //Converting OneNote to Image using the Default Options
    
    // [C# Code Sample]
    
    // Load the document into Aspose.Note.
    Document oneFile = new Document(@"FullFileName.one");
    
    // Save the document as Gif.
    oneFile.Save("FullFileName.gif", SaveFormat.Gif);
    
    //[VB.NET Code Sample]
    
    ' Load the document into Aspose.Note.
    Dim oneFile As New Document("FullFileName.one")
    
    ' Save the document as Gif.
    oneFile.Save("FullFileName.gif", SaveFormat.Gif)
    
    //Converting a Specific Page in a OneNote Document to Image
    
    // [C# Code Sample]
    
    // Load the document into Aspose.Note.
    Document oneFile = new Document(@"FullFileName.one");
    
    // Initialize ImageSaveOptions object
    ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png);
    // set page index
    opts.PageIndex = 1;
    
    // Save the document as PNG.
    oneFile.Save(@"FullFileName.png", opts);
    
    //[VB.NET Code Sample]
    
    ' Load the document into Aspose.Note.
    Dim oneFile As New Document("FullFileName.one")
    
    ' Initialize ImageSaveOptions object
    Dim opts As New ImageSaveOptions(SaveFormat.Png)
    ' set page index
    opts.PageIndex = 1
    
    ' Save the document as PNG.
    oneFile.Save("FullFileName.png", opts)
    
    

    public by johansonkatherine modified Jun 19, 2014  2851  3  6  1

    PHP Code to Protect a Word Document Using Aspose for Cloud API

    The following technical tip shows how php developers can protect their word documents in cloud using Aspose for Cloud SDK in php.
    use Aspose\Cloud\Common\AsposeApp;
    use Aspose\Cloud\Common\Product;
    use Aspose\Cloud\Common\Utils;
    use Aspose\Cloud\Words\Document;
    
    /**** Section 1 ****/
    Product::$baseProductUri = 'http://api.aspose.com/v1.1';
    AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx";
    AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";
    AsposeApp::$outPutLocation = getcwd() . "/output/";
    /**** End Section 1 ****/
    
    /**** Section 2 ****/
    $fileName = "Test.docx";
    $password = "123456";
    $protectionType = "AllowOnlyComments";
    
    $doc = new Document($fileName);
    $result = $doc->protectDocument($password, $protectionType);
    /**** End Section 2 ****/
    			
    • Public Snippets
    • Channels Snippets