Close





 

Spire.PDF enables your .NET application to convert image to PDF. If you have a lot of images, photos or pictures with any format such as jpg, PNG, bmp, tiff, etc. you can use Spire.PDF to convert all of them to PDF format. With special features, Spire.PDF can help you encrypt them and watermark them when you convert.

 

Download Spire.PDF (or Spire.Office) with .NET framework 2.0 (or above) together. Create a project and add Spire.PDF dll as reference. Copy the C#/VB.NET code below into the project to convert files from Image to PDF.

Note: Please make sure Spire.PDF and Visual Studio are correctly installed on system.

 

Convert Image to PDF with C# Code:

[C#]
using System;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            PdfSection section = doc.Sections.Add();
            PdfPageBase page = doc.Pages.Add();
            PdfImage image = PdfImage.FromFile("test.png");

            float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
            float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
            float fitRate = Math.Max(widthFitRate, heightFitRate);
            float fitWidth = image.PhysicalDimension.Width / fitRate;
            float fitHeight = image.PhysicalDimension.Height / fitRate;

            page.Canvas.DrawImage(image, 0, 0, fitWidth, fitHeight);
            doc.SaveToFile("test.pdf");
            doc.Close();
        }
    }
}    

Convert Image to PDF with VB.NET Code:

[Visual Basic]
Imports System.Text
Imports Spire.Pdf
Imports System.Drawing.Imaging
Imports Spire.Pdf.Graphics

Namespace ConsoleTest
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			Dim doc As New PdfDocument()
			Dim section As PdfSection = doc.Sections.Add()
			Dim page As PdfPageBase = doc.Pages.Add()
			Dim image As PdfImage = PdfImage.FromFile("test.png")

			Dim widthFitRate As Single = image.PhysicalDimension.Width \ page.Canvas.ClientSize.Width
			Dim heightFitRate As Single = image.PhysicalDimension.Height \ page.Canvas.ClientSize.Height
			Dim fitRate As Single = Math.Max(widthFitRate, heightFitRate)
			Dim fitWidth As Single = image.PhysicalDimension.Width / fitRate
			Dim fitHeight As Single = image.PhysicalDimension.Height / fitRate

			page.Canvas.DrawImage(image, 0, 0, fitWidth, fitHeight)
			doc.SaveToFile("test.pdf")
			doc.Close()
		End Sub
	End Class
End Namespace      
          

 

Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more...

 

Download Spire.PDF for .NET

Purchase Spire.PDF for .NET

Spire.Doc, as a powerful .NET Word component, besides convert files from popular office format between Word doc/docx, it can also convert RTF to PDF. Totally programmatically converting RTF documents to PDF without Microsoft Office installed on your system! Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight.

 

Download Spire.Doc (or Spire.Office) with .NET framework together and use the C#/VB.NET code below to convert RTF to PDF.

 

Convert RTF to PDF with C# Code:

