Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
O próximo trecho de código cria um novo objeto Document usando uma variável de entrada que contém o caminho para o arquivo PDF. O exemplo acessa os formulários apresentados na página 2 do documento e verifica se há formulários com certas propriedades. Se um formulário do tipo “Typewriter” e subtipo “Form” for encontrado, ele usa TextFragmentAbsorber para visitar e remover todos os fragmentos de texto nesse formulário.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ClearTextInForm(string input, string output)
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextBox.pdf"))
{
// Get the forms from the first page
var forms = document.Pages[1].Resources.Forms;
foreach (var form in forms)
{
// Check if the form is of type "Typewriter" and subtype "Form"
if (form.IT == "Typewriter" && form.Subtype == "Form")
{
// Create a TextFragmentAbsorber to find text fragments
var absorber = new Aspose.Pdf.Text.TextFragmentAbsorber();
absorber.Visit(form);
// Clear the text in each fragment
foreach (var fragment in absorber.TextFragments)
{
fragment.Text = "";
}
}
}
// Save PDF document
document.Save(dataDir + "TextBox_out.pdf");
}
}
Este trecho de código pesquisa os formulários na primeira página de um documento PDF em busca de formulários com uma intenção (IT) de “Typewriter” e um subtipo (Subtype) de “Form.” Se ambas as condições forem atendidas, o formulário é excluído do PDF. O documento modificado é então salvo no arquivo de saída especificado.
A biblioteca Aspose.PDF fornece duas maneiras de remover tais formulários de PDFs:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeleteSpecifiedForm(string input, string output)
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextField.pdf"))
{
// Get the forms from the first page
var forms = document.Pages[1].Resources.Forms;
// Iterate through the forms and delete the ones with type "Typewriter" and subtype "Form"
for (int i = forms.Count; i > 0; i--)
{
if (forms[i].IT == "Typewriter" && forms[i].Subtype == "Form")
{
forms.Delete(forms[i].Name);
}
}
// Save PDF document
document.Save(dataDir + "TextBox_out.pdf");
}
}
Método 2:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeleteSpecifiedForm(string input, string output)
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextField.pdf"))
{
// Get the forms from the first page
var forms = document.Pages[1].Resources.Forms;
// Iterate through the forms and delete the ones with type "Typewriter" and subtype "Form"
foreach (var form in forms)
{
if (form.IT == "Typewriter" && form.Subtype == "Form")
{
var name = forms.GetFormName(form);
forms.Delete(name);
}
}
// Save PDF document
document.Save(dataDir + "TextBox_out.pdf");
}
}
Este código remove todos os elementos de formulário da primeira página de um documento PDF e, em seguida, salva o documento modificado no caminho de saída especificado.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RemoveAllForms(string input, string output)
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "TextField.pdf"))
{
// Get the forms from the first page
var forms = document.Pages[1].Resources.Forms;
// Clear all forms
forms.Clear();
// Save PDF document
document.Save(dataDir + "TextBox_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.