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 of a document describes a file in terms of its properties such as author, title, last author, company, language, and other similar information. This is useful information that is stored along with the document. Aspose.PUB for .NET lets you edit metadata of a PUB file using the DocSummaryInfo and SummaryInfo classes as shown in the following code sample.
1 string dataDir = RunExamples.GetDataDir_Data();
2
3 string pubFile = dataDir + "document.pub";
4
5 IPubParser parser = PubFactory.CreateParser(pubFile);
6 Document document = parser.Parse();
7
8 document.DocumentSummaryInfo.SetCategory("category");
9 document.DocumentSummaryInfo.SetCompany("company");
10 document.DocumentSummaryInfo.SetLanguage("language");
11
12 document.SummaryInfo.SetComments("comments");
13 document.SummaryInfo.SetKeywords("keywords");
14 document.SummaryInfo.SetLastAuthor("last author");
15 document.SummaryInfo.SetTitle("title");
16 document.SummaryInfo.SetSubject("subject");
Write output to stream
The code below defines a process of PUB to TIFF conversion and saving the result into a stream. Writing output to stream may save the output ensuring efficient handling of potentially large image files, proper resource management, and flexibility in choosing the output destination. Here’s an explanation of what the code does:
- Get the directory path where the input and output files are stored using the method RunExamples.GetDataDir_Data().
- Construct the full path of the input .pub file by appending the file name to the data directory path.
- Create a parser for the .pub file using PubFactory.CreateParser(fileName), then parse the file to obtain a Document object representing the .pub file’s contents.
- Open a file stream for writing the output
tiff
file. The ConvertToStream method is then called with the document, the desired export format (PubExportFormats.Tiff), and the open file stream. Similarly to ConvertToFile, this method converts the document to the specified format but writes the output to a stream instead of a file.
A similar way you can convert PUB to another format, using one of the supported PubExportFormats
1 // The path to the documents directory.
2 string dataDir = RunExamples.GetDataDir_Data();
3
4 string fileName = dataDir + "halloween-flyer.pub";
5
6 var parser = PubFactory.CreateParser(fileName);
7
8 var doc = parser.Parse();
9
10 //Convert to tiff using file stream and save resultant stream as "halloween-flyer_out.tiff"
11 using (FileStream st = File.OpenWrite(dataDir + "halloween-flyer_out.tiff"))
12 {
13 ConvertToStream(doc, PubExportFormats.Tiff, st);
14 }
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.