API to manipulate Publisher files in C#
Aspose.PUB for .NET lets you work with PUB files in your .NET applications. It supports manipulating .pub files with a simple and well-defined structure.
Edit MetaData of PUB Files
Metadata of .pub files accessible by Aspose.PUB
Microsoft Publisher (.pub) files have metadata information about the file itself. There is examples of information that you can get using this API Solution:
| Metadata | Description |
|---|---|
| Application Name | The name of the application that was used to create the document |
| Title | The title of the publication. |
| Author | The name of the person or entity who created the publication. |
| Version | Version value |
| Subject | A brief description or topic associated with the publication. |
| Keywords | Relevant keywords or tags to describe the content of the publication. |
| Comments | Additional notes related to the publication. |
| Creation Date | The date when the publication was originally created. |
| Modification Date | The date when the publication was last edited. |
| Last Author | The name of the person who last made changes to the document. |
| Template | Application-specific template from which the document was created. |
| Character Count | Provides the total number of characters in the document. |
| Word Count | Provides the total number of words in the document. |
| Page Count | Provides the total number of pages in the document. |
Functionality to work with metadata of .pub files provided by Aspose.PUB for .NET
Metadata describes document properties such as title, company, language, and related information. The following example parses halloween-flyer.pub and updates eight properties through the
DocSummaryInfo and
SummaryInfo classes. These changes affect the parsed Document in memory; the example does not save a modified PUB file.
In these examples, DataDir is the input directory and OutputDir is the output directory. Set them to your own directories and ensure the output directory exists before running the stream example. Import the Aspose.Pub and System.IO namespaces when using the snippets in your application.
1// Edit the metadata of a parsed PUB document in memory
2
3// Parse the input Publisher document.
4string fileName = Path.Combine(DataDir, "halloween-flyer.pub");
5IPubParser parser = PubFactory.CreateParser(fileName);
6Document document = parser.Parse();
7
8// Update document metadata. These changes do not save a PUB file.
9document.DocumentSummaryInfo.SetCategory("category");
10document.DocumentSummaryInfo.SetCompany("company");
11document.DocumentSummaryInfo.SetLanguage("language");
12
13document.SummaryInfo.SetComments("comments");
14document.SummaryInfo.SetKeywords("keywords");
15document.SummaryInfo.SetLastAuthor("last author");
16document.SummaryInfo.SetTitle("title");
17document.SummaryInfo.SetSubject("subject");Write output to stream
The following example converts a PUB document to TIFF and writes the result to a file stream. The using block closes the stream after conversion. Here is how the example works:
- Construct the input path with
Path.Combine(DataDir, "halloween-flyer.pub"). - Create an
IPubParserusing PubFactory.CreateParser(fileName), then callparser.Parse()to obtain aDocumentobject. - Construct
outPathwithPath.Combine(OutputDir, "halloween-flyer_out.tiff")and open the output stream withFile.Create(outPath). This creates the file or truncates an existing file. - Call
PubFactory.CreatePubConverter()to create a converter, then callConvertToFormat(doc, outputStream, PubExportFormats.Tiff)to write TIFF data to the stream. The stream is disposed when theusingblock ends.
A similar way you can convert PUB to another format, using one of the supported PubExportFormats
1// Convert a PUB document to TIFF using an output stream
2
3// Parse the input Publisher document.
4string fileName = Path.Combine(DataDir, "halloween-flyer.pub");
5IPubParser parser = PubFactory.CreateParser(fileName);
6Document doc = parser.Parse();
7
8// Write TIFF output to a file stream and close it after conversion.
9string outPath = Path.Combine(OutputDir, "halloween-flyer_out.tiff");
10using (FileStream outputStream = File.Create(outPath))
11{
12 PubFactory.CreatePubConverter().ConvertToFormat(doc, outputStream, PubExportFormats.Tiff);
13}To learn all the .NET code examples and data files, please go to Aspose.PUB-Documentation for C# Github project.
Also take a look at the functionality provided by Aspose.PUB implemented into a set of cross-platform applications to manipulate .pub files.