Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This article explains how to convert various other types of file formats to PDF using C#. It covers the following topics.
The following code snippet also work with Aspose.PDF.Drawing library.
Aspose.PDF for .NET allows you simply convert EPUB files to PDF format.
EPUB (short for electronic publication) is a free and open e-book standard from the International Digital Publishing Forum (IDPF). Files have the extension .epub. EPUB is designed for reflowable content, meaning that an EPUB reader can optimize text for a particular display device.
EPUB also supports fixed-layout content. The format is intended as a single format that publishers and conversion houses can use in-house, as well as for distribution and sale. It supersedes the Open eBook standard.The version EPUB 3 is also endorsed by the Book Industry Study Group (BISG), a leading book trade association for standardized best practices, research, information and events, for packaging of content.
Try to convert EPUB to PDF online
Aspose.PDF for .NET presents you online free application “EPUB to PDF”, where you may try to investigate the functionality and quality it works.
Next following code snippet show you how to convert EPUB files to PDF format with C#.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertEPUBtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.EpubLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "EPUBToPDF.epub", options))
{
// Save PDF document
document.Save(dataDir + "ConvertEPUBtoPDF_out.pdf");
}
}
You can also set page size for conversion. To define new page size you SizeF
object and pass it to EpubLoadOptions constructor.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertEPUBtoPDFAdv()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.EpubLoadOptions(new SizeF(1190, 1684));
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "EPUBToPDF.epub", options))
{
// Save PDF document
document.Save(dataDir + "ConvertEPUBtoPDFAdv_out.pdf");
}
}
This feature is supported by version 19.6 or greater.
Try to convert Markdown to PDF online
Aspose.PDF for .NET presents you online free application “Markdown to PDF”, where you may try to investigate the functionality and quality it works.
Aspose.PDF for .NET provides the functionality to create a PDF document based on input Markdown data file. In order to convert the Markdown to PDF, you need to initialize the Document using MdLoadOptions.
The following code snippet shows how to use this functionality with Aspose.PDF library:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertMarkdownToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.MdLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "sample.md", options))
{
// Save PDF document
document.Save(dataDir + "ConvertMarkdownToPDF_out.pdf");
}
}
PCL (Printer Command Language) is a Hewlett-Packard printer language developed to access standard printer features. PCL levels 1 through 5e/5c are command based languages using control sequences that are processed and interpreted in the order they are received. At a consumer level, PCL data streams are generated by a print driver. PCL output can also be easily generated by custom applications.
Try to convert PCL to PDF online
Aspose.PDF for for .NET presents you online free application “PCL to PDF”, where you may try to investigate the functionality and quality it works.
Currently only PCL5 and older versions are supported
Sets of Commands | Support | Exceptions | Description |
---|---|---|---|
Job control commands | + | Duplex printing mode | Control print process: number pf copies, output bin, simplex/duplex printing, left and top offsets etc. |
Page control commands | + | Perforation Skip command | Specify a size of page, margins, page orientation inter -lines, -character distances etc. |
Cursor Positioning Commands | + | Specify cursor position and, hence, origins of text, raster or vector images and details. | |
Font selection commands | + |
|
Allow loading soft (embedded) fonts from PCL file and managing them in memory. |
Raster graphics commands | + | Only black & white |
Allow loading raster images from PCL file to memory, specify raster parameters. such as width, height, compression type, resolution etc. |
Color commands | + | Allow coloring for all printable objects. | |
Print Model commands | + |
Allow filling text, raster images and rectangular areas with a raster predefined and user-defined patterns specify transparency mode for patterns and source raster image. Predefined patterns are hatching, cross-hatch and shading ones. |
|
Rectangle area fill commands | + | Allow creation and filling rectangular areas with patterns. | |
HP-GL/2 Vector Graphics commands | + | Screened Vector Command (SV), Transparency Mode Command (TR), Transparent Data Command (TD), RO (Rotate Coordinate System), Scalable or Bitmap Fonts Command (SB), Character Slant Command (SL) and Extra Space (ES) are not implemented and DV (Define Variable Text Path) commands are realized in beta version. |
Allow loading HP-GL/2 vector images from PCL file into memory. Vector image has an origin at lower
left corner of the printable area, can be scaled, translated, rotated and clipped. Vector image can contain text, as labels, and geometric figures such as rectangle, circle, ellipse, line, arc, bezier curve and complex figures composed from the simple ones. Closed figures including letters of labels can be filled with solid fill or vector pattern. Pattern can be hatching, cross-hatch, shading, raster used-defined, PCL hatching or cross-hatch and PCL user-defined. PCL patterns are raster. Labels can be individually rotated, scaled, and directed in four directions: up, down, left and right. Left and Right directions involve one-after-another letter arrangement. Up and Down directions involve one-under-another letter arrangement. |
Macroses | ― | Allow loading a sequence of PCL commands into memory and use this sequence many times, for example, to print page header or set one formatting for a set of pages. | |
Unicode text | ― |
Allow printing non ASCII characters. Not implemented due to lack of sample files with Unicode text |
|
PCL6 (PCL-XL) |
Realized only in Beta version because of lack in test files. Embedded fonts also are not
supported. JetReady extension is not supported because it is impossible to have JetReady specification. |
Binary file format. |
To allow conversion from PCL to PDF, Aspose.PDF has the class PclLoadOptions
which is used to initialize the LoadOptions object. Later on this object is passed as an argument during Document object initialization and it helps the PDF rendering engine to determine the input format of source document.
The following code snippet shows the process of converting a PCL file into PDF format.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPCLtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.PclLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ConvertPCLtoPDF.pcl", options))
{
// Save PDF document
document.Save(dataDir + "ConvertPCLtoPDF_out.pdf");
}
}
You can also monitor the detection of errors during the conversion process. To do this, you need to configure PclLoadOptions object: set or unset SupressErrors.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPCLtoPDFAdvanced()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.PclLoadOptions { SupressErrors = true };
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ConvertPCLtoPDFAdvanced.pcl", options))
{
if (options.Exceptions != null)
{
foreach (var ex in options.Exceptions)
{
Console.WriteLine(ex.Message);
}
}
// Save PDF document
document.Save(dataDir + "ConvertPCLtoPDFAdvanced_out.pdf");
}
}
Aspose.PDF for .NET support the feature converting plain text and pre-formatted text file to PDF format.
Converting text to PDF means adding text fragments to the PDF page. As for text files, we are dealing with 2 types of text: pre-formatting (for example, 25 lines with 80 characters per line) and non-formatted text (plain text). Depending on our needs, we can control this addition ourselves or entrust it to the library’s algorithms.
Try to convert TEXT to PDF online
Aspose.PDF for .NET presents you online free application “Text to PDF”, where you may try to investigate the functionality and quality it works.
In case of the plain text file, we can use the following technique:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPlainTextFileToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Read the source text file
using (var streamReader = new StreamReader(dataDir + "TextToPDFInput.txt"))
{
// // Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Create an instance of TextFragment and pass the text from reader object to its constructor as argument
var text = new Aspose.Pdf.Text.TextFragment(streamReader.ReadToEnd());
// Add a new text paragraph in paragraphs collection and pass the TextFragment object
page.Paragraphs.Add(text);
// Save PDF document
document.Save(dataDir + "TextToPDF_out.pdf");
}
}
}
Converting pre-formatted text is like plain text but you need to make some additional actions such as setting margins, font type and size. Obviously that font should be monospace (for example Courier New).
Follow these steps to convert pre-formatted text to PDF with C#:
Convert Pre-formatted TXT to PDF
In this case, the library’s algorithm also adds extra pages, but we can control this process ourselves. Following example shows how to convert pre-formatted text file to PDF document with page size A4.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPreFormattedTextToPdf()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Read the text file as array of string
var lines = File.ReadAllLines(dataDir + "ConvertPreFormattedTextToPdf.txt");
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Set left and right margins for better presentation
page.PageInfo.Margin.Left = 20;
page.PageInfo.Margin.Right = 10;
page.PageInfo.DefaultTextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Courier New");
page.PageInfo.DefaultTextState.FontSize = 12;
foreach (var line in lines)
{
// check if line contains "form feed" character
// see https://en.wikipedia.org/wiki/Page_break
if (line.StartsWith("\x0c"))
{
page = document.Pages.Add();
page.PageInfo.Margin.Left = 20;
page.PageInfo.Margin.Right = 10;
page.PageInfo.DefaultTextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Courier New");
page.PageInfo.DefaultTextState.FontSize = 12;
}
else
{
// Create an instance of TextFragment and pass the line to its constructor as argument
var text = new Aspose.Pdf.Text.TextFragment(line);
// Add a new text paragraph in paragraphs collection and pass the TextFragment object
page.Paragraphs.Add(text);
}
}
// Save PDF document
document.Save(dataDir + "PreFormattedTextToPDF_out.pdf");
}
}
Aspose.PDF for .NET support feature converting XPS files to PDF format. Check this article to resolve your tasks.
The XPS file type is primarily associated with the XML Paper Specification by Microsoft Corporation. The XML Paper Specification (XPS), formerly codenamed Metro and subsuming the Next Generation Print Path (NGPP) marketing concept, is Microsoft’s initiative to integrate document creation and viewing into its Windows operating system.
In order to convert XPS to PDF with Aspose.PDF for .NET, we have introduced a class named XpsLoadOption which is used to initialize a LoadOptions object. Later, this object is passed as an argument during the Document object initialization and it helps the PDF rendering engine to determine the source document’s input format.
The following code snippet shows the process of converting XPS file into PDF format with C#.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertXPSToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate Options object
var options = new Aspose.Pdf.XpsLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "XPSToPDF.xps", options))
{
// Save PDF document
document.Save(dataDir + "ConvertXPSToPDF_out.pdf");
}
}
Try to convert XPS format to PDF online
Aspose.PDF for .NET presents you online free application “XPS to PDF”, where you may try to investigate the functionality and quality it works.
Aspose.PDF for .NET support features converting PostScript files to PDF format. One of the features from Aspose.PDF is that you can set a set of font folders to be used during conversion.
In order to convert a PostScript file to PDF format, Aspose.PDF for .NET offers PsLoadOptions class which is used to initialize the LoadOptions object. Later this object can be passed as an argument to Document object constructor, which will help PDF Rendering Engine to determine the format of source document.
Following code snippet can be used to convert a PostScript file into PDF format with Aspose.PDF for .NET:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPostScriptToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new PsLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ConvertPostscriptInput.ps", options))
{
// Save PDF document
document.Save(dataDir + "PSToPDF_out.pdf");
}
}
Additionally, you can set a set of font folders that will be used during conversion:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPostscriptToPDFAdvanced()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options with custom font folders
var options = new Aspose.Pdf.PsLoadOptions
{
FontsFolders = new[] { dataDir + @"\fonts1", dataDir + @"\fonts2" }
};
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ConvertPostscriptInput.ps", options))
{
// Save PDF document
document.Save(dataDir + "ConvertPostscriptToPDFAdvanced_out.pdf");
}
}
The XML format used to store structured data. There are several ways to convert XML to PDF in Aspose.PDF:
Try to convert XML to PDF online
Aspose.PDF for .NET presents you online free application “XML to PDF”, where you may try to investigate the functionality and quality it works.
The conversion of XSL-FO files to PDF can be implemented using the traditional Aspose.PDF technique - instantiate Document object with XslFoLoadOptions. But sometimes you can meet with the incorrect file structure. For this case, XSL-FO converter allows setting the error handling strategy. You can choose ThrowExceptionImmediately
, TryIgnore
or InvokeCustomHandler
.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void Convert_XSLFO_to_PDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.XslFoLoadOptions(dataDir + "XSLFOToPdfInput.xslt");
// Set error handling strategy
options.ParsingErrorsHandlingType = Aspose.Pdf.XslFoLoadOptions.ParsingErrorsHandlingTypes.ThrowExceptionImmediately;
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "XSLFOToPdfInput.xml", options))
{
// Save PDF document
document.Save(dataDir + "XSLFOToPdf_out.pdf");
}
}
The LaTeX file format is a text file format with markup in the LaTeX derivative of the TeX family of languages and LaTeX is a derived format of the TeX system. LaTeX (ˈleɪtɛk/lay-tek or lah-tek) is a document preparation system and document markup language. It is widely used for the communication and publication of scientific documents in many fields, including mathematics, physics, and computer science. It also has a prominent role in the preparation and publication of books and articles that contain complex multilingual materials, such as Sanskrit and Arabic, including critical editions. LaTeX uses the TeX typesetting program for formatting its output, and is itself written in the TeX macro language.
Try to convert LaTeX/TeX to PDF online
Aspose.PDF for .NET presents you online free application “LaTex to PDF”, where you may try to investigate the functionality and quality it works.
Aspose.PDF for .NET supports the feature to convert TeX files to PDF format and in order to accomplish this requirement, Aspose.Pdf namespace has a class named LatexLoadOptions which provides the capabilities to load LaTex files and render the output in PDF format using Document class. The following code snippet shows the process of converting LaTex file to PDF format with C#.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertTeXtoPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.TeXLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "samplefile.tex", options))
{
// Save PDF document
document.Save(dataDir + "TeXToPDF_out.pdf");
}
}
OFD format refers to “Open Fixed-layout Document,” established as China’s national standard for electronic file storage, used as an alternative to the popular PDF format. It supports fixed-layout documents, ensuring consistent display across different platforms. OFD files are utilized for various purposes, including digital documents and business applications.
Aspose.PDF for .NET supports the feature to convert OFD files to PDF format and in order to accomplish this requirement, Aspose.Pdf namespace has a class named OfdLoadOptions which provides the capabilities to load OFD files and render the output in PDF format using Document class.
The following code snippet shows the process of converting OFD file to PDF format with C#.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertOFDToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Convert options
var options = new Aspose.Pdf.OfdLoadOptions();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ConvertOFDToPDF.ofd", options))
{
// Save PDF document
document.Save(dataDir + "ConvertOFDToPDF_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.