在 PS 文件中使用页面 | Python

Contents
[ Hide Show ]

向 PS 文档添加页面

Aspose.Page for Python via .NET 提供了两种向 PsDocument 对象添加页面的方法。

以下代码片段演示了如何通过 8 个步骤创建 2 页 PS 文档:

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项实例化 PsSaveOptions 对象。
  3. 使用之前创建的输出流和保存选项创建 2 页 PsDocument。
  4. 使用文档的默认页面尺寸(纵向 A4 尺寸)打开第一页。
  5. 关闭页面。
  6. 使用新的尺寸打开第二页。
  7. 关闭页面。 8.保存文档。
 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_pages()
 3
 4# Create an output stream for the PostScript document
 5with open(data_dir + "document1.ps", "wb") as out_ps_stream:
 6    # Create save options with A4 size
 7    options = PsSaveOptions()
 8    
 9    # Create a new 2-paged PS Document
10    document = PsDocument(out_ps_stream, options, 2)
11    
12    # Add the first page
13    document.open_page(None)
14    
15    # Add content
16    
17    # Close the first page
18    document.close_page()
19    
20    # Add the second page with a different size
21    document.open_page(400, 700)
22    
23    # Add content
24    
25    # Close the second page
26    document.close_page()
27    
28    # Save the document
29    document.save()

请参阅在 .NETJava 中处理 PS 文档中的页面。

以下代码片段同样可以创建一个两页的 PS 文档,但需要执行 7 个步骤:

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项启动 PsSaveOptions 对象。
  3. 使用已创建的输出流和保存选项创建一个多页的 PsDocument。在本例中,第一页已经打开,其大小为文档的默认页面大小(纵向 A4 尺寸)。
  4. 关闭页面。
  5. 打开第二页,并设置新的尺寸。
  6. 关闭页面。
  7. 保存文档。 当文档只有 1 页或不确定是 1 页还是 2 页时,这种添加页面的方式非常有用。
 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_pages()
 3
 4# Create an output stream for PostScript document
 5with open(data_dir + "document2.ps", "wb") as out_ps_stream:
 6    # Create save options with A4 size
 7    options = PsSaveOptions()
 8    
 9    # Set a variable that indicates if resulting PostScript document will be multipaged
10    multi_paged = True
11    
12    # Create new multipaged PS Document with one page opened
13    document = PsDocument(out_ps_stream, options, multi_paged)
14    
15    # Add content
16    
17    # Close the first page
18    document.close_page()
19    
20    # Add the second page with different size
21    document.open_page(500, 300)
22    
23    # Add content
24    
25    # Close the second page
26    document.close_page()
27    
28    # Save the document
29    document.save()

您可以从 GitHub下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.