如何从 PS 个文件创建 PDF,同时减少页面并将 4 个变成一个页面(向上 4 个)?

How to create a PDF from PS files while reducing the pages and having 4 to a page (4 up)?

打印路径为:

  1. Excel 或 VB.net PrintDocument >
  2. 后记 >
  3. 使用 GhostScript 将多个 PS 文件转换为单个 PDF >
  4. 使用 iTextPDF 添加图章 >
  5. 使用 duplex/staple 等的自定义 PJL 命令从 PDF 为特定打印机创建 PCL 文件 >
  6. 使用 LPR 将 PCL 文件发送到打印机

在第 3 步中,是否可以从 PS 文件创建 PDF(使用 GhostScript),同时减少页面并将 4 个变成一页(向上 4 个)?还是 2 个到一页(2 个向上)?

4 up 表示 4 页缩小以适合一张 sheet 纸:

    'This uses a list of PS files to create one PDF
    Private Shared Sub ConvertToPDF(ByVal PSPathFileList As List(Of String), _
                             ByVal PDFPathName As String, _
                             ByVal WaitForExit As Boolean, ByVal DeletePS As Boolean)

        'check that all files exist
        PSPathFileList.ForEach(AddressOf CheckFiles)

        'check old pdf file
        If IO.File.Exists(PDFPathName) Then
            Throw New ApplicationException( _
                "PDF cannot be created. File already exists: " & PDFPathName)
        End If

        'convert engine
        Dim myProcInfo As New ProcessStartInfo
        myProcInfo.FileName = DanBSolutionsLocation & "Misc\GhostScript\GSWIN32C.EXE"
        Debug.Print(myProcInfo.FileName)

        'write file names to text file as the list can be very long
        Dim tempPath As String = IO.Path.GetDirectoryName(PSPathFileList.Item(0))
        Dim fiName2 As String = tempPath & IO.Path.GetFileNameWithoutExtension(PDFPathName) & ".txt"

        Dim ft As New StreamWriter(fiName2)
        ft.WriteLine("-sDEVICE=pdfwrite -q -dSAFER -dNOPAUSE -sOUTPUTFILE=""" & PDFPathName & """ -dBATCH ")
        For i As Long = 0 To PSPathFileList.Count - 1
            ft.WriteLine(Chr(34) & PSPathFileList.Item(i) & Chr(34))
        Next
        ft.Close()

        'set args to text file
        myProcInfo.Arguments = """@" & fiName2 & """"

        'set up for output and errors
        myProcInfo.UseShellExecute = False
        myProcInfo.RedirectStandardOutput = True
        myProcInfo.RedirectStandardError = True
        Debug.Print(myProcInfo.Arguments)

        'do the conversion
        Dim myProc As Process = Process.Start(myProcInfo)

        Debug.Print(myProc.StandardOutput.ReadToEnd)
        Debug.Print(myProc.StandardError.ReadToEnd)

        If WaitForExit Then
            'wait for finish; (no more than 60 seconds)
            myProc.WaitForExit(60000)

            'delete PS
            If DeletePS Then
                PSPathFileList.ForEach(AddressOf DeleteFiles)
            End If
        End If

    End Sub

是的,它可以获取 'N' 页的 PostScript 文件并生成 'M' 页的单个 PDF 文件,其中每个页面有 N/M 个原始页面,缩小和偏移量。

这叫做拼版,有商业工具可以做到这一点,或者你可以使用psnup。

或者您可以自己编写 PostScript 来执行此操作(毕竟 PostScript 是一种编程语言)。可能最简单的方法是自定义 BeginPage 例程。

此例程应检查页面数,并使用它来确定将虚拟页面绘制到哪个象限。这意味着更改 CTM 以缩放内容并翻译来源。虽然缩放比例保持不变,但平移因每个虚拟页面而异,以便将其移动到不同的象限。哦,你还需要一个自定义的 EndPage,这样只有每 4 页被发送到输出。

一个更复杂的实现也会覆盖 setpagedevice 以便为每个媒体请求单独设置缩放,以防页面不在同一媒体上。

或者您可以将所有内容提炼成一个 PDF 文件,然后使用我编写的程序 以 PDF 格式完成这项工作。

当然,您的多次转换,PS->PDF->PCL 很可能会导致妥协,因为每种页面描述语言的功能不同。希望页面的内容比较简单......