Creare un file XPS OM vuoto
In questo argomento viene descritto come creare un file XPS OM vuoto. Presenta gli esempi di codice che illustrano come usare un file XPS OM per compilare la struttura del documento di un documento XPS con una pagina vuota.
Per essere salvato come documento XPS, XPS OM richiede almeno i componenti seguenti:
- Un IXpsOMPackage che descrive il pacchetto di documento XPS
- Un IXpsOMDocumentSequence che contiene la struttura dei contenuti del pacchetto.
- Un IXpsOMDocument che contiene il framework di un documento all'interno del pacchetto
- Un IXpsOMPageReference che contiene l'insieme di pagine nel documento
- Un IXpsOMPage che contiene una pagina vuota
Quando si utilizzano queste interfacce, XPS OM conterrà un documento con una pagina vuota. Per creare questo documento in un file XPS OM, il programma deve prima creare i singoli componenti e quindi collegarli.
Prima di usare gli esempi di codice seguenti, leggere la dichiarazione di non responsabilità in Common XPS Document Programming Tasks.
Esempi di codice
Nell'esempio di codice seguente si presuppone che l'inizializzazione, descritta in Inizializzare unXPS OM , abbia avuto esito positivo.
// Declare the variables used in this section.
HRESULT hr = S_OK;
IOpcPartUri *opcPartUri = NULL;
IXpsOMPackage *xpsPackage = NULL;
IXpsOMDocumentSequence *xpsFDS = NULL;
IXpsOMDocumentCollection *fixedDocuments = NULL;
IXpsOMDocument *xpsFD = NULL;
IXpsOMPage *xpsPage = NULL;
IXpsOMPageReferenceCollection *pageRefs = NULL;
IXpsOMPageReference *xpsPageRef = NULL;
// These values are set outside of this code example.
XPS_SIZE pageSize = {width, height};
// Create the package.
hr = xpsFactory->CreatePackage( &xpsPackage );
// Create the URI for the fixed document sequence part and then
// create the fixed document sequence
hr = xpsFactory->CreatePartUri(
L"/FixedDocumentSequence.fdseq", &opcPartUri );
hr = xpsFactory->CreateDocumentSequence( opcPartUri, &xpsFDS );
// Release this URI to reuse the interface pointer.
if (NULL != opcPartUri) {opcPartUri->Release(); opcPartUri = NULL;}
// Create the URI for the document part and then create the document.
hr = xpsFactory->CreatePartUri(
L"/Documents/1/FixedDocument.fdoc", &opcPartUri );
hr = xpsFactory->CreateDocument( opcPartUri, &xpsFD );
// Release this URI to reuse the interface pointer.
if (NULL != opcPartUri) {opcPartUri->Release(); opcPartUri = NULL;}
// Create a blank page.
hr = xpsFactory->CreatePartUri(
L"/Documents/1/Pages/1.fpage", &opcPartUri );
hr = xpsFactory->CreatePage(
&pageSize, // Page size
L"en-US", // Page language
opcPartUri, // Page part name
&xpsPage);
// Release this URI to reuse the interface pointer.
if (NULL != opcPartUri) {opcPartUri->Release(); opcPartUri = NULL;}
// Create a page reference for the page.
hr = xpsFactory->CreatePageReference( &pageSize, &xpsPageRef );
// Add the fixed document sequence to the package.
hr = xpsPackage->SetDocumentSequence( xpsFDS );
// Get the document collection of the fixed document sequence
// and then add the document to the collection.
hr = xpsFDS->GetDocuments( &fixedDocuments );
hr = fixedDocuments->Append( xpsFD );
// Get the page reference collection from the document
// and add the page reference and blank page.
hr = xpsFD->GetPageReferences( &pageRefs );
hr = pageRefs->Append( xpsPageRef );
hr = xpsPageRef->SetPage( xpsPage );
// Release interface pointer
if (NULL != xpsPage) xpsPage->Release();
if (NULL != pageRefs) pageRefs->Release();
if (NULL != fixedDocuments) fixedDocuments->Release();
if (NULL != xpsPageRef) xpsPageRef->Release();
if (NULL != xpsFD) xpsFD->Release();
if (NULL != xpsFDS) xpsFDS->Release();
if (NULL != xpsPackage) xpsPackage->Release();
Procedure consigliate
Dopo aver usato un'interfacciaIOpcPartUriper creare un componente, ad esempio dopo aver chiamato il metodo CreateDocument nell'esempio di codice, rilasciare il puntatore a tale interfaccia, a meno che non sia necessario per un'altra chiamata.
Argomenti correlati
-
passaggi successivi
-
Posiziona le immagini in un XPS OM
-
utilizzato in questa pagina
-
per altre informazioni