IXpsFixedPageWriter.Commit 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
清除並關閉固定頁面寫入器。
public:
void Commit();
public void Commit ();
abstract member Commit : unit -> unit
Public Sub Commit ()
範例
下列範例示範如何使用 方法排清和關閉固定頁面寫入器 Commit 。
// ------------------------- AddDocumentContent ---------------------------
/// <summary>
/// Adds a predefined set of content to a given document writer.</summary>
/// <param name="fixedDocumentWriter">
/// The document writer to add the content to.</param>
void AddDocumentContent (IXpsFixedDocumentWriter^ fixedDocumentWriter)
{
// Collection of image and font resources used on the current page.
// Key: "XpsImage", "XpsFont"
// Value: List of XpsImage or XpsFont resources
Dictionary<System::String^,List<XpsResource^>^>^ resources;
try
{
// Add Page 1 to current document.
IXpsFixedPageWriter^ fixedPageWriter = fixedDocumentWriter->AddFixedPage();
// Add the resources for Page 1 and get the resource collection.
resources = AddPageResources(fixedPageWriter);
// Write page content for Page 1.
WritePageContent(fixedPageWriter->XmlWriter, "Page 1 of " + fixedDocumentWriter->Uri->ToString(), resources);
// Commit Page 1.
fixedPageWriter->Commit();
// Add Page 2 to current document.
fixedPageWriter = fixedDocumentWriter->AddFixedPage();
// Add the resources for Page 2 and get the resource collection.
resources = AddPageResources(fixedPageWriter);
// Write page content to Page 2.
WritePageContent(fixedPageWriter->XmlWriter, "Page 2 of " + fixedDocumentWriter->Uri->ToString(), resources);
// Commit Page 2.
fixedPageWriter->Commit();
} catch (XpsPackagingException^ xpsException)
{
throw xpsException;
}
};// end:AddDocumentContent()
// ------------------------- AddDocumentContent ---------------------------
/// <summary>
/// Adds a predefined set of content to a given document writer.</summary>
/// <param name="fixedDocumentWriter">
/// The document writer to add the content to.</param>
private void AddDocumentContent(IXpsFixedDocumentWriter fixedDocumentWriter)
{
// Collection of image and font resources used on the current page.
// Key: "XpsImage", "XpsFont"
// Value: List of XpsImage or XpsFont resources
Dictionary<string, List<XpsResource>> resources;
try
{
// Add Page 1 to current document.
IXpsFixedPageWriter fixedPageWriter =
fixedDocumentWriter.AddFixedPage();
// Add the resources for Page 1 and get the resource collection.
resources = AddPageResources(fixedPageWriter);
// Write page content for Page 1.
WritePageContent(fixedPageWriter.XmlWriter,
"Page 1 of " + fixedDocumentWriter.Uri.ToString(), resources);
// Commit Page 1.
fixedPageWriter.Commit();
// Add Page 2 to current document.
fixedPageWriter = fixedDocumentWriter.AddFixedPage();
// Add the resources for Page 2 and get the resource collection.
resources = AddPageResources(fixedPageWriter);
// Write page content to Page 2.
WritePageContent(fixedPageWriter.XmlWriter,
"Page 2 of " + fixedDocumentWriter.Uri.ToString(), resources);
// Commit Page 2.
fixedPageWriter.Commit();
}
catch (XpsPackagingException xpsException)
{
throw xpsException;
}
}// end:AddDocumentContent()
' ------------------------- AddDocumentContent ---------------------------
''' <summary>
''' Adds a predefined set of content to a given document writer.</summary>
''' <param name="fixedDocumentWriter">
''' The document writer to add the content to.</param>
Private Sub AddDocumentContent(ByVal fixedDocumentWriter As IXpsFixedDocumentWriter)
' Collection of image and font resources used on the current page.
' Key: "XpsImage", "XpsFont"
' Value: List of XpsImage or XpsFont resources
Dim resources As Dictionary(Of String, List(Of XpsResource))
Try
' Add Page 1 to current document.
Dim fixedPageWriter As IXpsFixedPageWriter = fixedDocumentWriter.AddFixedPage()
' Add the resources for Page 1 and get the resource collection.
resources = AddPageResources(fixedPageWriter)
' Write page content for Page 1.
WritePageContent(fixedPageWriter.XmlWriter, "Page 1 of " & fixedDocumentWriter.Uri.ToString(), resources)
' Commit Page 1.
fixedPageWriter.Commit()
' Add Page 2 to current document.
fixedPageWriter = fixedDocumentWriter.AddFixedPage()
' Add the resources for Page 2 and get the resource collection.
resources = AddPageResources(fixedPageWriter)
' Write page content to Page 2.
WritePageContent(fixedPageWriter.XmlWriter, "Page 2 of " & fixedDocumentWriter.Uri.ToString(), resources)
' Commit Page 2.
fixedPageWriter.Commit()
Catch xpsException As XpsPackagingException
Throw xpsException
End Try
End Sub
備註
根據 和 的設定 XpsSerializationManager ,例如 FontSubsetterCommitPolicies 和 XpsPackagingPolicy PackageInterleavingOrder ,方法的 Commit 排清作業可能會延遲到完成 XpsDocument 關閉為止。