One thing to watch out is the use of images stored in static resources. PDF rendering engine doesn't like them. Start with deleting / commenting out the image-related tags.
If it fixes it - you can still use images you've uploaded to Documents tab (as long as they're marked as "externally available". In my current org I've uploaded logos to production's Documents folder and all email templates point to production link. Looks off, you'd maybe want to point to current sandbox but in dev sandboxes the Documents will always be empty. So it becomes a bit of preference, do you want templates that work everywhere or are you after clear distinction that email from sandbox is OK to not have images so nobody can do something with it by mistake.
Apart from that - ditch the JavaScript, <apex:form>
, <apex:commandButton>
and other "interactive" elements. Buttons will render (like <apex:detail>
will) but it doesn't mean it's a good idea.
I'm a little confused by your updated question. I'm not sure what you're doing with the response object. Here's a little test that I just did which might give you some food for thought:
Visualforce:
<apex:page id="authorizationForm" language="!$CurrentPage.parameters.language}" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false">
<html>
<head>
<style type="text/CSS">
@page {
size: A4;
margin: 25mm;
}
body {
font-family: 'Arial Unicode MS';
font-size: 11px;
color: black;
}
</style>
</head>
<body>
Things with apex:outputText etc.
</body>
</html>
</apex:page>
Apex REST:
@RestResource(urlMapping='/TestPDF/')
global class TestRestPDF
{
@HttpGet
global static String getPdf()
{
Blob pdf = new PageReference('/apex/authorizationForm').getContentAsPDF();
return EncodingUtil.base64Encode(pdf);
}
}
The REST service basically returns a Base64 encoded String representing the PDF. You would then need to decode that in your client app to reconstruct the PDF. You could also generate the PDF directly from the response of the method, for example if you were to paste this in its entirety to your browser URL you'd get a PDF on screen:
data:application/pdf;base64,JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDE1NT4+c3RyZWFtCnicVY5NC4JAGITv8yveY122/VAXOwZ1CDoIL3SIDpHmB2laK/rzW5UOMZeHGZiZDjuGJBtr4hR7RoIOUkhjQxqg6ejDCkrSCZerpBQmIhtGVCO0Cz1nMpGQgWfzh0te4IzG90x659Pg5qBI+cUH1OwqCjRZEwsdENdYcVE2+YeG0hV0a7Nx++pd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the application calling your REST service?
This also appears to return correctly:
global class TestRestPDF
{
@HttpGet
global static void getPdf()
{
Blob pdf = new PageReference('/apex/authorizationForm').getContentAsPDF();
RestContext.response.addHeader('Content-Type', 'application/pdf');
RestContext.response.responseBody = pdf;
}
}
Though, I can only see the RAW response, it may well be worth converting to Base64 first, e.g.:
RestContext.response.responseBody = Blob.valueOf(EncodingUtil.base64Encode(pdf));
Best Answer
Note that you are outputting something of value conditionally otherwise, you are outputting just empty value. Since you have div repeats for each outblock, it will show up as div with empty output field.
You might want to use
render
attribute on div tag to hide that block. See this help for more info on how to conditionally render.