Create elements wrapper vertically rotated out of the PDF main central content

I want to position inside an existing pdf and out of the main central content some elements behaving like a block. Those elements consist of a barcode image, some text and another text with a link.

See the attached pdf to make a better idea of what I am refering to: ExamplePDF.pdf (288.4 KB)
Pay attention to the rotated elements on the first page left.

I want all that elements to behave like a block to have the possibity to show then vertically or horizontally in an easy way depending on a parameter.

Which is the best approach to implement this with aspose.pdf java library?

I have tried with tables, with a floating box but don´t find definitely the way to place all the elements like a whole in a concrete position and with a concrete rotation angle.

Thank you in advance!

@aarbosaccasa

Thanks for contacting support.

We have investigated your requirement and tried to come up with a workaround where you can deal with the whole content as a single object to add it inside the PDF document. You can prepare a separate PDF document which contains all the content you want to display as a block in your original file. Later, you can use PdfFileStamp Class to add the stamp inside PDF document. Please check the below code snippet:

Add Pdf File Stamp

com.aspose.pdf.facades.PdfFileStamp fileStamp = new com.aspose.pdf.facades.PdfFileStamp();
fileStamp.bindPdf(dataDir + "ExamplePDF.pdf");
com.aspose.pdf.facades.Stamp stamp = new com.aspose.pdf.facades.Stamp();
stamp.bindPdf(dataDir + "stampDoc.pdf", 1);
stamp.setOrigin(20, 20);
stamp.setRotation(90);
//stamp.IsBackground = false;
fileStamp.addStamp(stamp);
fileStamp.save(dataDir + "output.pdf");
fileStamp.close();

Following is the code which was used to generate the stamp document:

Document stampDoc = new Document();
Page page = stampDoc.getPages().add();
page.getPageInfo().setMargin(new MarginInfo(0,0,0,0));

Table table = new Table();
table.setColumnWidths("50 200 300");
//table.setColumnAdjustment(ColumnAdjustment.AutoFitToContent);
//table.setDefaultCellBorder(new BorderInfo(BorderSide.All, 0.5F));

page.getParagraphs().add(table);

Row row = table.getRows().add();

Image img = new Image();
img.setFixHeight(60);
img.setFixWidth(50);
img.setFile(dataDir + "Barcode.jpg");

Cell cell = row.getCells().add();
cell.getParagraphs().add(img);
cell.setAlignment(HorizontalAlignment.Right);
cell.setVerticalAlignment(VerticalAlignment.Center);

cell.setRowSpan(2);

Cell cell2 = row.getCells().add("Ziurtagiriaren zk. Código de Verificación");
cell2.setAlignment(HorizontalAlignment.Center);
cell2.setVerticalAlignment(VerticalAlignment.Bottom);
Cell cell3 = row.getCells().add("Egiaztatzeko helbidea Dirección de comprobación");
cell3.setAlignment(HorizontalAlignment.Center);
cell3.setVerticalAlignment(VerticalAlignment.Bottom);

Row row2 = table.getRows().add();

Cell cell5 = row2.getCells().add("974w-iyXT-bjZa-We7N");
cell5.setAlignment(HorizontalAlignment.Center);
cell5.setVerticalAlignment(VerticalAlignment.Top);
Cell cell6 = row2.getCells().add("https://domain.es/wps/portal/ConsultaCove");
cell6.setAlignment(HorizontalAlignment.Center);
cell6.setVerticalAlignment(VerticalAlignment.Top);

stampDoc.save(dataDir + "stampDoc.pdf");

Attached is the output PDF document obtained from the approach mentioned above:

output.pdf (345.2 KB)

We hope this would help you in achieving your requirements.

1 Like

This solution works perfectly.
Thank you very much.

@aarbosaccasa

It is good to know that you were able to achieve your requirements with suggested approach. Please keep using our API and feel free to create a new topic in case of any further inquiry.