Conversion

Conversion (22)

Thursday, 07 March 2019 06:32

Convert PDF to PostScript in C#, VB.NET

Written by support iceblue

A PostScript (.PS) file is an image saved in the PostScript page description language. The PostScript file format is widely used by publishers primarily for printing purposes. This article will show you how we can easily convert PDF to PostScript by using Sprie.PDF with C# and VB.NET.

Below is the screenshot of the input PDF file.

Convert PDF to PostScript in C#, VB.NET

Full Code

[C#]
//create a PdfDocument instance
PdfDocument document = new PdfDocument();

//load a sample PDF file
document.LoadFromFile(@"C:\Users\Administrator\Desktop\Introduction.pdf");

//save as .ps file
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT);
[VB.NET]
'create a PdfDocument instance
Dim document As PdfDocument =  New PdfDocument() 
 
'load a sample PDF file
document.LoadFromFile("C:\Users\Administrator\Desktop\Introduction.pdf")
 
'save as .ps file
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT)

Output

Convert PDF to PostScript in C#, VB.NET

Wednesday, 06 March 2019 07:45

Convert PDF to PCL in C#, VB.NET

Written by support iceblue

A PCL file is a Printer Command Language document. Printer Command Language is a page description language developed by HP as a printer protocol and has been widely supported in many printers now. Start from version 5.2.3, Spire.PDF supports converting PDF file to PCL format. There are six major levels of PCL, the PCL here refers to PCL 6 (PCL 6 Enhanced or PCL XL).

Example code

[C#]
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load the PDF file
pdf.LoadFromFile("Input.pdf");
//Save to PCL format
pdf.SaveToFile("ToPCL.pcl", FileFormat.PCL);
[VB.NET]
Private Sub SurroundingSub()
    Dim pdf As PdfDocument = New PdfDocument()
    pdf.LoadFromFile("Input.pdf")
    pdf.SaveToFile("ToPCL.pcl", FileFormat.PCL)
End Sub

This article we will demonstrate how to convert the PDF pages to HTML, Word, SVG, XPS, PDF and save them to stream by calling the method PdfDocument.SaveToStream() offered by Spire.PDF. And starts from Spire.PDF version 4.3, it newly supports to convert the defined range of PDF pages and save them to stream.

Save the PDF to stream

Step 1: Create a new PdfDocument instance and load the sample document from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

Step 2: Save the document to stream.

MemoryStream ms=new MemoryStream ();
pdf.SaveToStream(ms);

Save the PDF to stream and defined the file format to HTML, Word, SVG, XPS and PDF

Step 1: Create a new PdfDocument instance and load the sample document from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

Step 2: Save the document to stream and use FileFormat format to define the format.

MemoryStream ms=new MemoryStream ();
pdf.SaveToStream(ms, FileFormat.HTML);

Convert the defined range of PDF pages to HTML, word, SVG, XPS and save them to stream

Step 1: Create a new PdfDocument instance and load the sample document from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf"); 

Step 2: Only save some PDF pages to stream by using pdf.SaveToStream(int startIndex, int endIndex, FileFormat format) method; and FileFormat.PDF is not supported.

pdf.SaveToStream(1, 2, FileFormat.SVG);

Full codes of save PDF to stream:

PdfDocument pdf = new PdfDocument();

pdf.LoadFromFile("Sample.pdf");
            
MemoryStream ms=new MemoryStream ();
pdf.SaveToStream(ms);
pdf.SaveToStream(ms, FileFormat.HTML);

pdf.SaveToStream(1, 2, FileFormat.SVG);

We've have demonstrated how to convert PDF page to SVG file format in the previous post. This guidance shows you how we can specify the width and height of output file using the latest version of Spire.PDF with C# and VB.NET.

Step 1: Load a sample PDF document to PdfDocument instance.

PdfDocument document = new PdfDocument();
document.LoadFromFile("pdf-sample.pdf");

Step 2: Specify the output file size through ConvertOptions.SetPdfToSvgOptions() method.

document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f);

Step 3: Save PDF to SVG file format.

document.SaveToFile("result.svg", FileFormat.SVG);

Output:

Convert PDF to SVG with Custom Width and Height in C#, VB.NET

Full Code:

[C#]
PdfDocument document = new PdfDocument();
document.LoadFromFile("pdf-sample.pdf");
document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f);
document.SaveToFile("result.svg", FileFormat.SVG);
[VB.NET]
Dim document As New PdfDocument()
document.LoadFromFile("pdf-sample.pdf")
document.ConvertOptions.SetPdfToSvgOptions(800F, 1200F)
document.SaveToFile("result.svg", FileFormat.SVG)
Wednesday, 23 August 2017 06:30

