function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paul F-2Paul F-2 

pdf corrupted when created from Salesforce1

I created a VF page that renders as PDF and a simple VF UI page that generates then attaches the PDF to my custom object when the user clicks a 'Create' button.  This is based on Jeff Douglas's excellent article from July 2010.  Everthing works fine in Salesforce web.  The PDF size is 7 KB. I can view the PDF from the 'Notes and Attachments' related list in Salesforce and Salesforce1.  However, when I generate the PDF from Salesforce1 for Android, everything executes without issue but the PDF size is 111 KB instead of 7 KB. In Salesforce1, the PDF will not display - the new window opens but the body is black. In Salesforce web (IE), Adobe Reader says the file is unsupported or damaged.  

My 'Create' button invokes the method below.  Are there any special requirementst for PDF generation from Salesforce1?
Thanks for any assistance.

public PageReference attachReceipt() {
        /* Get the page reference and set the Id */
        PageReference pdfPage = Page.ReceiptPDF;
        pdfPage.getParameters().put('id', shmtId);
       
        /* get the pdf blob */
        Blob pdf;
        try {
         pdf = pdfPage.getContent();
        } catch (VisualforceException e) {
         System.debug('exception');
        }
        /* add the pdf attachment */
        Attachment a = new Attachment(ParentId = shmtId, Body = pdf, contentType = 'pdf', Name = 'Delivery Receipt.pdf');
        try {
            insert a;
        }
        catch (Exception e) {
            System.debug('EXCEPTION:' + e);
        }
              
        return new PageReference('/'+shmtId);
    }
Paul F-2Paul F-2
I switched from inserting the pdf as an Attachment to inserting as a Feed Item and the problem went away.