Write output to stream
Easily save the result of a PUB file conversion into stream via C# .NET API
Microsoft® Publisher document file format is designed for creating various types of publications, including newsletters, brochures, flyers, and postcards, and is commonly used in emails and on websites. Publisher files can contain both text and graphical elements, including bitmap and vector graphics.
Aspose.PUB for .NET has functionality to save the output file to streams which is useful in several scenarios:
- When you handle large files streams allow for processing data incrementally without needing to load the entire data set into memory.
- Streams can facilitate real-time data processing, where data can be processed as it is being read or written, enabling more responsive applications.
- When transmitting data over a network, streams allow for efficient data transfer in operations like file uploads or downloads.
- Using streams, particularly with constructs like using in C#, ensures that resources are properly managed and released.
- Streams can be part of a pipeline, where data flows through multiple processing stages. Each stage reads from an input stream and writes to an output stream, promoting modular and maintainable code.
- Streams support parallel processing, where different parts of the data can be processed simultaneously, improving performance for certain types of tasks.
Convert PUB to TIFF and save the result into a stream
- The provided code uses a stream to save the output of .pub file conversion. It includes the following steps:
- Retrieve the path to the documents directory.
- Construct the full path to a specific Publisher file using the PubFactory Class.
- Creates and use a parser to parse the Publisher file into a document object using the Parse() Method of IPubParser Interface.
- Process the conversion using ConvertToStream() Method. It takes the document, the desired export format (TIFF in this case), and the file stream as parameters and writes the converted image to the stream.
Get Started with .NET PUB API
- Install from command line as
nuget install Aspose.PUB
or via Package Manager Console of Visual Studio withInstall-Package Aspose.PUB
. - Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .
.NET Code to Convert PUB to TIFF and save the result into a strem
using Aspose.Pub;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Construct the path to the documents directory.
string dataDir = RunExamples.GetDataDir_Data();
string fileName = dataDir + "halloween-flyer.pub";
var parser = PubFactory.CreateParser(fileName);
var doc = parser.Parse();
//Convert to tiff using the file stream and save the resultant stream as "halloween-flyer_out.tiff"
using (FileStream st = File.OpenWrite(dataDir + "halloween-flyer_out.tiff"))
{
ConvertToStream(doc, PubExportFormats.Tiff, st);
}
Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.PUB for .NET?
- Customers List
- Success Stories