423,680 Members | 2,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,680 IT Pros & Developers. It's quick & easy.

C# : Web : - How to Convert .doc,rtf,.xls files to pdf

P: 29
Hi all,

can u pls tell me how to convert
.doc,rtf,.xls files to pdf in C# .Net


thx
Feb 14 '08 #1
Share this Question
Share on Google+
6 Replies


P: 2
Friend please to try this codeing

Expand|Select|Wrap|Line Numbers
  1. ==============================
  2.  
  3. mports BCL.easyPDF.Interop.EasyPDFPrinter
  4. Imports System.Windows.Forms
  5.  
  6. Public Class Form1
  7.     Private oPrinter As Printer = Nothing
  8.     Private oPrintJob As PrintJob = Nothing
  9.     Private oPDFSetting As PDFSetting = Nothing
  10.     Private oWatermarkText As String = Nothing
  11.     Private oWatermarkBool As Boolean
  12.  
  13.     ' #################################################################################
  14.     ' Sub CheckBox1_CheckedChanged
  15.     ' Description: Check if users enables or disables the watermark option from the UI.
  16.     ' #################################################################################
  17.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  18.         If (CheckBox1.Enabled = True) Then
  19.             oWatermarkBool = True
  20.         Else
  21.             oWatermarkBool = False
  22.         End If
  23.     End Sub
  24.  
  25.     ' #################################################################################
  26.     ' Function ConvertToPDF, return String
  27.     ' Description: Return the watermark text.           
  28.     ' #################################################################################
  29.     Public Function GetWatermarkText() As String
  30.         Return oWatermarkText
  31.     End Function
  32.  
  33.  
  34.     ' #################################################################################
  35.     ' Sub ConvertToPDF
  36.     ' Description: Initialize the printer driver name and check the watermark condition
  37.     '              and print to pdf file.              
  38.     ' #################################################################################
  39.     Private Sub ConvertToPDF(ByVal inFile As String, ByVal outFile As String)
  40.         Try
  41.             ' This is how our printer driver gets initialized
  42.             oPrinter = CreateObject("easyPDF.Printer.5")
  43.             oPrintJob = oPrinter.PrintJob
  44.  
  45.             ' Use PDFSetting because we want to use Watermark feature
  46.             oPDFSetting = oPrintJob.PDFSetting
  47.  
  48.             ' Check the watermark properties if the users has entered the text or not
  49.             ' oWatermarkBool is a global variable for enable/disable watermark
  50.             ' GetWatermarkText will return a value of oWatermarkText
  51.             If (oWatermarkBool And (oWatermarkText <> Nothing)) Then
  52.                 oPDFSetting.Watermark(0) = oWatermarkBool
  53.                 oPDFSetting.WatermarkText(0) = GetWatermarkText()
  54.             End If
  55.  
  56.             ' Printing to pdf from whatever inFile format is
  57.             oPrintJob.PrintOut(inFile, outFile)
  58.  
  59.             MessageBox.Show("Success!!!")
  60.  
  61.             ' All the conversion errors will get caught here and the message box
  62.             ' will pop up notifying users for the errors.
  63.         Catch ex As System.Runtime.InteropServices.COMException
  64.             MessageBox.Show(ex.Message)
  65.             If (ex.ErrorCode = prnResult.PRN_R_CONVERSION_FAILED And Not oPrintJob Is Nothing) Then
  66.                 MessageBox.Show(oPrintJob.ConversionResultMessage)
  67.             End If
  68.         End Try
  69.  
  70.         ' Clean up the object from the memory
  71.         oPrinter = Nothing
  72.  
  73.     End Sub
  74.  
  75.  
  76.     ' #################################################################################
  77.     ' Sub Button1_Click 
  78.     ' Description: open the "Open File Dialog" and "Save File Dialog"
  79.     '              asking users to choose the input file and the target file name, 
  80.     '              this case is pdf.
  81.     ' #################################################################################
  82.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  83.         Dim openFile As OpenFileDialog
  84.         Dim savePDFFile As SaveFileDialog
  85.         Dim inFileName As String
  86.         Dim outFileName As String
  87.         Dim pos As Integer
  88.  
  89.         ' "Open File Dialog" instantiation
  90.         openFile = New System.Windows.Forms.OpenFileDialog
  91.         openFile.Filter = "All Files (*.*)|*.*"
  92.         openFile.Title = "Select a File"
  93.         If (openFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
  94.             Return
  95.         End If
  96.         inFileName = openFile.FileName
  97.  
  98.         outFileName = inFileName
  99.         pos = inFileName.LastIndexOf(".")
  100.         If (pos > 0) Then
  101.             outFileName = outFileName.Substring(0, pos)
  102.         End If
  103.         outFileName += ".pdf"
  104.  
  105.         ' "Save File Dialog" instantiation
  106.         savePDFFile = New System.Windows.Forms.SaveFileDialog
  107.         savePDFFile.FileName = outFileName
  108.         savePDFFile.Filter = "pdf files (*.pdf)|*.pdf"
  109.         savePDFFile.Title = "Save PDF File"
  110.         If (savePDFFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
  111.             Return
  112.         End If
  113.         outFileName = savePDFFile.FileName
  114.  
  115.         ' Once we know the input file and the output file, we pass these information to
  116.         ' the ConvertToPDF function for printing to pdf file.
  117.         ConvertToPDF(inFileName, outFileName)
  118.     End Sub
  119.  
  120.     ' #################################################################################
  121.     ' Sub TextBox1_TextChanged
  122.     ' Description: Assign the string text of the watermark to oWatermarkText variable.
  123.     ' #################################################################################
  124.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  125.         oWatermarkText = TextBox1.Text
  126.     End Sub
  127.  
  128. End Class
  129. =======================================
Feb 14 '08 #2

P: 29
Thanks Prabakaran...

let me try this in C# as i need to impliment this in C#

this line of code
imports BCL.easyPDF.Interop.EasyPDFPrinter

i would need this dll right ?

thanks again vl try and get back to u
Feb 15 '08 #3

P: 29
No it didnt work ..couldnt get the dll
Feb 26 '08 #4

P: 12
vel
hi did you get the solution for this convertion problem.
Jun 30 '08 #5

Curtis Rutland
Expert 2.5K+
P: 3,256
No it didnt work ..couldnt get the dll
Looks like you need a 3rd party DLL to use his solution.

Actually...there is no native PDF functionality, so you will need a third-party dll regardless. I suggest either searching for the one he used (start here, i found this from a quick google search) and if you can't find it, move on to Sourceforge. They have plenty of .NET PDF solutions.
Jun 30 '08 #6

P: 23
Seems to be a great converter?
2 Weeks Ago #7

Post your reply

Sign in to post your reply or Sign up for a free account.