I have an Aura component that download a JSON from an external REST service and I have to render the JSON in a PDF. How can I pass the JSON directly from the aura component in the visualforce page without saving the data some where?

Alternatively, is there a way to reassign the local variable of the visualforce when the page is rendering? What I would like to do is to have a variable in the visualforce that will have the same JSON-structure of the JSON of interest. At the moment I am saving the data in a proper field on a record and recalling it via the page controller, the problem is that I am not able to reassign the variable.

Just to be clear in my Aura Component I am opening the visualforce page as follows:

redirectToPdf: function(bigliettoId, component) {
        console.log('Redirecting to pdf...')
        try {
            window.open('/apex/PdfFattura?bigliettoId=' + bigliettoId)
        } catch (e) {
            console.log('Exception: ', JSON.parse(JSON.stringify(e)))
            component.set("v.success", false)
            component.set("v.successMessage", false)
            component.set("v.error", true)
            component.set("v.messageError", "C'è stato un errore visualizzando la Fattura")

The visualforce is as follows:

<apex:page standardStylesheets="false" standardController="Biglietto__c" extensions="PdfFatturaCtrl" showHeader="false" sidebar="false" applyBodyTag="false" applyHtmlTag="False" >
        <script type="text/javascript">
            function init() {
                let json = '{!json}'
                let fatturaParsed = '{!fattura}'
                // here i want to reassign the local variable fattura from the json that I retrived via the controller as:
                // fattura.FatturaElettronicaHeader
                // fattura.FatturaElettronicaBody
                // ...

    <body onload="init()">
            fattura header: {!fattura.FatturaElettronicaHeader}
            fattura Body: {!fattura.FatturaElettronicaBody}

Actually I thought I could attach the data as body in the url and retrieve the data from the visualforce page, but I am in the same situation, how can I do it?

Thank you in advance for any hint.

  • how large is the json? too large to encode as a url parameter? alternatively, have you looked into rendering the visualforce page as a pdf from apex? you can do that via PageReference.getContentAsPDF(), giving you the Blob data representation of the pdf.
    – stackasaur
    Commented Jul 16, 2021 at 12:31
  • Sorry if I did not answer you. Actually I found a feasible solution in which I created a class for the object and used the function System.JSON.deserialize(jsonStr,Fattura.class) casting as the object Fattura in the controller of the page.
    – Giovanni
    Commented Jul 20, 2021 at 13:42

1 Answer 1


I solved with the following method:

  1. I created a class, with all the subclasses that I needed, to describe the json that I have to pass to the visualforce. The object, just to give the context, is named Fattura.
  2. In the controller, after retrieving the stringified json from the record, I used the function System.JSON.deserialize(jsonStr, Fattura.class) and casted to the desired object, i.e. Fattura.

This gave me the possibility to access the object as it will be a json in the visualforce page via the dot notation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .