working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,819 snippets matching: extract

    public by antlong  489215  15  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 skaggej  237861  1  6  0

    SharePoint 2010 - Bulk Upload Solution Packages

    When migrating a SharePoint environment from 2007 to 2010, don't forget about your solution packages! You can extract them from the SharePoint 2007 Solution Store, then use this script to upload them all to SharePoint 2010 in seconds!
    $solutions = Get-ChildItem -Path "C:\downloads\Exported Solution Packages"
    $solutions | ForEach-Object {add-spsolution -literalpath "C:\Exported Solution Packages\$_"}

    public by hypn0z  136857  0  4  0

    Extract line range from file

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

    public by p.kontalis  99040  2  5  0

    VTiger Extraction Customers' Data by City

    Extract from Vtiger Customers' List with address and to whom they have been assigned
    SET @city = '[CITY NAME]'; #Replace [CITY NAME] with your preferable city name
    SET @db_name='[DATABASE NAME]'; #Replace [DATABASE NAME] with your database name
    SET @myquery = CONCAT('
    SELECT	', @db_name, '.vtiger_account.accountid AS \'Company Code\',
    		', @db_name, '.vtiger_account.accountname AS \'Company\', 
    		', @db_name, '.vtiger_account.phone AS \'Phone 1\', 
    		', @db_name, '.vtiger_account.otherphone AS \'Phone 2\', 
    		', @db_name, '.vtiger_account.email1 AS \'Email 1\', 
    		', @db_name, '.vtiger_account.email2 AS \'Email 2\', 
    		', @db_name, '.vtiger_account.website AS \'Website\', 
    		', @db_name, '.vtiger_account.fax AS \'Fax\',
    		', @db_name, '.vtiger_accountbillads.bill_city AS \'City\',
    		', @db_name, '.vtiger_accountbillads.bill_code AS \'TK\',
    		', @db_name, '.vtiger_accountbillads.bill_country AS \'Country\',
    		', @db_name, '.vtiger_accountbillads.bill_state AS \'State\',
    		', @db_name, '.vtiger_accountbillads.bill_street AS \'Street\',
    		', @db_name, '.vtiger_accountbillads.bill_pobox AS \'TK\', 
    		', @db_name, '.vtiger_users.last_name AS \'Αssignment το\'
    FROM ', @db_name, '.vtiger_account
    INNER JOIN ', @db_name, '.vtiger_accountbillads 
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_accountbillads.accountaddressid
    INNER JOIN ', @db_name, '.vtiger_crmentity
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_crmentity.crmid	
    LEFT JOIN ', @db_name, '.vtiger_users
    ON ', @db_name, '.vtiger_crmentity.smownerid = ', @db_name, '.vtiger_users.id
    WHERE ', @db_name, '.vtiger_accountbillads.bill_city=@city
    AND ', @db_name, '.vtiger_crmentity.setype=\'Accounts\' 
    ');
    PREPARE stmt FROM @myquery;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
                
    

    public by sherazam  2770  3  6  0

    How to Extract Text from PDF Documents Based on Columns inside .NET Apps

    // Enter here the actual content of the snippet.            //The following code snippet shows the steps to reduce text size and then try extracting text from PDF document.
    
    //[C# Code Sample]
     
    
    string path = "D:\\Temp\\";
    InitLicense();
    Document pdfDocument = new Document(path + "net_New-age NED's.pdf");
    
    TextFragmentAbsorber tfa = new TextFragmentAbsorber();
    pdfDocument.Pages.Accept(tfa);
    TextFragmentCollection tfc = tfa.TextFragments;
    foreach (TextFragment tf in tfc)
    {
        //need to reduce font size at least for 70%
        tf.TextState.FontSize = tf.TextState.FontSize * 0.7f;
    }
    Stream st = new MemoryStream();
    pdfDocument.Save(st);
    pdfDocument = new Document(st);
    
    TextAbsorber textAbsorber = new TextAbsorber();
    pdfDocument.Pages.Accept(textAbsorber);
    String extractedText = textAbsorber.Text;
    textAbsorber.Visit(pdfDocument);
    
    System.IO.File.WriteAllText(path + "Extracted.txt", extractedText);
    
    // [VB.NET Code Sample]
     
    
    Dim path As String = "D:\\Temp\\"
    ' instantiate Document object 
    Dim pdfDocument As Document = New Document(path + "net_New-age NED's.pdf")
    
    Dim tfa As Aspose.Pdf.Text.TextFragmentAbsorber = New Aspose.Pdf.Text.TextFragmentAbsorber()
    pdfDocument.Pages.Accept(tfa)
    Dim tfc As Aspose.Pdf.Text.TextFragmentCollection = tfa.TextFragments
    For Each tf As Aspose.Pdf.Text.TextFragment In tfc
    
        ' need to reduce font size at least for 70%
        tf.TextState.FontSize = tf.TextState.FontSize * 0.7F
    Next
    ' create temporary stream object
    Dim st As Stream = New MemoryStream()
    ' save PDF file with reduced font size
    pdfDocument.Save(st)
    ' Instantiate Document object with stream instance
    pdfDocument = New Document(st)
    
    Dim textAbsorber As Aspose.Pdf.Text.TextAbsorber = New Aspose.Pdf.Text.TextAbsorber()
    pdfDocument.Pages.Accept(textAbsorber)
    Dim extractedText As String = textAbsorber.Text
    textAbsorber.Visit(pdfDocument)
    
    System.IO.File.WriteAllText(path + "Extracted.txt", extractedText)
     
    //Second approach - Using ScaleFactor
    
    //[C# Code Sample]
     
    
    Document pdfDocument = new Document(inputFile);
    
    TextAbsorber textAbsorber = new TextAbsorber();
    textAbsorber.ExtractionOptions = new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Pure);
    //Setting scale factor to 0.5 is enough to split columns in the majority of documents
    //Setting of zero allows to algorithm choose scale factor automatically
    textAbsorber.ExtractionOptions.ScaleFactor = 0.5; /* 0; */
    pdfDocument.Pages.Accept(textAbsorber);
    String extractedText = textAbsorber.Text;
    
    System.IO.File.WriteAllText(outFile, extractedText);
     
    // [VB.NET Code Sample]
     
    
    Dim pdfDocument As Document = New Document(inputFile)
    
    Dim textAbsorber As Aspose.Pdf.Text.TextAbsorber = New Aspose.Pdf.Text.TextAbsorber()
    textAbsorber.ExtractionOptions = New TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Pure)
    'Setting scale factor to 0.5 is enough to split columns in the majority of documents
    'Setting of zero allows to algorithm choose scale factor automatically
    textAbsorber.ExtractionOptions.ScaleFactor = 0.5 ' 0;
    pdfDocument.Pages.Accept(textAbsorber)
    Dim extractedText As String = textAbsorber.Text
    
    System.IO.File.WriteAllText(outFile, extractedText)
    

    public by lbottaro  2863  1  7  3

    Extract or Unpack a TarBz2 File

    This code shows how to extract a tar bz2 file in linux. Command options: -x : Extract a tar ball. -v : Verbose output or show progress while extracting files. -f : Specify an archive or a tarball filename. -j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
    # This will extract the bz2 in a specific directory
    tar xvf file.tar.bz2 -C targetDirectory/
    
    # This will zip the directory into a file
    tar cvjf file.tar.bz2 targetDirectory/

    public by lbottaro  1910  0  5  0

    Extract or Unpack a TarBall File

    This simple snippet shows hot to extract a tar file
    tar -xvf file.tar

    public by Geometry  857  0  4  0

    Extract integer value from string representation of value/comments

    Extract integer value from string representation of value/comments
    // Extract integer value from string representation of value/comments
    private static int ExtractIntegerValue(string strValue)
    {
        try
        {
            // split value from comment
            string[] strs = strValue.Split('/');
    
            // return value as integer
            return int.Parse(strs[0].Trim());
        }
        catch
        {
            throw new ArgumentException("The stream does not contain valid FITS image.");
        }
    }

    public by johansonkatherine  6778  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 sai1857  2203  2  5  1

    Extract urls from a string and list the strings and urls in the same sequence.

    public static List<String> extractUrls(String value) throws Exception
    	{
    	    if (value == null) throw new Exception("urls to extract");
    	    List<String> result = new ArrayList<String>();
    	   String urlPattern = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
    	    Pattern p = Pattern.compile(urlPattern,Pattern.CASE_INSENSITIVE);
    	    Matcher m = null;
    	    while(value.length()>0)
    	    {
    	    	m = p.matcher(value);
    	    	if(m.find())
    	    	{
    	    		String pre = value.substring(0, m.start(0));
    	    		String url = value.substring(m.start(0),m.end(0));
    	    		value = value.substring(m.end(0));
    	    		result.add(pre.trim());
    	    		result.add(url.trim());
    	    	}
    	    	else
    	    	{
    	    		result.add(value.trim());
    	    		break;
    	    	}
    	    }
    	    
    	    return result;
    	}
    • Public Snippets
    • Channels Snippets