PdfFileMend addText not working

The following code (a modified sample) does not add the added text. Also when used with addImage() the images do not display. Removing the addText() the images display properly.

public class InsertEmptyPageAtEndofPDFFile
{
public static void main(String[] args) throws Exception
{
// The path to the documents directory.
String dataDir = “src/programmersguide/workingwithasposepdf/workingwithpages/insertemptypageatendofpdffile/data/”;

//open first document
com.aspose.pdf.Document pdfDocument1 = new com.aspose.pdf.Document(dataDir + “input.pdf”);

//insert a empty page in a PDF
pdfDocument1.getPages().add();
PdfFileMend mender = new PdfFileMend();
mender.bindPdf(pdfDocument1);
// mender.setWordWrap(true);
// mender.setWrapMode(WordWrapMode.ByWords);

// FormattedText text = new FormattedText(“This is some text”,
// java.awt.Color.BLACK, java.awt.Color.WHITE,
// FontStyle.Courier, EncodingType.Winansi, true, 14 );
// mender.addText(text, 1,
// 100, 200, 200, 400);
mender.addText(new FormattedText(“This is some text”), 1,
100, 200, 200, 400);

//save output file
pdfDocument1.save(dataDir + “output.pdf”);

System.out.println(“Empty page added successfully!”);
}
}

Hi Mark,


Thanks for contacting support.

When using PdfFileMend to add Image/Text stamp, you need to call save(…) method of PdfFileMend class, instead of calling save(…) method from Document instance. For your reference, I have also attached the resultant PDF generated with following code snippet.

[Java]

//open first document<o:p></o:p>

com.aspose.pdf.Document pdfDocument1 = new com.aspose.pdf.Document();

//insert a empty page in a PDF

pdfDocument1.getPages().add();

com.aspose.pdf.facades.PdfFileMend mender = new com.aspose.pdf.facades.PdfFileMend();

mender.bindPdf(pdfDocument1);

//mender.setWordWrap(true);

//mender.setWrapMode(WordWrapMode.ByWords);

//FormattedText text = new FormattedText("This is some text",

// java.awt.Color.BLACK, java.awt.Color.WHITE,

// FontStyle.Courier, EncodingType.Winansi, true, 14 );

//mender.addText(text, 1,

// 100, 200, 200, 400);

mender.addText(new com.aspose.pdf.facades.FormattedText("This is some text"), 1,

100, 200, 200, 400);

mender.save("c:/pdftest/MenderOutput.pdf");

//save output file

//pdfDocument1.save("c:/pdftest/FileMendIssue_output.pdf");

System.out.println(“Empty page added
successfully!”
);