Redigere i formati PDF in C++

Informazioni di redazione sensibili ai documenti PDF nativi e ad alte prestazioni utilizzando Aspose.PDF lato server per le API C++, senza l’uso di software come Microsoft o Adobe PDF.

Come redigere il file PDF usando la libreria C++

Per oscurare il file PDF, useremo l’API Aspose.PDF for C++ che è un’API di manipolazione dei documenti ricca di funzionalità, potente e facile da usare per la piattaforma cpp. Apri il gestore pacchetti NuGet, cerca Aspose.pdf e installa. È inoltre possibile utilizzare il seguente comando dalla console di Gestione pacchetti.

Redigere documenti PDF tramite C++


È necessario Aspose.PDF for C++ per provare il codice nel proprio ambiente.

  1. Carica il PDF con un’istanza di Document.
  2. Creare un oggetto TextFragmentAbsorber con i termini di ricerca come argomento.
  3. Imposta le opzioni di ricerca.
  4. Esegui un ciclo attraverso ogni frammento raccolto per oscurare.
  5. Salva il file PDF.

Redigere i file PDF - C++


    // Load PDF file
    auto pdfDocument = MakeObject<Document>(u"sourceFile.pdf");

    // Create TextAbsorber object to find all instances of the input search phrase
    auto textFragmentAbsorber = MakeObject<TextFragmentAbsorber>(u"Document");

    // Accept the absorber for all the pages
    pdfDocument->get_Pages()->Accept(textFragmentAbsorber);

    // Get the extracted text fragments
    auto textFragmentCollection = textFragmentAbsorber->get_TextFragments();

    // Loop through the fragments
    for (auto textFragment : textFragmentCollection){
        // Update text and other properties
        textFragment->set_Text(u"UPDATED TEXT");
        textFragment->get_TextState()->set_Font(FontRepository::FindFont(u"TimesNewRoman"));
        textFragment->get_TextState()->set_FontSize(22);
    }

    // Save the resulting PDF document.
    pdfDocument->Save(u"outputFile.pdf");