Close





 
Thursday, 16 June 2011 06:31

Create PDF Converter

Spire PDF Converter (Free/Pro) is created and designed by Spire.Office. With Spire.Offce, you can create a professional PDF Converter by yourself. Spire.Office includes Spire.Doc, Spire.XLS and Spire.PDF which can easily help you convert files from XLS/Xlsx to PDF, Doc/Docx to PDF, HTML to PDF, Text to PDF, XML to PDF, and Image to PDF. And Spire.PDF can help you encrypt the output PDF files and enable you add text/image watermark. Spire.Office for .NET is a compilation of every .NET component offered by e-iceblue. Using Spire.Office for .NET developers can create a wide range of applications. And this article will simply show you how to create a professional PDF Converter.

Install Spire.Office and follow the 4 steps below:

1, Set Main Functions:

  • Convert files from Word Doc to PDF
  • Convert files from Excel to PDF
  • Convert files from HTML to PDF
  • Convert files from Text to PDF
  • Convert files from Image (all formats) to PDF
  • Encrypt output PDF files by setting password and permissions
  • Add text/image watermark
  • Batch conversion
  • Other friendly features

2, Programming

PDFConverter classes relationship:

All converter classes inherit from abstract class, BaseConverter. And achieve IConvertable interface. There are 2 methods in BaseConverter: Encryption and Watermark

public void Encryption(PdfDocument pdfDocument)
        {
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (!string.IsNullOrEmpty(c.AppSettings.Settings["UserPassword"].Value))
            {
                pdfDocument.Security.UserPassword = c.AppSettings.Settings["UserPassword"].Value;
            }
            if (!string.IsNullOrEmpty(c.AppSettings.Settings["OwnPassword"].Value))
            {
                pdfDocument.Security.OwnerPassword = c.AppSettings.Settings["OwnPassword"].Value;
            }
            int Permissions;
            if (!string.IsNullOrEmpty(c.AppSettings.Settings["Permissions"].Value))
            {
                int.TryParse(c.AppSettings.Settings["Permissions"].Value, out Permissions);
                pdfDocument.Security.Permissions = (pdfSecurity.PdfPermissionsFlags)Permissions;
            }
        }

public void WaterMark(PdfPageCollection pages)
        {
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (!string.IsNullOrEmpty(c.AppSettings.Settings["TextWatermark"].Value))
            {
                foreach (PdfPageBase page in pages)
                {
                    TextWaterMark(page);
                }
            }
            if (!string.IsNullOrEmpty(c.AppSettings.Settings["ImageWatermark"].Value))
            {
                foreach (PdfPageBase page in pages)
                {
                    ImageWaterMark(page);
                }
            }
        }

          

Use ConverterFactory static method getConverter when need to get relevant Converter object.

          public static IConvertable GetConverter(string fileFullName)
        {
            FileInfo fi = new FileInfo(fileFullName);
            if (!File.Exists(fileFullName))
            {
                throw new Exception(fi.Name + " is not existed!");
            }
            switch (Path.GetExtension(fileFullName).ToLower())
            {
                case ".doc":
                case ".docx":
                case ".rtf":
                    return new WordConverter();
                case ".htm":
                case ".html":
                    return new HTMLConverter();
                case ".xls":
                case ".xlsx":
                    return new ExcelConverter();
                case ".txt":
                    return new TextConverter();
                case ".jpg":
                case ".png":
                case ".bmp":
                case ".gif":
                case ".tiff":
                    return new ImageConverter();
                default:
                    throw new Exception(fi.Name + " can not convert to pdf!");
            }
        }

          

