Lavorare con le pagine in PostScript | C++

Contents
[ Hide Show ]

Aggiungi pagine al documento PS

Aspose.Page per C++ offre due modi per aggiungere pagine all’oggetto PsDocument.

Il seguente frammento di codice crea un documento PS di 2 pagine in 8 passaggi:

  1. Crea un flusso di output per il file PS risultante.
  2. Crea un oggetto PsSaveOptions con opzioni predefinite.
  3. Crea un documento PS di 2 pagine con un flusso di output già creato e opzioni di salvataggio.
  4. Apri la prima pagina con il formato di pagina predefinito del documento (A4 con orientamento verticale).
  5. Chiudi la pagina.
  6. Apri la seconda pagina con un nuovo formato.
  7. Chiudi la pagina. 8. Salvare il documento.
 1    // The path to the documents directory.
 2    System::String dataDir = RunExamples::GetDataDir_WorkingWithPages();
 3    
 4    //Create output stream for PostScript document
 5    {
 6        System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"document1.ps", System::IO::FileMode::Create);
 7        // Clearing resources under 'using' statement
 8        System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
 9        // ------------------------------------------
10        
11        try
12        {
13            //Create save options with A4 size
14            System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
15            
16            // Create new 2-paged PS Document
17            System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, 2);
18            
19            //Add the first page
20            document->OpenPage();
21            
22            //Add content
23            
24            //Close the first page
25            document->ClosePage();
26            
27            //Add the second page with different size
28            document->OpenPage(400.0f, 700.0f);
29            
30            //Add content
31            
32            //Close the second page
33            document->ClosePage();
34            
35            //Save the document
36            document->Save();
37        }
38        catch(...)
39        {
40            __dispose_guard_0.SetCurrentException(std::current_exception());
41        }
42    }

Vedere come lavorare con le pagine nei documenti PS in .NET o Java.

Il seguente frammento di codice crea anche un documento PS di 2 pagine, ma con 7 passaggi:

  1. Creare un flusso di output per il file PS risultante.
  2. Creare l’oggetto PsSaveOptions con le opzioni predefinite.
  3. Creare un documento PsDocument multipagina con flusso di output e opzioni di salvataggio già creati. In questo caso, la prima pagina è già aperta e le sue dimensioni sono quelle predefinite del documento (A4 con orientamento verticale).
  4. Chiudere la pagina.
  5. Aprire la seconda pagina con una nuova dimensione.
  6. Chiudere la pagina.
  7. Salvare il documento. Questo metodo di aggiunta di pagine è utile quando il documento ha 1 pagina o non si sa se sarà un documento di 1 o 2 pagine.
 1    // The path to the documents directory.
 2    System::String dataDir = RunExamples::GetDataDir_WorkingWithPages();
 3    
 4    //Create output stream for PostScript document
 5    {
 6        System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"document2.ps", System::IO::FileMode::Create);
 7        // Clearing resources under 'using' statement
 8        System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
 9        // ------------------------------------------
10        
11        try
12        {
13            //Create save options with A4 size
14            System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
15            
16            //Set variable that indicates if resulting PostScript document will be multipaged
17            bool multiPaged = true;
18            
19            // Create new multipaged PS Document with one page opened
20            System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, multiPaged);
21            
22            //Add content
23            
24            //Close the first page
25            document->ClosePage();
26            
27            //Add the second page with different size
28            document->OpenPage(500.0f, 300.0f);
29            
30            //Add content
31            
32            //Close the second page
33            document->ClosePage();
34            
35            //Save the document
36            document->Save();
37        }
38        catch(...)
39        {
40            __dispose_guard_0.SetCurrentException(std::current_exception());
41        }
42    }

È possibile scaricare esempi e file di dati da GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.