Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How to convert the data in the file stream to pdf with out any plugin using c# code and
download.

What I have tried:

byte[] fileContents = Docx();
         using (FileStream file = new FileStream(wordPath, FileMode.Create))
         {
             file.Write(fileContents, 0, fileContents.Length);
             file.Close();
         }


i want to convert the data in fileContents to pdf
Posted
Updated 10-Feb-17 23:38pm
v3
Comments
ZurdoDev 30-Jan-17 7:04am    
C# does not natively support converting to pdf so you'll need to use a 3rd party tool.

You can't - or at least not in a reasonable time frame.
DOCX is a Zipped XML based document format, PDF is nothing like it.
You can't just take a "raw" DOCX as a stream of bytes and say "this is a PDF" - you have to process the DOCX file into a document and reinterpret that document as a PDF file.

Use a plug in, or an API - it really isn't a good idea to try and do it yourself, there is just too much involved as neither document format is trivial to understand and process.
 
Share this answer
 
Comments
Member 11471318 30-Jan-17 7:13am    
then how to solve this using wkhtmltopdf
OriginalGriff 30-Jan-17 7:20am    
Read their documentation.
But ... you do realize that HTML also isn't DOCX?
Member 11471318 30-Jan-17 7:24am    
i have data on buffer need to convert and download it as pdf. i tried using oword but failed
OriginalGriff 30-Jan-17 7:30am    
So what format is it in to start with? How do you know that?
It is possible, but you will need 3rd party library. In that case your code could look like this:

C#
byte[] fileContents = Docx();
using (FileStream file = new FileStream(wordPath, FileMode.Create))
{
	file.Write(fileContents, 0, fileContents.Length);
	file.Close();
}

// dummy object for constructor, since you will not merge outside data
object myDataObject = new object();

DocumentGenerator dg = new DocumentGenerator(myDataObject); 
MemoryStream outputDocumentStream = new MemoryStream(); 
dg.GenerateDocument(file, outputDocumentStream, Pdf); 

See more examples if you think this could be helpful for you.
 
Share this answer
 
Comments
Member 11471318 21-Feb-17 1:55am    
Hi
which is the best Api used to convert and download bufferdata or docx file as pdf
please help.

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