Dear All,
How to create a pdf from memorystream?.. I use codes below but it fails:
private void createPdf(byte[] b)
{
MemoryStream ms = new MemoryStream(b);
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(ms);
pdf1.Save(@“d:\verytemp\test.pdf”);
ms.Close();
}
Hi,
Thanks for contacting support.
Please note that Pdf class present under Aspose.Pdf.Generator namespace provides the feature to create PDF document from scratch and once the PDF file is created, you can save the output over system or save it in Stream object. Now concerning to your requirement on creating PDF file from MemoryStream, my understanding is that you want to create the PDF file and save it in MemoryStream object. If so is the case, please try using following code snippet.
[C#]
// create MemoryStream object
MemoryStream ms = new MemoryStream();
// create Pdf object
Pdf pdf = new Pdf();
// create Pdf section
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
// add sample text paragraph to section
sec1.Paragraphs.Add(new Text("Hello World..."));
// save the output in MemoryStream object
pdf.Save(ms);
// close MemoryStream
ms.Close();
In case you need to create PDF file in direct to file mode, you can pass Stream object as an argument to Pdf object but when following this approach, you need to call Close() method of Pdf class instead of Save(). Please take a look over following code snippet.
[C#]
// create MemoryStream object
MemoryStream ms = new MemoryStream();
// create Pdf object
Pdf pdf = new Pdf(ms);
// create Pdf section
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
// add sample text paragraph to section
sec1.Paragraphs.Add(new Text("Hello World..."));
// save the output in MemoryStream object
pdf.Close();
// close MemoryStream
ms.Close();
Hi,
I am using the same code above and the close method for PDF takes about 20 seconds before moving into the next line. Do you know how can I speed this steps? I have attached the document that the process is reproducing.
thank you
Alvaro
Hi Alvaro,