C# Convert PDF to HTML

Written by support iceblue

From Spire.PDF for .NET 3.9.285, it is possible to convert PDF files to HTML in C# and VB.NET. The output format for saving images and texts is SVG when converting PDF to HTML. This article will demonstrate how to use Spire.PDF to save PDF file as HTML format.

The sample PDF file includes image, text and hyperlink.

C# Convert PDF to HTML

We can realize our requirement of converting PDF to HTML in several lines of code. Here are the steps:

Step 1: Create a PDF document and load sample PDF.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Test.pdf");

Step 2: Use SaveToFile method and set conversion target parameter as FileFormat.HTML.

pdf.SaveToFile("Result.html", FileFormat.HTML);

Here are the screenshot:

C# Convert PDF to HTML

Full codes:

[C#]
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Test.pdf");

pdf.SaveToFile("Result.html", FileFormat.HTML);
[VB.NET]
Dim pdf As New PdfDocument()
pdf.LoadFromFile("Test.pdf")
pdf.SaveToFile("Result.html", FileFormat.HTML)
Friday, 09 June 2017 06:41

Convert PDF Page to SVG in C#, VB.NET

Written by support iceblue

Spire.PDF allows us to convert a PDF document, a single page or a range of pages in a PDF document to SVG file format. We have introduced how to convert a PDF document to SVG, in this tutorial, we are going to demonstrate how to convert a PDF page to SVG.

Below is the source PDF file we used in this example:

Convert PDF Page to SVG in C#, VB.NET

Code snippets:

Step 1: Instantiate an object of PdfDocument class and load the PDF document.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Test.pdf");

Step 2: Convert the first page of the PDF document to SVG using the SaveToFile(string filename, int startIndex, int endIndex, FileFormat fileFormat) method.

doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);

The resultant SVG file looks as follows:

Convert PDF Page to SVG in C#, VB.NET

Full code:

[C#]
using Spire.Pdf;

namespace PDF_Page_to_SVG
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("Test.pdf");
            doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace PDF_Page_to_SVG
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("Test.pdf")
			doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG)
		End Sub
	End Class
End Namespace

We have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.

Here comes to the code snippets:

Step 1: Create a PDF instance.

PdfDocument pdf = new PdfDocument();

Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.

pdf.UseHighQualityImage = true;

Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().

pdf.LoadFromFile("Sample.xps",FileFormat.XPS);

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot of the high quality image after saving XPS as PDF file format:

How to keep high quality image when convert XPS to PDF in C#

Full codes:

{
    PdfDocument pdf = new PdfDocument();

    pdf.UseHighQualityImage = true;

    pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
    //pdf.LoadFromXPS("Sample.xps");

    pdf.SaveToFile("result.pdf", FileFormat.PDF);

}

About SVG (Scalable Vector Graphics)

SVG (Scalable Vector Graphics) is an image file format for two-dimensional, XML based vector images developed by the World Wide Web Consortium (W3C). Comparing with other image file formats, SVG has many advantages such as supporting interactivity and animation, allowing users to search, index, script, and compress/enlarge images without losing quality and it can be created and edited with any text editor.

Convert PDF to SVG (Scalable Vector Graphics) using Spire.PDF

Very often, developers need to convert files like PDF to SVG file format. The following part shows how to accomplish this requirement using a powerful .NET PDF component - Spire.PDF. Below is the screenshot of the source PDF file:

Convert PDF to SVG (Scalable Vector Graphics) in C#, VB.NET

Detail steps:

Step 1: Create a C#/Vb.net project in visual studio, then add a reference to Spire.Pdf.dll and use the following namespace.

using Spire.Pdf;

Step 2: Instantiate an object of PdfDocument class and load the source PDF file.

PdfDocument document = new PdfDocument();
document.LoadFromFile("Test.pdf");

Step 3: Call SaveToFile(string filename, FileFormat fileFormat) method to save PDF file to SVG file format.

document.SaveToFile(@"E:\Program Files\Result.svg", FileFormat.SVG);

After running the code, we'll get the following result SVG file:

Convert PDF to SVG (Scalable Vector Graphics) in C#, VB.NET

Full code:

