We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Docx to PDF- is any problem with this code- why not generating PDF properly

when i am trying to generate PDF from my Docx getting error , file damged , but i can generate RTF and other document, what is worng with rhis code

FileStream fs = new FileStream(@"C:\\TEST_Project_Status.docx", FileMode.Open , FileAccess.Read);

Byte[] mydata = new Byte[fs.Length]; // This is what is commited to the db.

fs.Read(mydata, 0, (int)fs.Length);

fs.Close();

//Reading the data from the db into a stream.

MemoryStream decompressedMemoryStream = new MemoryStream();

decompressedMemoryStream.Write(mydata, 0, mydata.Length);

LoadFormat inputFormat = Document.DetectFileFormat(decompressedMemoryStream);

string extension = string.Empty;

SaveFormat outputFormat = SaveFormat.Pdf ;

string outputfile = @"c:\TEST_Project_Status.Pdf";// +"." + textBox1.Text;

using (FileStream fsw = new FileStream(outputfile , FileMode.OpenOrCreate, FileAccess.Write))

{

//fsw.Write(letter.FileContent, 0, letter.FileContent.Length);

fsw.Write(mydata, 0, mydata.Length);

}

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please attach your document here for testing? I will check the problem on my side and provide you more information.

Best regards,

Please find docu and code

Project.docx

Thanks for your inquiry. Could you please attach your document here for testing? I will check the problem on my side and provide you more information.

//Code

private void button1_Click(object sender, EventArgs e)

{

//Example

FileStream fs = new FileStream(@"C:\\Project.docx", FileMode.Open, FileAccess.Read);

Byte[] mydata = new Byte[fs.Length]; // This is what is commited to the db.

fs.Read(mydata, 0, (int)fs.Length);

fs.Close();

//Reading the data from the db into a stream.

MemoryStream decompressedMemoryStream = new MemoryStream();

decompressedMemoryStream.Write(mydata, 0, mydata.Length);

LoadFormat inputFormat = Aspose.Words.Document.DetectFileFormat(decompressedMemoryStream);

string extension = string.Empty;

SaveFormat outputFormat = SaveFormat.Doc ;

string outputfile = @"c:\Project_output" +"." + textBox1.Text;

using (FileStream fsw = new FileStream(outputfile , FileMode.OpenOrCreate, FileAccess.Write))

{

//fsw.Write(letter.FileContent, 0, letter.FileContent.Length);

fsw.Write(mydata, 0, mydata.Length);

}

decompressedMemoryStream.Close();

}

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. But I do not see your document here. Could you please attach your document one more time?

Best regards,

I am expecting u have my code already

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. If you take a look at your code you will see that you just write from one stream to another. I suppose there is no sense in such operation. If I understand you correctly, you need to convert DOC file to PDF. In this case, your code should look like the following:

// Open source document.

Document doc = new Document("in.doc");

// Save document in PDF format.

doc.SaveToPdf("out.pdf");

Or like the following, if you would like to open document from stream and save PDF document into another stream:

using ( FileStream fs = File.OpenRead(@"C:\Project.docx"))

{

// Open docuemnt from stream

Document doc = new Document(fs);

// Save docuemnt as PDF into another stream.

MemoryStream pdfStream = new MemoryStream();

doc.SaveToPdf(0, doc.PageCount, pdfStream, null);

}

Please see the documentation for more information.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/loading-saving-and-converting.html

Best regards,