You need to sign in to do that
Don't have an account?
sonatine
get PDF from external URL
hi guys,
i have a requirement to grab a pdf page from an external link, and attach it into an object.
by that i mean if you open the external link in a browser, it will come up as a pdf file.
i know how to attach it, but as far as i know the PageReference .getContent() can only work for visualforce page.
anyone know how to do this?
thank you in advance.
have you tried to use document and create a document out of the link????
hi vanessen, thanks for the reply.
could you give me a simple example?
is the link to the pdf generated by you or should you pass it via a parameter to the page ?
you can try this :
public Attachment file = new Attachment();
file.url = 'http://......./sample.pdf'; // when using url do not specify the body and bodylength
and then you can attach the file to the object you want
suppose it is to be attached to case,
file.ParentId = newCase.Id; // new Case is a case object
insert file;
hope this help.
hi vanessen,
the url will be passed via parameter.
im clear with the attachment object which i usually used to attach a file.
but how to grab the pdf from the external url?
url to a pdf example: http://www.lc.unsw.edu.au/onlib/pdf/plag.pdf
i want to grab that file and attach it into (for example) case object.
i tried and checked the attachment object, it does not have the 'attachment.url' method.
thanks again.
hi vanessen, thanks again for the reply.
i have tried using the Document.URL.
and as the description said, it will create a document that saves the url.
but it is not actually grabbing the page.
this is what i have so far:
the code will run and attach a file, but when i tried to open the file, it says:
File does not begin with '%PDF-'