[C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
	 
namespace RTF2Pdf
	{
	    class Program
	    {
	        static void Main(string[] args)
	        {
	            Document doc = new Document();
	            doc.LoadFromFile("sample.rtf", FileFormat.RTF);
	            doc.SaveToFile("test.pdf", FileFormat.PDF);
	        }
	    }
	}
     

Convert RTF to PDF with VB.NET Code:

[Visual Basic]
	
Imports System.Text
Imports Spire.Doc
 
Namespace RTF2Pdf
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim doc As New Document()
            doc.LoadFromFile("sample.rtf", FileFormat.RTF)
            doc.SaveToFile("test.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

 

More about Spire.Doc

Download Spire.Doc

Purchase Spire.Doc

PDF is now recognized globally as the ideal electronic format for storing and sharing documents via the World Wide Web, email and CD-ROM. However, sometimes we need to split a PDF file to several parts. Months ago, one of our clients has a multi-page PDF file. He need it split by page. It seems necessary to do these jobs of extracting part of PDF content and producing new PDF files because we may come across some large PDF files but just need to share part of which to the receivers sometimes.

The methods of splitting PDF, one of the most popular file formats worldwide, are easy to get from internet. Different kinds of software, tools, programs and PDF components support splitting PDF document, no matter free or commercial. Commercial PDF components can give you support on technical which I recommend this method to all of you. And Spire.PDF for .NET could be one of your choices.

How to Use Spire.PDF for .NET Split PDF Documents

Download Spire.PDF for .NET (or Spire.Office) with .NET framework together.
Use the C#/VB.NET codes of Spire.PDF for .NET below to Split a large content PDF document:

[C#]
using System;
using Spire.Pdf;

namespace SplitDocument
{
    class Program
    {
        static void Main(string[] args)
        {
            //open pdf document
            PdfDocument doc = new PdfDocument(@"..\..\..\..\..\..\Data\Sample3.pdf");

            String pattern = "SplitDocument-{0}.pdf";
            doc.Split(pattern);

            String lastPageFileName
                = String.Format(pattern, doc.Pages.Count - 1);

            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start(lastPageFileName);
        }
               
    }
}   
          
[Visual Basic]
Imports Spire.Pdf

Namespace SplitDocument
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			'open pdf document
			Dim doc As New PdfDocument("..\..\..\..\..\..\Data\Sample3.pdf")

			Dim pattern As String = "SplitDocument-{0}.pdf"
			doc.Split(pattern)

			Dim lastPageFileName As String = String.Format(pattern, doc.Pages.Count - 1)

			doc.Close()

			'Launching the Pdf file.
			Process.Start(lastPageFileName)
		End Sub

	End Class
End Namespace         
          
more about Spire.PDF
download Spire.PDF
purchase spire.PDF
As a PDF document creation component, Spire.PDF can help users create PDF documents. Users can easily use C#/VB.NET to design text content at will. In addition, by using Spire.PDF, we can also insert image into the PDF document.

How to Create a PDF Document via Spire.PDF

Step 1 Prepare

Download Spire.PDF (Spire.Office) and install on system. Then, create a project in visual studio and add Spire.PDF DLL as reference.

Step 2 Create a PDF Document

The code below can help us create a PDF document and generate a PDF page.
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

Step 3 Write Text Content

Now, use the following code to design text content. We can also design the text font.
            page.Canvas.DrawString("Hello, World!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);

Step 4 Save and Preview

We can use the code below to save the designed PDF document and launch to preview.
            //Save pdf file.
            doc.SaveToFile("Sample.pdf");
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start("Sample.pdf");

How to Insert an Image into PDF Document via Spire.PDF

Step 1, 2, 3 are the same as above.

Step 4 Insert Image

Choose an image which we need insert into the PDF document and put it in the Project folder as the image shows below:
Following the code below to insert and design image. We can set the image width and height.
            //Draw the image
            PdfImage image = PdfImage.FromFile(@"..\..\Sample.jpg");
            float width = image.Width * 0.75f;
            float height = image.Height * 0.75f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

Step 5 Save and Preview

It’s the same as the Step 4 of “How to Create a PDF Document via Spire.PDF” above.

Effective Screenshot:


Full Demo Can be Found Here

Spire.PDF owns the ability of drawing text in PDF document. It supports text formatting, multilingual and text extraction. Here we will introduce how to draw text in PDF with different styles. Spire.PDF enables users to draw rotate text in PDF, draw transform text in PDF, draw alignment text in PDF, draw alignment text in rectangle and other style settings such as font, size, color, pen, etc.

Download Spire.PDF (Spire.Office) and install on system. Create project in visual studio, add Spire.PDF dll and system.drawing as reference. The following code can help us create a blank PDF document, PDF page and save the result PDF document. We can also find the solutions here.
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            RotateText(page);

            //Save doc file.
            doc.SaveToFile("DrawText.pdf");
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start("DrawText.pdf");
        }

Draw Transform Text in PDF

To draw transform text in PDF, we can set scale transform and skew transform. Furthermore, we can also design font and color. Sample Code:
        private static void TransformText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f);
            PdfSolidBrush brush1 = new PdfSolidBrush(Color.DeepSkyBlue);
            PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue);

            page.Canvas.TranslateTransform(20, 200);
            page.Canvas.ScaleTransform(1f, 0.6f);
            page.Canvas.SkewTransform(-10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush1, 0, 0);

            page.Canvas.SkewTransform(10, 0);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, 0);

            page.Canvas.ScaleTransform(1f, -1f);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush2, 0, -2 * 18);
            //restor graphics
            page.Canvas.Restore(state);
        }

Effective Screenshot:

Draw Alignment Text in PDF

Usually we have 3 types of alignment on PDF text, left alignment, right alignment and center alignment. Sample code:
        private static void AlignText(PdfPageBase page)
        {
            //Draw the text - alignment
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Left!", font, brush, 0, 20, leftAlignment);
            page.Canvas.DrawString("Left!", font, brush, 0, 50, leftAlignment);

            PdfStringFormat rightAlignment = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 30, rightAlignment);
            page.Canvas.DrawString("Right!", font, brush, page.Canvas.ClientSize.Width, 60, rightAlignment);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!",
                font, brush, page.Canvas.ClientSize.Width / 2, 40, centerAlignment);
        }
Effective Screenshot:

Draw alignment Text in a Rectangle

Draw alignment text in a rectangle means there has rectangles in PDF document and we will draw text in the rectangles and set alignment style. Sample Code:
        private static void AlignTextInRectangle(PdfPageBase page)
        {
            //Draw the text - align in rectangle
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);
            RectangleF rctg1 = new RectangleF(0, 70, page.Canvas.ClientSize.Width / 2, 100);
            RectangleF rctg2
                = new RectangleF(page.Canvas.ClientSize.Width / 2, 70, page.Canvas.ClientSize.Width / 2, 100);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightBlue), rctg1);
            page.Canvas.DrawRectangle(new PdfSolidBrush(Color.LightSkyBlue), rctg2);

            PdfStringFormat leftAlignment
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg1, leftAlignment);
            page.Canvas.DrawString("Left! Left!", font, brush, rctg2, leftAlignment);

            PdfStringFormat rightAlignment
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg1, rightAlignment);
            page.Canvas.DrawString("Right! Right!", font, brush, rctg2, rightAlignment);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Bottom);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg1, centerAlignment);
            page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, rctg2, centerAlignment);
        }
Effective Screenshot:

Draw Rotate Text in PDF

To draw rotate text in PDF, we should set the text as center alignment first. In addition, we can also set transform text here. Sample Code:
        private static void RotateText(PdfPageBase page)
        {
            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw the text - transform           
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Blue);

            PdfStringFormat centerAlignment
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            float x = page.Canvas.ClientSize.Width / 2;
            float y = 380;

            page.Canvas.TranslateTransform(x, y);
            for (int i = 0; i < 12; i++)
            {
                page.Canvas.RotateTransform(30);
                page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment);
            }

            //restor graphics
            page.Canvas.Restore(state);
        }
Effective Screenshot:


Spire.PDF also supports other text styles in PDF. Click here to learn more about Spire.PDF.

download Spire.PDF
purchase spire.PDF
<< Start < Prev 1 2 3 4 5 6 Next > End >>
Page 5 of 6