working on it ...

Filters

Explore Public Snippets

Sort by

Found 33k snippets matching: line

    public by antlong modified Aug 10, 2015  488646  10  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by sTiLL-iLL modified Feb 17, 2015  203045  1  8  27

    kWetntz.js ... next in line please...

    sequential async execution... NEXT!!! *** idk if this even werks, havent tried yet! ***
    //  sequential execution....
    
    var kWentz = (function() {
        var roster = {}, lastTime = {}, slf = this,
            signal = function(name, arg) {
               var idx=0, kall = {};
               if(roster[name]) {
                   for(idx; kall=roster[name][idx]; idx++) {
                       kall(arg);
                   }
               }
            },
            receive = function(name, receiver) {
               if(!roster[name]) {
                  roster[name] = [];
               }
               roster[name].push(receiver);
               return slf;
            },
            drop = function(name, receiver) {
               if(roster[name]) {
                   var lst = [], kall = {}, idx = 0;
                   for(idx; kall=roster[name][idx]; idx++) {
                       if(kall !== receiver) {
                           lst.push(kall);
                       }
                   }
                   roster[name] = lst;
               }
               return slf;
            },
            exec = function() {
              if(arguments.length > 0) {
                var cbks = [], kall = {}, elm = {}, idx = 0;
                for(idx; kall=arguments[idx]; idx++) {
                   cbks.push(kall);
                }
                elm = cbks.shift();
                if(typeof elm === 'function') {
                   elm(lastTime, function(dta) {
                         lastTime = dta;
                         exec.apply(slf, cbks);
                   });
                } 
                else if(typeof elm === 'object' && elm.length > 0) {
                   var kall = elm.shift(),
                      callBK = function(dta) {
                         lastTime = dta;
                         exec.apply(slf, cbks);
                      };
                   kall.apply(kall, elm.concat([callBK]));
                }
             } 
             else {
                  signal("done", lastTime);
             }
             return slf;
          };
          return {
              execute: exec,
              receive: receive,
              drop: drop
          };
    })();            

    public by sherazam modified Jul 27, 2016  120423  0  5  0

    How to Set Line Spacing of a Paragraph in an Excel Shape or Textbox inside .NET Apps

    This technical tip shows how to Set Line Spacing of the Paragraph in a Shape or Textbox in .NET applications. You can set the line space of the paragraph, its space before and space after using the TextParagraph.LineSpace, TextParagraph.SpaceBefore and TextParagraph.SpaceAfter respectively. The following example shows how to Set Line Spacing of the
    // Enter here the actual content of the snippet.            
    
    //[C# Code]
     
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    
    // Create a workbook
    Workbook wb = new Workbook();
    
    // Access first worksheet
    Worksheet ws = wb.Worksheets[0];
    
    // Add text box inside the sheet
    ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200);
    
    // Access first shape which is a text box and set is text
    Shape shape = ws.Shapes[0];
    shape.Text = "Sign up for your free phone number.\nCall and text online for free.";
    
    // Acccess the first paragraph
    TextParagraph p = shape.TextBody.TextParagraphs[1];
    
    // Set the line space
    p.LineSpaceSizeType = LineSpaceSizeType.Points;
    p.LineSpace = 20;
    
    // Set the space after
    p.SpaceAfterSizeType = LineSpaceSizeType.Points;
    p.SpaceAfter = 10;
    
    // Set the space before
    p.SpaceBeforeSizeType = LineSpaceSizeType.Points;
    p.SpaceBefore = 10;
    
    // Save the workbook in xlsx format
    wb.Save(dataDir + "output_out_.xlsx", SaveFormat.Xlsx); 
    
    //[VB.NET Code]
    
    ' For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    ' The path to the documents directory.
    Dim dataDir As String = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    
    ' Create a workbook
    Dim wb As New Workbook()
    
    ' Access first worksheet
    Dim ws As Worksheet = wb.Worksheets(0)
    
    ' Add text box inside the sheet
    ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200)
    
    ' Access first shape which is a text box and set is text
    Dim shape As Shape = ws.Shapes(0)
    shape.Text = "Sign up for your free phone number." & vbLf & "Call and text online for free."
    
    ' Acccess the first paragraph
    Dim p As TextParagraph = shape.TextBody.TextParagraphs(1)
    
    ' Set the line space
    p.LineSpaceSizeType = LineSpaceSizeType.Points
    p.LineSpace = 20
    
    ' Set the space after
    p.SpaceAfterSizeType = LineSpaceSizeType.Points
    p.SpaceAfter = 10
    
    ' Set the space before
    p.SpaceBeforeSizeType = LineSpaceSizeType.Points
    p.SpaceBefore = 10
    
    ' Save the workbook in xlsx format
    wb.Save(dataDir & Convert.ToString("output_out_.xlsx"), SaveFormat.Xlsx) 
    
    

    public by hypn0z modified Jan 8, 2015  136626  0  4  0

    Extract line range from file

    perl -ne 'print if 16224..16482' file.txt > new_file.txt        
    

    public by lbottaro modified Jan 4, 2014  20104  228  8  0

    How to programmatically convert the Visual Studio coverage file to coveragexml by command line tool in csharp

    This code shows how to programmatically export and convert the coverage data ( .coverage) generated by Visual Studio into a readable xml file (.coveragexml). The xml file can be used to generated a code coverage report, eg using the ReportGenerator tool. The conversion is done using the CoverageInfo and CoverageDS objects and invoking the metho
    using Microsoft.VisualStudio.Coverage.Analysis;
    
    namespace CodeCoverageConverter
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args == null || args.Length != 3 || args[0] == null || args[1] == null ||  args[2] == null ||
                    string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || string.IsNullOrEmpty(args[2]))
                {
                    help();
                    return;
                }
                string coverageFileName = args[0];
                string dllFileName = args[1];
                string coverageXmlFileName = args[2];
                Console.WriteLine("args[0] = " + coverageFileName);
                Console.WriteLine("args[1] = " + dllFileName);
                Console.WriteLine("args[2] = " + coverageXmlFileName);
    
                using (CoverageInfo info = CoverageInfo.CreateFromFile(coverageFileName, new string[] { dllFileName }, new string[] { }))
                {
                    CoverageDS data = info.BuildDataSet();
    
                    data.WriteXml(coverageXmlFileName);
                }
            }
    
            static private void help()
            {
                Console.WriteLine("Help!");
                Console.Write(@"
                    Arguments
                        Args[0]: data coverage file name (data.coverage)
                        Args[1]: DLL to use (myProject.dll)
                        Args[2]: coveragexml file name to be generated (converted.coveragexml)
                     ");
    
            }
    
        }
    }

    public by micurs modified Oct 30, 2015  32613  448  8  3

    HTML5 Canvas: drawing an arrow at the end of the line

    The Canvas 2D API does not have a way to draw an arrow as endpoint of a line. This simple code shows how you can draw one yourself. With this HTML: Running demo available here: http://jsfiddle.net/n7e2zhj3/2/
    var canvas = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
    
    function grid() {
        for (var x = 0.5; x < canvas.width; x += 10) {
            ctx.moveTo(x, 0);
            ctx.lineTo(x, canvas.height);
        }
        for (var y = 0.5; y < canvas.height; y += 10) {
            ctx.moveTo(0, y);
            ctx.lineTo(canvas.width, y);
        }
        ctx.strokeStyle = "#eee";
        ctx.stroke();
    }
    
    function arrow(p1, p2) {
    
        ctx.save();
        var dist = Math.sqrt((p2[0] - p1[0]) * (p2[0] - p1[0]) + (p2[1] - p1[1]) * (p2[1] - p1[1]));
    
        ctx.beginPath();
        ctx.lineWidth = 2;
        ctx.strokeStyle = '#0000ff';
        ctx.moveTo(p1[0], p1[1]);
        ctx.lineTo(p2[0], p2[1]);
        ctx.stroke();
    
        var angle = Math.acos((p2[1] - p1[1]) / dist);
    
        if (p2[0] < p1[0]) angle = 2 * Math.PI - angle;
    
        var size = 15;
    
        ctx.beginPath();
        ctx.translate(p2[0], p2[1]);
        ctx.rotate(-angle);
        ctx.fillStyle = '#0000ff';
        ctx.lineWidth = 2;
        ctx.strokeStyle = '#ff0000';
        ctx.moveTo(0, -size);
        ctx.lineTo(-size, -size);
        ctx.lineTo(0, 0);
        ctx.lineTo(size, -size);
        ctx.lineTo(0, -size);
        ctx.closePath();
        ctx.fill();
        ctx.stroke();
        ctx.restore();
    }
    
    $('#myCanvas').bind('mousemove', function (e) {
        var offset = $(this).offset();
        var p1 = [200.0, 200.0];
        var p2 = [e.pageX - offset.left, e.pageY - offset.top];
    
        ctx.clearRect(0, 0, 400, 400);
        grid();
        arrow(p1, p2);
    })                                  

    public by qxshower modified Apr 24, 2015  118123  0  4  0

    IsNewLine

    check if a character is a new line specifier
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    static bool IsNewLine(char c)
    {
        switch (c)
        {
            case '\n':
            case '\r':
            case '\f':
                return true;
            default:
                return false;
        }
    }            

    public by sherazam modified Jul 20, 2016  1825  0  5  0

    How to Add Rectangle or Line Object to An Existing PDF File using .NET

    This technical tip shows how .NET developers can add line object to an Existing PDF File inside their .NET applications. Aspose.Pdf for .NET supports the feature to add graph objects (for example graph, line, rectangle etc.) to PDF documents. You also get the leverage to add Line object where you can also specify the dash pattern, color and other f
    // Enter here the actual content of the snippet.   
    //The following code snippet shows how to add a Rectangle object that is filled with color.
    
    //[C# Code]
     
    // Create Document instance
    Document doc = new Document();
    // Add page to pages collection of PDF file
    Page page = doc.Pages.Add();
    // Create Graph instance
    Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);             
    // Add graph object to paragraphs collection of page instance
    page.Paragraphs.Add(graph);
    // Create Rectangle instance
    Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[]{100, 100, 200, 100});
    // Specify fill color for Graph object
    line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
    line.GraphInfo.DashPhase = 1;
    // Add rectangle object to shapes collection of Graph object
    graph.Shapes.Add(line);
    // Save PDF file
    doc.Save("c:/pdftest/LineAdded.pdf");
    
    //[VB.NET Code]
     
    ' Create Document instance
    Dim doc As Document = New Document()
    ' Add page to pages collection of PDF file
    Dim page As Page = doc.Pages.Add()
    ' Create Graph instance
    Dim graph As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
    ' Add graph object to paragraphs collection of page instance
    page.Paragraphs.Add(graph)
    ' Create Rectangle instance
    Dim line As Aspose.Pdf.Drawing.Line = New Aspose.Pdf.Drawing.Line(New Single() {100, 100, 200, 100})
    ' Specify fill color for Graph object
    line.GraphInfo.DashArray = New Integer() {0, 1, 0}
    line.GraphInfo.DashPhase = 1
    ' Add rectangle object to shapes collection of Graph object
    graph.Shapes.Add(line)
    ' Save PDF file
    doc.Save("c:/pdftest/LineAdded.pdf")
    
    //DashLengthInBlack and DashLengthInWhite properties for Line object
    
    //[C# Code]
     
     // instantiate Document instance
    Document doc = new Document();
    // add page to pages collection of Document object
    Page page = doc.Pages.Add();
    // create Drawing object with certain dimensions
    Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
    // add drawing object to paragraphs collection of page instance
    page.Paragraphs.Add(canvas);
    // create Line object
    Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { 100, 100, 200, 100 });
    // set color for Line object
    line.GraphInfo.Color = Aspose.Pdf.Color.Red;
    // specify dash array for line object
    line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
    // set the dash phase for Line instance
    line.GraphInfo.DashPhase = 1;
    // add line to shapes collection of drawing object
    canvas.Shapes.Add(line);
    // save PDF document
    doc.Save("c:/DashLineInBlack.pdf");
    
    //[VB.NET Code]
     
    ' instantiate Document instance
    Dim doc As Document = New Document()
    ' add page to pages collection of Document object
    Dim page As Page = doc.Pages.Add()
    ' create Drawing object with certain dimensions
    Dim canvas As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
    ' add drawing object to paragraphs collection of page instance
    page.Paragraphs.Add(canvas)
    ' create Line object
    Dim line As Aspose.Pdf.Drawing.Line = New Aspose.Pdf.Drawing.Line(New Single() {100, 100, 200, 100})
    ' set color for Line object
    line.GraphInfo.Color = Aspose.Pdf.Color.Red
    ' specify dash array for line object
    line.GraphInfo.DashArray = New Integer() {0, 1, 0}
    ' set the dash phase for Line instance
    line.GraphInfo.DashPhase = 1
    ' add line to shapes collection of drawing object
    canvas.Shapes.Add(line)
    ' save PDF document
    doc.Save("c:/DashLineInBlack.pdf")
    
    

    public by mporru modified Mar 29, 2013  7388  7  8  1

    Java split a string by new line

    How to split a string by new line
    public static String[] countLines(String str) {
    	return str.split("\r\n|\r|\n");
    }

    public by Geometry modified Aug 7, 2016  895  0  5  0

    Line: Draw a line on the specified image.

    Draw a line on the specified image. Source image data to draw on. The first point to connect. The second point to connect. Line's color. The source image has incorrect pixel format.
    /// <summary>
    /// Draw a line on the specified image.
    /// </summary>
    /// 
    /// <param name="imageData">Source image data to draw on.</param>
    /// <param name="point1">The first point to connect.</param>
    /// <param name="point2">The second point to connect.</param>
    /// <param name="color">Line's color.</param>
    /// 
    /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception>
    /// 
    public static void Line(BitmapData imageData, IntPoint point1, IntPoint point2, Color color)
    {
        Line(new UnmanagedImage(imageData), point1, point2, color);
    }
    • Public Snippets
    • Channels Snippets