[C#]
using Spire.Pdf;

namespace Convert_PDF_to_SVG
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument();
            document.LoadFromFile("Test.pdf");

            document.SaveToFile(@"E:\Program Files\Result.svg", FileFormat.SVG);
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace Convert_PDF_to_SVG
	Class Program
		Private Shared Sub Main(args As String())
			Dim document As New PdfDocument()
			document.LoadFromFile("Test.pdf")

			document.SaveToFile("E:\Program Files\Result.svg", FileFormat.SVG)
		End Sub
	End Class
End Namespace
Tuesday, 12 July 2016 07:45

Covert PDF to EMF image file format in C#

Written by support iceblue

Spire.PDF supports to save the PDF files into different image file formats, such as BMP, JPG, PNG, GIF and TIFF. It also supports to save the PDF files as the Enhanced Metafile (EMF) image file format. This article will demonstrate how to save the PDF file as the EMF image file format in C#. With the help of Spire.PDF, we only need three lines of codes to finish the conversion function.

Note: Before Start, please download the latest version of Spire.PDF and add Spire.Pdf.dll in the bin folder as the reference of Visual Studio.

Here comes to the steps of how to export the PDF file to EMF in C#:

Step 1: Create a new PDF document and load from file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

Step 2: Call to use the SaveAsImage method to save all the PDF pages as System.Drawing.Imaging.ImageFormat.Emf file format.

for (int i = 0; i < doc.Pages.Count; i++)
{
    String fileName = String.Format("Sample-img-{0}.emf", i);
    using (Image image = doc.SaveAsImage(i, Spire.Pdf.Graphics.PdfImageType.Metafile, 300, 300))
    {
        image.Save(fileName, System.Drawing.Imaging.ImageFormat.Emf);
    }
}

Effective screenshot:

Covert PDF to EMF image file format in C#

Full codes:

static void Main(string[] args)
 {
     PdfDocument doc = new PdfDocument();
     doc.LoadFromFile("sample.pdf");

     for (int i = 0; i < doc.Pages.Count; i++)
     {
         String fileName = String.Format("Sample-img-{0}.emf", i);
         using (Image image = doc.SaveAsImage(i, Spire.Pdf.Graphics.PdfImageType.Metafile, 300, 300))
         {
             image.Save(fileName, System.Drawing.Imaging.ImageFormat.Emf);
         }
     }
 }
Thursday, 23 July 2015 01:01

How to Convert PDF to PDF/A in C#, VB.NET

Written by support iceblue

PDF/A standard is based on Adobe PDF version 1.4, which ensures that the PDF document will look the same when it is accessed or processed in years to come. The standard specifies two levels of compliance for PDF files: PDF/A-1a and PDF/A-1b. What Spire.PDF support is to convert most of your PDF documents to become compliant with the PDF/A-1b. In the following section, let’s see detailed steps of how to convert PDF to PDF/A-1b compliant PDF suing Spire.PDF in C#, VB.NET.

Detailed Steps:

Step 1: Initialize a new instance of PdfDocument class and load the sample file.

PdfDocument OriginalDoc = new PdfDocument();
OriginalDoc.LoadFromFile("sample.pdf");

Step 2: Create a new object of PdfNewDocument class, set the PDF conformance level as PDF/A-1b.

PdfNewDocument newDOC = new PdfNewDocument();
newDOC.Conformance = PdfConformanceLevel.Pdf_A1B;

Step 3: Clone page sizes and contents from the original document to the new PDF document.

foreach (PdfPageBase page in OriginalDoc.Pages)
{
    SizeF size = page.Size;
    PdfPageBase p = newDOC.Pages.Add(size, new Spire.Pdf.Graphics.PdfMargins(0));
    page.CreateTemplate().Draw(p, 0, 0);
}

Step 4: Save the file and launch to view the effect.

newDOC.Save("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

Result:

How to Convert PDF to PDF/A in C#, VB.NET

Full Code:

[C#]
PdfDocument OriginalDoc = new PdfDocument();
OriginalDoc.LoadFromFile("sample.pdf");

PdfNewDocument newDOC = new PdfNewDocument();
newDOC.Conformance = PdfConformanceLevel.Pdf_A1B;
foreach (PdfPageBase page in OriginalDoc.Pages)
{
    SizeF size = page.Size;
    PdfPageBase p = newDOC.Pages.Add(size, new Spire.Pdf.Graphics.PdfMargins(0));
    page.CreateTemplate().Draw(p, 0, 0);
}

newDOC.Save("result.pdf");
System.Diagnostics.Process.Start("result.pdf");
[VB.NET]
Dim OriginalDoc As New PdfDocument()
OriginalDoc.LoadFromFile("sample.pdf")

Dim newDOC As New PdfNewDocument()
newDOC.Conformance = PdfConformanceLevel.Pdf_A1B
For Each page As PdfPageBase In OriginalDoc.Pages
	Dim size As SizeF = page.Size
	Dim p As PdfPageBase = newDOC.Pages.Add(size, New Spire.Pdf.Graphics.PdfMargins(0))
	page.CreateTemplate().Draw(p, 0, 0)
Next

newDOC.Save("result.pdf")
System.Diagnostics.Process.Start("result.pdf")
Page 1 of 2