Click here to Skip to main content
14,929,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I have page with a div control , i want to generate pdf from that div control without using third party tool like ItextSharp or any other.

Thanks
Posted

1 solution

Hello,
I wrote a tutorial explaining how to convert a .doc in a pdf file. I didn't use third party, but Microsoft Office must be installed.

If you can generate a doc, or any sort of "office" file, it can be converted to pdf.

The code I used to convertion is:

C#
private void ConvertWord2PDF(string inputFile, string outputPath)
{
	try
	{
		if (outputPath.Equals("") || !File.Exists(inputFile))
		{
			throw new Exception("Either file does not exist or invalid output path");
		}

		// app to open the document belower
		Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
		Document wordDocument = new Document();

		// input variables
		object objInputFile = inputFile;
		object missParam = Type.Missing;                
		
		wordDocument = wordApp.Documents.Open(ref objInputFile, ref missParam, ref missParam, ref missParam,
			ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam,
			ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam);

		if (wordDocument != null)
		{
			// make the convertion
			wordDocument.ExportAsFixedFormat(outputPath, WdExportFormat.wdExportFormatPDF, false,
				WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportAllDocument,
				0, 0, WdExportItem.wdExportDocumentContent, true, true, 
				WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missParam);                                                    
		}

		// close document and quit application
		wordDocument.Close();
		wordApp.Quit();

		MessageBox.Show("File successfully converted");
		ClearTextBoxes();
	}
	catch (Exception e)
	{                
		throw e;
	}
}


But the entire tutorial can be found here
http://codeabout.wordpress.com/2012/03/20/convert-a-word-file-to-pdf-with-c/[^]

I don't know if this is exactly what you are looking for, but i hope it helps.
Regards,
Felipe
   
Comments
deepakdynamite 28-Apr-12 1:24am
   
Thanks for your help but this is a workaround for what i want to do. I directly want to convert context of div tag into PDF.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900