Using Aspose.Pdf for Template Transformation

Hello,

We are currently looking for a solution that allows us to convert a PDF Template into PDF documents. During the transformation process we want to replace the following template-elements:

  • Replacing single words or sentences (strings)
  • Replacing a complete paragraph
  • Adding paragraphs
  • Removing paragraphs
  • Replacing cell contents in a table (containing only strings)
  • Adding additional rows to a table
  • Removing rows from a table
  • Replacing images (complex charts as well as simple icons).

Would it be possible to do that with the Aspose.PDF for .NET? And how much effort would you estimate to write an appropriate conversion module using Aspose.PDF for .NET?

Hi,

Thanks for contacting support.

In order to accomplish your requirements, please visit Replace Text in a PDF Document.

Currently our API does not support the feature to manipulate complete paragraph and does not support the feature to return paragraph in which searched text is present. However for the sake of correction, its been logged in our issue tracking system as PDFNEWNET-33730 .

Please visit Add Text to a PDF file using C#

In order to remove complete paragraph, first we need to identify the paragraph in which searched text/string is present. However as shared above, its currently not supported.

For required information / instructions, please visit Manipulate tables in existing PDF using C#

I am afraid currently this feature is not supported. However for the sake of correction, we already have logged it as PDFNEWNET-30842 in our issue tracking system.

Please follow the instructions specified over Replace Image in Existing PDF File using C#

The effort to write complete solution depends upon your understanding about our API and in case you need any assistance, please feel free to contact.

Thanks for your response. Would it be easier to do all this using Aspose.Words (e.g. using its mail merge capabilities) and convert the final Word document into PDFß


Thanks, Peter

Hi,


Thanks for the acknowledgement. The above shared details are for Aspose.Pdf for .NET and I have also intimated my fellow from Aspose.Words team and they will reply accordingly.

Hi,

Thanks for your inquiry.

pmaier:

Replacing single words or sentences (strings)

Replacing a complete paragraph

You can meet this requirement by using Aspose.Words for .NET. Please refer to the following article:

http://www.aspose.com/docs/display/wordsnet/Find+and+Replace

pmaier:

Adding paragraphs

Removing paragraphs

Please check the following code:

Document doc = new Document(MyDir + @“input.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);

// Add a new Paragraph with some text

builder.Writeln(“New Paragraph”);

// Remove last Paragraph

doc.LastSection.Body.LastParagraph.Remove();

doc.Save(MyDir + @“16.12.0.docx”);

Also, please check the following article:
Use DocumentBuilder to Insert Document Elements

pmaier:

Replacing cell contents in a table (containing only strings)

Adding additional rows to a table

Removing rows from a table

Please refer to the following article:

http://www.aspose.com/docs/display/wordsnet/Working+with+Tables

pmaier:

Replacing images (complex charts as well as simple icons).

You can find old Shape nodes and then insert a new Shape node at the same location by using CompositeNode.InsertAfter Method or by using DocumentBuilder.MoveTo Method followed by DocumentBuilder.InsertImage Method.

Hope, this helps.

Best regards,

@pmaier

Thanks for your patience.

We are pleased to inform you that the functionality has been added and available in latest version Aspose.PDF for .NET 18.3. We have implemented new functions for searching sections and paragraphs in the text of PDF document pages. Please consider using following code snippet in order to use the new feature:

string textToRemove = "United";

Document doc = new Document(myDir + "amblatt2013-10-05.pdf");
Page page = doc.Pages[2];

ParagraphAbsorber absorber = new ParagraphAbsorber();
absorber.Visit(page);

PageMarkup markup = absorber.PageMarkups[0];

foreach (MarkupSection section in markup.Sections)
{
    foreach (MarkupParagraph paragraph in section.Paragraphs)
    {
        bool isTextFound = false;

        foreach (TextFragment fragment in paragraph.Fragments)
        {
            if (isTextFound || !fragment.Text.Contains(textToRemove))
                continue;
            isTextFound = true;
        }

        if (isTextFound)
        {
            foreach (TextFragment fragment in paragraph.Fragments)
            {
                fragment.Text = String.Empty;
            }
        }
    }
}

doc.Save(myDir + "amblatt2013-10-05_paragraph_removing.pdf");

Concerning to the other logged issue PDFNET-30842, we will surely let you know once we make some significant progress towards its resolution. Please spare us little time.

We are sorry for the inconvenience.