Main Converter convert methods

          public class ExcelConverter : BaseConverter, IConvertable
    {
        #region IConvertable 

        public void Convert(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new Exception(string.Format("{0} does not exist!", fileFullName));
            }
            Spire.Xls.Converter.PdfConverter pdfConverter = new Spire.Xls.Converter.PdfConverter(fileFullName);

            PdfDocument pdfDocument = new PdfDocument();
           
            pdfDocument.PageSettings.Orientation = pdf.PdfPageOrientation.Landscape;
            pdfDocument.PageSettings.Width = 970;
            pdfDocument.PageSettings.Height = 850;

            PdfConverterSettings settings = new PdfConverterSettings();
            settings.EmbedFonts = true;
            settings.TemplateDocument = pdfDocument;
            pdfDocument = pdfConverter.Convert(settings);
            //WaterMark(pdfDocument);
#if !FreeEdition
            WaterMark(pdfDocument.Pages);
            Encryption(pdfDocument);
#endif
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string savePath = Path.Combine(c.AppSettings.Settings["OutputFile"].Value, Path.GetFileName(fileFullName) + ".pdf");
            pdfDocument.SaveToFile(savePath);
            pdfDocument.Close();
        }

        #endregion
}


public class WordConverter : BaseConverter, IConvertable
    {
        #region IConvertable 

        public void Convert(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new Exception(string.Format("{0} does not exist!", fileFullName));
            }
            Document document = new Document();
            document.LoadFromFile(fileFullName);
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string savePath = Path.Combine(c.AppSettings.Settings["OutputFile"].Value, Path.GetFileName(fileFullName) + ".pdf");
            using (MemoryStream stream = new MemoryStream())
            {
                document.SaveToStream(stream, FileFormat.PDF);
                document.Close();
                PdfDocument pdfdoc = new PdfDocument(stream);
                //WaterMark(pdfdoc);
#if !FreeEdition
                WaterMark(pdfdoc.Pages);
                Encryption(pdfdoc);
#endif

                pdfdoc.SaveToFile(savePath);
                pdfdoc.Close();
            }
        }

        #endregion
    }


public class HTMLConverter : BaseConverter, IConvertable
    {
        #region IConvertable 

        public void Convert(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new Exception(string.Format("{0} does not exist!", fileFullName));
            }
            PdfDocument pdfdoc = new PdfDocument();
            //pdfdoc.Sections.Add().LoadFromHTML(fileFullName, true, true, new Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat() { FitToPage = Spire.Pdf.HtmlConverter.Clip.Width, Layout = pdfGraphics.PdfLayoutType.Paginate });
            pdfdoc.LoadFromHTML(fileFullName, true, true, true);
            //pdfdoc.LoadFromFile(url);
            FileInfo fi = new FileInfo(fileFullName);
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string savePath = Path.Combine(c.AppSettings.Settings["OutputFile"].Value, Path.GetFileName(fileFullName) + ".pdf");
            //WaterMark(pdfdoc);
#if !FreeEdition
            WaterMark(pdfdoc.Pages);
            Encryption(pdfdoc);
#endif
            pdfdoc.SaveToFile(savePath);
            pdfdoc.Close();
        }

        #endregion
    }


public class ImageConverter : BaseConverter, IConvertable
    {
      #region IConvertable 

        public void Convert(string fileFullName)
        {
            if (!File.Exists(fileFullName))
            {
                throw new Exception(string.Format("{0} does not exist!", fileFullName));
            }
            PdfDocument doc = new PdfDocument();
            PdfSection section = doc.Sections.Add();
           
            PdfPageBase page = doc.Pages.Add();
            PdfImage image = PdfImage.FromFile(fileFullName);

            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);
            Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string savePath = Path.Combine(c.AppSettings.Settings["OutputFile"].Value, Path.GetFileName(fileFullName) + ".pdf");
            //WaterMark(doc);
#if !FreeEdition
            WaterMark(doc.Pages);
            Encryption(doc);
#endif
            doc.SaveToFile(savePath);
            doc.Close();
        } 
        #endregion
    }

          

Note: Spire.Doc and Spire.Pdf both have a namespace Spire.Pdf.Graphics. When use this namespace, use alias.

 

3, Design Product Interface

When you finish programming, you need make your PDF Converter with a good appearance. If you are good at PS, your product should be very attractive.

