We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Placing an Image as a replacement to the text (at a specific location of the document) in the PDF

Hi ,

Is there a way in Aspose library to find the XY coordinates and page for a place holder (a peice of text) where an image (jpeg/tiff signature) can be placed over that place holder in a PDF document ?

The idea is to have a signature image to be placed at a place holder(text) using aspose PDF library. If there is no out of the box solution for this you may suggest some workarounds that might help.

Best Regards...

Hi Karri,


Thanks for contacting support.

Aspose.Pdf for Java offers the feature to search text inside PDF file and get coordinates of text fragment inside the PDF document. It also provides the capability to place image at particular location of PDF file (certain X,Y) location. So as per your requirement, you can try using our API to search text inside PDF file, get its coordinates and place image over same location. For further details, please visit


In case you encounter any issue, please share the resource PDF file.

Hello,

Thanks for the information and it helps.

We would like to know if we could insert text (a paragraph of text) into middle of an existing PDF ? If yes please direct us to a suitable example.

Best Regards,

Midhun

Hi Midhun,


Thanks for your feedback. You can easily add text in an existing PDF document. Please check following documentation link for a sample code snippet and details.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Midhun,


Thanks for contacting support.

Adding more to Tilal’s comments, the earlier shared link provides the instructions to add text at any location inside PDF document. However if you need to place the text paragraph in the middle of any existing paragraphs inside PDF document, then you need to try using Search & Text replace feature. Using this approach, you need to find certain TextFragment inside PDF, replace the contents with larger paragraph and enable auto-adjust for PDF contents. For further details, please visit Text Replacement should automatically re-arrange Page Contents

In case you encounter any issue, please share the code snippet and resource PDF files.

Hi Team Support,

Following is the piece of logic that i have been executing to insert a paragraph in a place holder ("[Cname, companyname,Textbox, 50]") in the source pdf (SRC.pdf attached to this post) and obtain the output (as TRG.pdf attached to this postattached to this post) . The issue is that the paragraph that needs to replace the place holder does not wrap to the next line and also gets beyond the margin.

If you think the code needs to be altered, you may tweak it please .

com.aspose.pdf.Document pdfDocument=new com.aspose.pdf.Document("C://Users//999//Desktop//del//work7//SRC.pdf");

com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber1 =

new com.aspose.pdf.TextFragmentAbsorber("[Cname, companyname,Textbox, 50]");

TextEditOptions objTextEditOptions=

new TextEditOptions(ReplaceAdjustment.WholeWordsHyphenation);

textFragmentAbsorber1.setTextEditOptions(objTextEditOptions);

TextReplaceOptions objTextReplaceOptions=

new TextReplaceOptions(ReplaceAdjustment.WholeWordsHyphenation);

textFragmentAbsorber1.setTextReplaceOptions(objTextReplaceOptions);

pdfDocument.getPages().accept(textFragmentAbsorber1);

com.aspose.pdf.TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber1.getTextFragments();

for(TextFragment textFragment : (Iterable)textFragmentCollection1){

textFragment.setText("A Christmas tree is a decorated tree, usually an evergreen conifer such as spruce, pine, or fir associated with the celebration of Christmas. An artificial Christmas tree, usually made from polyvinyl chloride (PVC), is a man-made replication of such a tree and is often used instead of a live tree in order to retain the Christmas spirit and decorations without the care and maintenance of a cut tree");

textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont("Times"));

textFragment.getTextState().setFontSize(10);

textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlack());

textFragment.getTextState().setBackgroundColor(com.aspose.pdf.Color.getWhite());

}

pdfDocument.save("C://Users//999//Desktop//del//work7//TRG.pdf");

Midhun Reddy:

Hi Team Support,

Following is the piece of logic that i have been executing to insert a paragraph in a place holder ("[Cname, companyname,Textbox, 50]") in the source pdf (SRC.pdf attached to this post) and obtain the output (as TRG.pdf attached to this postattached to this post) . The issue is that the paragraph that needs to replace the place holder does not wrap to the next line and also gets beyond the margin.

If you think the code needs to be altered, you may tweak it please .

com.aspose.pdf.Document pdfDocument=new com.aspose.pdf.Document(“C://Users//999//Desktop//del//work7//SRC.pdf”);


com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber1 =

new com.aspose.pdf.TextFragmentAbsorber("[Cname, companyname,Textbox, 50]");


TextEditOptions objTextEditOptions=

new TextEditOptions(ReplaceAdjustment.WholeWordsHyphenation);


textFragmentAbsorber1.setTextEditOptions(objTextEditOptions);


TextReplaceOptions objTextReplaceOptions=

new TextReplaceOptions(ReplaceAdjustment.WholeWordsHyphenation);


textFragmentAbsorber1.setTextReplaceOptions(objTextReplaceOptions);


pdfDocument.getPages().accept(textFragmentAbsorber1);


com.aspose.pdf.TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber1.getTextFragments();


for(TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>)textFragmentCollection1){


textFragment.setText(“A Christmas tree is a decorated tree, usually an evergreen conifer such as spruce, pine, or fir associated with the celebration of Christmas. An artificial Christmas tree, usually made from polyvinyl chloride (PVC), is a man-made replication of such a tree and is often used instead of a live tree in order to retain the Christmas spirit and decorations without the care and maintenance of a cut tree”);


textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont(“Times”));


textFragment.getTextState().setFontSize(10);

textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getBlack());

textFragment.getTextState().setBackgroundColor(com.aspose.pdf.Color.getWhite());


}


pdfDocument.save(“C://Users//999//Desktop//del//work7//TRG.pdf”);

Hi Midhun,

Thanks for sharing the details.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34622. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.