working on it ...

Filters

Explore Public Snippets

Sort by

Found 3 snippets matching: ".net pdf component"

    public by sherazam  2703  8  5  0

    How to Convert Large Text Files to PDF inside .NET Applications

    This technical tip shows how to convert a text file to PDF inside .NET applications. We are often asked if we can quickly provide some code which can accomplish this task and save them the effort of going through the documentation. So for the benefit of everyone, we present here a simple example which can be used as it is to easily and efficiently
    // Enter here the actual content of the snippet.            
    //Please take a look over the following code snippet for converting a text file to PDF
    
    //[C# Code Sample]
     
    
    //read the source text file
    System.IO.TextReader tr = new StreamReader("test.txt");
    
    //Instantiate Pdf pbject by calling its empty constructor
    Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
    
    //Create a new section in the Pdf object
    Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
    
    //Create a new text paragraph and pass the text to its constructor as argument
    Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text(tr.ReadToEnd());
    sec1.Paragraphs.Add(t2);
    
    pdf1.Save("test.Pdf");
    
    //[VB.NET Code Sample]
     
    
    Dim tr As System.IO.TextReader = New StreamReader("test.txt")
    
    'Instantiate Pdf pbject by calling its empty constructor
    Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
    
    'Create a new section in the Pdf object
    Dim sec1 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()
    
    'Create a new text paragraph and pass the text to its constructor as argument
    Dim t2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(tr.ReadToEnd())
    
    sec1.Paragraphs.Add(t2)
    
    pdf1.Save("test.Pdf")
    
    //Converting Large Text files to PDF
    
    //[C# Code Sample]
     
    
    //Instantiate Pdf pbject by calling its empty constructor
    Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
    //Create a new section in the Pdf object
    Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
    
    //Specify the location of input text file
    String FILE_NAME = "d:/pdftest/LargeText.txt";
    
    if (File.Exists(FILE_NAME))
       {
           
        System.IO.TextReader objReader =  new System.IO.StreamReader(FILE_NAME);
        // Read the file till the end of the file has come
        do 
        {
         //Create a new text paragraph & pass text to its constructor as argument
         Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text(objReader.ReadLine());
         // add the text object to paragraphs collection of section
         sec1.Paragraphs.Add(t2);
    
         // Read till the end of file
         }while(objReader.Peek() != -1);
    
       // Close the StreamReader object
       objReader.Close();
       }
       else
       MessageBox.Show("File Does Not Exist");
        
    // Save the PDF file
    pdf1.Save("d:/pdftest/large_textfile.pdf");
    
    //[VB.NET Code Sample]
     
    
    'Instantiate Pdf pbject by calling its empty constructor
    Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
    
    'Create a new section in the Pdf object
    Dim sec1 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()
    
    ' Specify the location of input text file
    Dim FILE_NAME As String = "d:/pdftest/LargeText.txt"
    
    If System.IO.File.Exists(FILE_NAME) = True Then
    
        Dim objReader As New System.IO.StreamReader(FILE_NAME)
        ' Read the file till the end of the file has come
        Do While objReader.Peek() <> -1
            'Create a new text paragraph and pass text to its constructor as argument
            Dim t2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(objReader.ReadLine())
            ' add the text object to paragraphs collection of section
            sec1.Paragraphs.Add(t2)
        Loop
        ' Close the StreamReader object
        objReader.Close()
    Else
        MsgBox("File Does Not Exist")
    End If
    
    ' Save the PDF file
    pdf1.Save("d:/pdftest/large_textfile.pdf")
    
    

    public by sherazam  2785  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 sherazam  3080  0  5  0

    How to Add Text with Transparent Color in PDF File using .NET

    // Enter here the actual content of the snippet.      
    //The following code snippet shows how to add text with transparent color.
    
    //C# Code Sample
    
    // create Document instance
    Document doc = new Document();
    // create page to pages collection of PDF file
    Aspose.Pdf.Page page = doc.Pages.Add();
    
    // create Graph object 
    Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
    // create rectangle instance with certain dimensions
    Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400);
    // create color object from Alpha color channel
    rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
    // add rectanlge to shapes collection of Graph object
    canvas.Shapes.Add(rect);
    // add graph object to paragraphs collection of page object
    page.Paragraphs.Add(canvas);
    // set value to not change position for graph object
    canvas.IsChangePosition = false;
    
    // create TextFragment instance with sample value
    TextFragment text = new TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ");
    // create color object from Alpha channel
    Aspose.Pdf.Color color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0);
    // set color information for text instance
    text.TextState.ForegroundColor = color;
    // add text to paragraphs collection of page instance
    page.Paragraphs.Add(text);
    // save PDF file
    doc.Save("c:/Transparent_Text.pdf");
    
    //VB.NET Code Sample
    
    ' create Document instance
    Dim doc As Document = New Document()
    ' create page to pages collection of PDF file
    Dim page As Aspose.Pdf.Page = doc.Pages.Add()
    
    ' create Graph object
    Dim canvas As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
    ' create rectangle instance with certain dimensions
    Dim rect As Aspose.Pdf.Drawing.Rectangle = New Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400)
    ' create color object from Alpha color channel
    rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)))
    ' add rectanlge to shapes collection of Graph object
    canvas.Shapes.Add(rect)
    ' add graph object to paragraphs collection of page object
    page.Paragraphs.Add(canvas)
    ' set value to not change position for graph object
    canvas.IsChangePosition = False
    
    ' create TextFragment instance with sample value
    Dim text As Aspose.Pdf.Text.TextFragment = New TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ")
    ' create color object from Alpha channel
    Dim color As Aspose.Pdf.Color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0)
    ' set color information for text instance
    Text.TextState.ForegroundColor = color
    ' add text to paragraphs collection of page instance
    page.Paragraphs.Add(Text)
    ' save PDF file
    doc.Save("c:/Transparent_Text.pdf")
          

    List Complete ( 3 snippets total )

    • Public Snippets
    • Channels Snippets