Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » embedding a PDF document as an object in the html code
embedding a PDF document as an object in the html code [message #1810287] Tue, 06 August 2019 14:35 Go to next message
Krzysztof Leja is currently offline Krzysztof LejaFriend
Messages: 26
Registered: April 2019
Junior Member
Hi,
As in the title: I would like to embed a PDF document in the form.
The PDF document is dynamically generated in the client module and stored in the instance of the BinaryResource class.
In the form I created a field inheriting from AbstractHtmlField, where in the execInitField () method I would like to load a PDF document as below in the example:
public class PrintField extends AbstractHtmlField {
	@Override
	protected void execInitField() {
		try {
			BinaryResource pdfContent = TableExporter.getAsPDF(parentTable);
			setValue("object:<center><object data=\"" + pdfContent.getFilename() + "\" type=\"application/pdf\" width=\"100%\" height=\"100%\"><p>No PDF document</p></object></center>");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Question:
How to correctly set the "data" attribute of the Object's tag so that a PDF document stored in the BinaryResource automatically loads in it?
Re: embedding a PDF document as an object in the html code [message #1810308 is a reply to message #1810287] Wed, 07 August 2019 12:53 Go to previous message
Krzysztof Leja is currently offline Krzysztof LejaFriend
Messages: 26
Registered: April 2019
Junior Member
In the meantime, I was able to solve my problem.
I added the "BinaryResource:" prefix to the data attribute and passed the BinaryResource handler to the addAttachment method as follows:
public class PrintField extends AbstractHtmlField {
	@Override
	protected void execInitField() {
		try {
			BinaryResource pdfContent = TableExporter.getAsPDF(parentTable);
			addAttachment(pdfContent);
			setValue("object:<center><object data=\"binaryResource:" + pdfContent.getFilename() + "\" type=\"application/pdf\" width=\"100%\" height=\"100%\"><p>No PDF document</p></object></center>");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Now it works :-)

I also discovered that an alternative effect can be obtained by using an AbstractBrowserField field like this:
public class BrowseField extends AbstractBrowserField {		
			@Override
			protected void execInitField() {
				BinaryResource pdfContent = TableExporter.getAsPDF(parentTable);
				setBinaryResource(pdfContent);
			}
	
			@Override
			protected boolean getConfiguredScrollBarEnabled() {
			          return true;
			}
}

[Updated on: Wed, 07 August 2019 12:59]

Report message to a moderator

Previous Topic:Image blocked from loading - CSP configuration parameters not taken into account ?
Next Topic:Registration Form
Goto Forum:
  


Current Time: Tue Dec 10 21:03:40 GMT 2019

Powered by FUDForum. Page generated in 0.02582 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top