working on it ...

Filters

Explore Public Snippets

Sort by

Found 3 snippets matching: ".net pdf api"

    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  2884  3  5  0

    How to Convert PDF Pages to TIFF Image inside .NET Applications

    This technical tip shows how to convert PDF pages to TIFF image inside .NET Applications. The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named Process which allows you to convert all the pages in a PDF file to a single TIFF image. To convert a particular page in a PDF file to a TIFF image, use an
    // Enter here the actual content of the snippet.            
    //The following code snippet shows how to convert all the PDF pages to a single TIFF image.
    
    //[C# Code Sample]
     
    
    // Open document
    Document pdfDocument = new Document("input.pdf");
    
    // Create Resolution object
    Resolution resolution = new Resolution(300);
    
    // Create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.None;
    tiffSettings.Depth = ColorDepth.Default;
    tiffSettings.Shape = ShapeType.Landscape;
    tiffSettings.SkipBlankPages = false;
    
    // Create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    
    // Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, "output.tif");
    
    //[VB.NET Code Sample]
     
    
    'Open document
    Dim pdfDocument As New Document("input.pdf")
    
    'Create Resolution object
    Dim resolution As New Resolution(300)
    
    'Create TiffSettings object
    Dim tiffSettings As New TiffSettings()
    tiffSettings.Compression = CompressionType.None
    tiffSettings.Depth = ColorDepth.Default
    tiffSettings.Shape = ShapeType.Landscape
    tiffSettings.SkipBlankPages = False
    
    'Create TIFF device
    Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
    
    'Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, "output.tif")
    
    
    //Convert One Page to TIFF Image
    
    //[C# Code Sample]
     
    
    // Open document
    Document pdfDocument = new Document("input.pdf");
    
    // Create Resolution object
    Resolution resolution = new Resolution(300);
    
    // Create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.None;
    tiffSettings.Depth = ColorDepth.Default;
    tiffSettings.Shape = ShapeType.Landscape;
    tiffSettings.SkipBlankPages = false;
    
    // Create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    
    
    // Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, 1, 1, "output.tif");
    
    
    //[VB.NET Code Sample]
     
    
    'Open document
    Dim pdfDocument As New Document("input.pdf")
    
    'Create Resolution object
    Dim resolution As New Resolution(300)
    
    'Create TiffSettings object
    Dim tiffSettings As New TiffSettings()
    tiffSettings.Compression = CompressionType.None
    tiffSettings.Depth = ColorDepth.Default
    tiffSettings.Shape = ShapeType.Landscape
    tiffSettings.SkipBlankPages = False
    
    'Create TIFF device
    Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
    
    'Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, 1, 1, "output.tif")
    
    //Use Bradley algorithm during conversion
    
    //[C# Code Sample]
     
    
    string outputImageFile = @"c:\resultant.tif";
    string outputBinImageFile = @"c:\37116-bin.tif";
    //open document
    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
    //create Resolution object
    Resolution resolution = new Resolution(300);
    //create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.LZW;
    tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
    //create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    //convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, outputImageFile);
    
    using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
    {
           using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
           {
                  tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
           }
    }
    
    //[VB.NET Code Sample]
     
    
    Dim outputImageFile As String = "c:\resultant.tif"
    Dim outputBinImageFile As String = "c:\37116-bin.tif"
    'open document
    Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document("c:\input.pdf")
    'create Resolution object
    Dim resolution As Aspose.Pdf.Devices.Resolution = New Aspose.Pdf.Devices.Resolution(300)
    'create TiffSettings object
    Dim tiffSettings As TiffSettings = New TiffSettings()
    tiffSettings.Compression = CompressionType.LZW
    tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp
    'create TIFF device
    Dim tiffDevice As TiffDevice = New TiffDevice(resolution, tiffSettings)
    'convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, outputImageFile)
    
    Using inStream As FileStream = New FileStream(outputImageFile, FileMode.Open)
    
        Using outStream As FileStream = New FileStream(outputBinImageFile, FileMode.Create)
            tiffDevice.BinarizeBradley(inStream, outStream, 0.1)
        End Using
    End Using
    
    

    public by sherazam  2156  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")
    
    

    List Complete ( 3 snippets total )

    • Public Snippets
    • Channels Snippets