hi friends,
Hi,
Thanks for contacting support.
Currently the Rotation enumeration in com.aspose.pdf
package does not support 45 degree angle. For the sake of implementation, I have logged this requirement as PDFNEWJAVA-34182 in our issue tracking system. The development team will further look into the details of this requirement and will keep you posted on the status of correction. Please be patient and spare us some time.
However, as a workaround, you may try using com.aspose.pdf.facades
package. Please try using the following code snippet to accomplish your requirement.
[Java]
//open document
com.aspose.pdf.facades.PdfFileStamp fileStamp = new com.aspose.pdf.facades.PdfFileStamp();
//get total number of pages
int totalPages = new com.aspose.pdf.facades.PdfFileInfo("c:/pdftest/SpecialCharacters_test2.pdf").getNumberOfPages();
//create formatted text for page number
com.aspose.pdf.facades.FormattedText formattedText = new com.aspose.pdf.facades.FormattedText("Page # Of " + totalPages, java.awt.Color.BLUE, java.awt.Color.GRAY, com.aspose.pdf.facades.FontStyle.Courier, com.aspose.pdf.facades.EncodingType.Winansi, false, 14);
//set starting number for first page; you might want to start from 2 or more
fileStamp.setStartingNumber(1);
//add page number
// fileStamp.addPageNumber(formattedText, 0);
com.aspose.pdf.facades.Stamp stamp = new com.aspose.pdf.facades.Stamp();
stamp.bindLogo(formattedText);
stamp.setRotation(45f);
fileStamp.addStamp(stamp);
//save updated PDF file
fileStamp.save("c:/pdftest/Stamped_45_Degree.pdf");
fileStamp.close();
hi,
Hi there,
Thanks for your feedback. It is good to know that your issue has been fixed.
In addition to the above suggested resolution, please note that to rotate a stamp to an arbitrary angle you need to use the setRotateAngle()
method in the com.aspose.pdf
package as follows.
Document pdfDocument = new Document(myDir + "helloworld.pdf");
//create image stamp
ImageStamp imageStamp = new ImageStamp(myDir + "aspose_pdf.jpg");
imageStamp.setBackground(true);
imageStamp.setXIndent(100);
imageStamp.setYIndent(100);
imageStamp.setHeight(300);
imageStamp.setWidth(300);
//imageStamp.setRotate(Rotation.on270);
imageStamp.setRotateAngle(45);
imageStamp.setOpacity(0.5);
imageStamp.setStampId(421);
//add stamp to particular page
pdfDocument.getPages().get_Item(1).addStamp(imageStamp);
//save output document
pdfDocument.save(myDir + "ImageStamp_output45.pdf")
Please feel free to contact us for any further assistance.
Best Regards,
hi Ahmed,
Hi,
hi nayyer.
Hi Chit,
Thanks for your inquiry. You may convert your string to float for the purpose, please check following code snippet. However, if there is some difference in your requirement and my understanding then please share some more details along with sample code, we will look into it and will guide you accordingly.
com.aspose.pdf.facades.Stamp stamp = new com.aspose.pdf.facades.Stamp();
stamp.bindLogo(formattedText);
**float** f = Float.**parseFloat**("60");
stamp.setRotation(f);
fileStamp.addStamp(stamp);
Best Regards,
hi tilal. thank you. i sent you email with my code
Hi Chit,
Hi Chit,
Hi Chit,
Thanks for your inquiry. Please note for multiline Text Stamp use addNewLineText property to add new line in FormattedText object instead creating separate stamp for each line, and use Vertical and Horizontal alignment properties of TextStamp to adjust stamp text automatically. Hopefully following code will help you to accomplish the task. However if there is difference in your requirement and my understanding then please share some more details, so we will guide you accordingly.
ArrayList<String> watermark = new ArrayList<>();
watermark.add("Test Line 1");
watermark.add("Test Line 2");
watermark.add("Test Line 3");
Document pdfDocument = new Document();
pdfDocument.getPages().add();
ArrayList<TextStamp> textStamps = new ArrayList<>();
// arrange muliline text stamp text
FormattedText ft = new FormattedText(watermark.get(0), java.awt.Color.LIGHT_GRAY, "Helvetica", EncodingType.Winansi, false, 80);
for (int i = 1; i < watermark.size(); i++) {
ft.addNewLineText(watermark.get(i));
}
TextStamp stamp = new TextStamp(ft);
stamp.setBackground(true);
stamp.setOpacity(0.5);
stamp.setRotateAngle(-45);
stamp.setTextAlignment(VerticalAlignment.Center);
stamp.setHorizontalAlignment(HorizontalAlignment.Center);
stamp.setVerticalAlignment(VerticalAlignment.Center);
// add stamp to page collection
pdfDocument.getPages().get_Item(1).addStamp(stamp);
pdfDocument.save("test.pdf");
Best Regards,
hi tilal. thank you for the code. it works
Hi Chit,