平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“C#代码实现方法将PDF转换为PostScript(PS)格式”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际采用顺序,把思路、关键写法和容易踩坑的地方讲清楚,便于大家直接对照操作。
实际处理时,PostScript 是由 Adobe Systems 在 20 世纪 80 年代开发的一种页面描述语言,用来将数字图形或文本文件转换为适合打印的固定格式。随着时间的推移,虽然 PostScript(PS)文件格式已不如过去那样流行,但目前仍然受到大多数打印机的兼容。
结合项目来看,下面会介绍如何采用 Spire.PDF for .NET 以编程方式将 PDF 文件转换为 PostScript(PS)文件。
安装 Spire.PDF for .NET
理解这一步时,首先,你需在 .NET 项目中引用 Spire.PDF for .NET 包中包含的 DLL 文件。你能够借助提供的链接下载这些 DLL 文件,或者借助 NuGet 进行安装。
PM> Install-Package Spire.PDF
在 C# 和 VB.NET 中将 PDF 转换为 PostScript
在这个场景下,将 PDF 转换为 PS 格式能够提升打印输出的质量。采用 Spire.PDF for .NET,你只需三行代码即可完成转换。具体步骤如下所示:
- 新建一个 PdfDocument 实例。
- 采用 PdfDocument.LoadFromFile() 方法加载示例 PDF 文件。
- 采用 PdfDocument.SaveToFile(string filename, FileFormat.POSTSCRIPT) 方法将 PDF 文件保存为 PS 文件。
示例如下所示:
using Spire.Pdf;
namespace PDFtoPS
{
class Program
{
static void Main(string[] args)
{
// 创建 PdfDocument 实例
PdfDocument document = new PdfDocument();
// 加载示例 PDF 文件
document.LoadFromFile("Test.pdf");
// 将 PDF 文件保存为 PS 文件
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT);
}
}
}
知识扩展
1.C# VB.NET将 PDF 转换为 PostScript
在这个场景下,将 PDF 转换为 PS 能够提高打印输出的质量。采用 Spire.PDF for .NET,您只需三行代码即可完成转换。以下是详细步骤。
- 新建一个PdfDocument实例。
- 实际处理时,采用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
- 从实现思路看,采用PdfDocument .SaveToFile(string filename, FileFormat.POSTSCRIPT)方法将 PDF 文件保存为 PS 文件。
C#
using Spire.Pdf;
namespace PDFtoPS
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument document = new PdfDocument();
//Load a sample PDF file
document.LoadFromFile("Test.pdf");
//Save the PDF file as a PS file
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT);
}
}
}
VB.NET
Imports Spire.PDF
Namespace PDFtoPS
Class Program
Private Shared Sub Main(ByVal args() As String)
'Create a PdfDocument instance
Dim document As PdfDocument = New PdfDocument
'Load a sample PDF file
document.LoadFromFile("Test.pdf")
'Save the PDF file as a PS file
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT)
End Sub
End Class
End Namespace
2.pdf转PostScript
pdftops version 4.03 [www.xpdfreader.com]
Copyright 1996-2021 Glyph & Cog, LLC
Usage: pdftops [options] <PDF-file> [<PS-file>]
-f <int> : first page to print
-l <int> : last page to print
-level1 : generate Level 1 PostScript
-level1sep : generate Level 1 separable PostScript
-level2 : generate Level 2 PostScript
-level2gray : generate Level 2 grayscale PostScript
-level2sep : generate Level 2 separable PostScript
-level3 : generate Level 3 PostScript
-level3gray : generate Level 3 grayscale PostScript
-level3sep : generate Level 3 separable PostScript
-eps : generate Encapsulated PostScript (EPS)
-form : generate a PostScript form
-opi : generate OPI comments
-noembt1 : don't embed Type 1 fonts
-noembtt : don't embed TrueType fonts
-noembcidps : don't embed CID PostScript fonts
-noembcidtt : don't embed CID TrueType fonts
-preload : preload images and forms
-paper <string> : paper size (letter, legal, A4, A3, match)
-paperw <int> : paper width, in points
-paperh <int> : paper height, in points
-nocrop : don't crop pages to CropBox
-expand : expand pages smaller than the paper size
-noshrink : don't shrink pages larger than the paper size
-nocenter : don't center pages smaller than the paper size
-pagecrop : treat the CropBox as the page size
-userunit : honor the UserUnit
-duplex : enable duplex printing
-opw <string> : owner password (for encrypted files)
-upw <string> : user password (for encrypted files)
-q : don't print any messages or errors
-cfg <string> : configuration file to use in place of .xpdfrc
-v : print copyright and version info
-h : print usage information
-help : print usage information
--help : print usage information
-? : print usage information
到此这篇关于C#代码实现将PDF转换为PostScript(PS)格式的文章就介绍到这了,更多相关C# PDF转PostScript内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多兼容脚本之家!
- 在C#中将Word转换为PostScript的代码实现
- C#采用Spire.PDF for .NET实现将PDF转换为PCL格式
- 采用C#和Spire.PDF库实现PDF与OFD格式互转的具体教程
- C#实现OFD格式与PDF格式的互转
- C#将PDF转为多种图像文件格式的方法(Png/Bmp/Emf/Tiff)
- C#实现WPS文件转PDF格式的方法示例