We’re converting Word documents to PDF and trying combine multiple files into one PDF document.
The requirement to fit converted content into a box to add border and fixed line numbering like this design:
What I tried to do for starters is to get the converted word document, iterate through pages and add their paragraphs into the new PDF paragraphs of a FloatingBox. But it doesn’t work as the paragraphs of the converted document is empty.
Code sample:
try (os) {
new com.aspose.words.Document(is).save(os, SaveFormat.PDF);
}
try (InputStream in = pipe.createInputStream(os);
com.aspose.pdf.Document document = new com.aspose.pdf.Document(in)) {
PageCollection pages = document.getPages();
pages.forEach(convertedPage -> {
Page newPdfPage = pdfDocument.getPages().add();
newPdfPage.getParagraphs().add(new TextFragment("This is a converted file"));
FloatingBox contentBox = new FloatingBox();
contentBox.setHorizontalAlignment(HorizontalAlignment.Right);
contentBox.setWidth(newPdfPage.getPageInfo().getWidth() - 120);
contentBox.setBorder(new BorderInfo(3, Color.getYellow()));
//copy paragraphs from converted word to floating box
convertedPage.getParagraphs().forEach(pr -> contentBox.getParagraphs().add(pr));
newPdfPage.getParagraphs().add(contentBox);
});
The result look like this even though the conversion is successful:
Please advise on what’s the best way to achieve this result.
Thanks
@lqutom It looks like you question more related to Aspose.PDF. But wouldn’t it easier to add line numbers upon conversion the document to PDF? For example see the following code:
Document doc = new Document("C:\\Temp\\in.docx");
for (Section s : doc.getSections())
{
s.getPageSetup().setLineStartingNumber(1);
s.getPageSetup().setLineNumberCountBy(1);
s.getPageSetup().setLineNumberRestartMode(LineNumberRestartMode.RESTART_PAGE);
}
doc.save("C:\\Temp\\out.pdf");
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.