4, Test and fix bugs

At last, test the PDF converter. Make sure it’s working well and with high performance.

 

Only 4 steps! Download Spire.Office and Create Your Own PDF Converter Now.

Published in PDFConverter
Thursday, 16 June 2011 02:36

Get PDF Converter Free

Help us Promote PDF Converter (Free/Pro) to Get PDF Converter Pro Free

 

You can easily via:

  • Useful Blog article
  • Helpful Forum Post (Forum List below)
  • Positive Software Review
  • YouTube
  • Others

Requirement: at least 1 link to e-iceblue

Forum List:

  • http://slickdeals.net/forums/
  • http://fatwallet.com
  • http://www.hotukdeals.com
  • http://forums.majorgeeks.com/
  • http://forums.techbargains.com/
  • http://www.redflagdeals.com
  • http://deals.woot.com/
  • http://www.dealextreme.com/forums
  • http://pressf1.pcworld.co.nz/
  • http://www.techsupportalert.com/freeware-forum/
  • http://forum.planetpdf.com/
  • http://user.services.openoffice.org/en/forum/
  • http://www.oooforum.org/forum
  • http://ubuntuforums.org/
  • http://forums.serif.com/
  • http://forums.opensuse.org/
  • http://www.techimo.com/
  • http://forums.mydigitallife.info/
  • http://www.softwaretipsandtricks.com/forum/
  • http://forum.egypt.com/enforum/
  • http://www.sevenforums.com/
  • http://www.v7n.com/forums/
  • http://forums.techguy.org/
  • http://forums.digitalpoint.com/
  • http://forums.computershopper.com/
  • http://www.daniweb.com/forums/
  • http://www.vistaheads.com/forums/


If you have other recommend forums, please do not hesitate to let us know. You may also get PDF Converter Pro Free via it.

 

Tell us once you promoted our PDF Converter via sending email to comments@e-iceblue.com and we will send you register code within 1 business day.

Published in Purchase
Monday, 30 May 2011 06:49

How to Convert Image to PDF

Spire PDF Converter is a powerful PDF converting tool which enables to convert files from Doc to PDF, HTML to PDF, Image to PDF, Excel to PDF and Text to PDF. This article will show you how to use Spire PDF Converter to convert file from Image to PDF.

How to Convert Image to PDF?

Free Download Spire PDF Converter
Only a few simple steps, you can finish a whole process of Image to PDF conversion by using Spire PDF Converter.

Step 1, Install and Run Spire PDF Converter

Step 2, Choose Image files

Click “Add Files” button to select Image files which you want to convert to PDF format.

Step 3, Choose output file folder

Click “browse” button to select file folder where you want to place the output PDF files. Spire PDF Converter supports encrypt out PDF files and enables add watermark (Text/Image watermark).

Step 4, Run Image to PDF conversion

Click “Convert” button to start converting process.
Free Download Spire PDF Converter Right Now!

Related Articles

Published in PDFConverter
Friday, 27 May 2011 05:42

How to Add PDF Watermark

Spire PDF Converter allows users to add watermark after converting to PDF. The following steps will guide you how to add PDF watermark by using Spire PDF Converter.

 

Step 1, Download Spire PDF Converter Install and Run

 

Step 2, Add Files

Click add file and choose the document which you want to convert and add watermark.

 

Step 3, Add PDF Watermark

Click Add Watermark and then a window pops up. If select Text Watermark, enter text. If select Image Watermark, click “Browse” to choose images. Then click “Watermark”

 

 

Step 4, Convert to PDF

Click “Convert”. And the document will be converted to PDF with watermark added.

 

Free Download Spire PDF Converter to Convert files to PDF format and Add PDF Watermark NOW!

 

Related Articles:

How to Use Spire PDF Converter

How to Convert Doc to PDF

How to Convert HTML to PDF

How to Convert Text to PDF

How to Use Spire PDF Converter Encrypt PDF Documents

Published in PDFConverter