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

Free Support Forum - aspose.com

Need to convert Aspose Word data to Aspose PDF byte of data without saving files on disk

Hi All

I need a convert a Aspose Word document to Aspose PDf document, but I am not suppose to save any file to disk at any point of time.

Steps followed:

1. Array of bytes[] info will be there is database. This bytes of data will be in Aspose Word format.

2. Now using this byte info I created a Aspose word document using memory stream as below

using ( MemoryStream meomoryStreamstream = new MemoryStream(data,true))

{

Document wordDocument = new Document(meomoryStreamstream);

Stream xmlStream = File.Create("text.xml");

wordDocument.Save(xmlStream, SaveFormat.AsposePdf);

Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();

pdfDocument.BindXML(xmlStream, null);

pdfDocument.IsImagesInXmlDeleteNeeded = true;

pdfDocument.Save(@"C:\Users\rchikkarangaiah\Desktop\pdf.pdf");

MemoryStream stream = new MemoryStream();

pdfDocument.Save(stream);

data = stream.GetBuffer();

}

But hete I am using "text.xml" file to strore the data from the aspose word document to Aspose pdf.

Since I shouldnt save any files to disk, what is alternative here.

pdfDocument.Save(stream);

data = stream.GetBuffer();

the 'data' which if of pdf form will be stored in data and will be shown to the user in the pdf file..

Thanks in advance

Ranganatha

Hello Ranganatha,

Please use the following code snippet to accomplish your requirement.

[C#]

using (MemoryStream meomoryStreamstream = new MemoryStream(data, true))
{
Document doc = new Document(meomoryStreamstream);
MemoryStream ms = new MemoryStream();

doc.Save(ms, Aspose.Words.SaveFormat.AsposePdf);
ms.Seek(0, SeekOrigin.Begin);

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(ms);

Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();
pdfDocument.BindXML(xmldoc, null);

pdfDocument.Save(@"c:\pdftest\Document_wihtmemoryStream.pdf");
// If you dont want to save the pdf file over hard drive,
//please use the following line of code to display the Pdf file in user browser
//pdfDocument.Save("My Document.pdf", Aspose.Pdf.SaveType, Response);

MemoryStream stream = new MemoryStream();
pdfDocument.Save(stream);
data = stream.GetBuffer();
}

Another scenario:

How do you convert Aspose Word data to Aspose byte of data without saving files on disk ?

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

Thanks for considering Aspose.

The answer to this question is, we use Memory stream to hold the intermediate XML file that is generated, and once the BindXML method is called, you can finally send the resultant file to user browser or save to Stream object and save the contents of Stream to Byte array. Please notice the following lines of code where XML file is saved to MemoryStream.

[C#]

MemoryStream ms = new MemoryStream();
doc.Save(ms, Aspose.Words.SaveFormat.AsposePdf);

Please correct me if I have not properly understood your question. I would more appreciate, if you could elaborate your requirement.