Last active
June 5, 2020 08:46
-
-
Save dmulvi/9acdaed9f306f19aca5d to your computer and use it in GitHub Desktop.
Save File as Note Attachment or Document in SugarCRM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'include/Sugarpdf/Sugarpdf.php'; | |
class CustomSugarpdf extends Sugarpdf | |
{ | |
function Footer() { | |
// just need to remove the unwanted hr | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use this code to save the pdf as a Document | |
require_once 'custom/awesome_directory_name/CustomSugarpdf.php'; | |
// override the footer method in the core class to fix unwanted hr | |
$document = BeanFactory::newBean('Documents'); | |
$document->name = 'New Doc Name'; | |
$document->revision = 1; | |
$document->save(); | |
// create document revision record | |
$docRevision = new DocumentRevision(); | |
$docRevision->revision = 1; | |
$docRevision->document_id = $document->id; | |
$docRevision->filename = $document->name; | |
$docRevision->file_ext = 'pdf'; | |
$docRevision->save(); | |
// create the pdf and save to file system | |
$pdf = new CustomSugarpdf(); | |
$pdf->SetAutoPageBreak(true, 5); | |
$pdf->setHeaderMargin(); | |
$pdf->setHeaderData(PDF_HEADER_LOGO, 60, $document->name); | |
$pdf->setfontsize(8); | |
$pdf->SetTopMargin(30); | |
$pdf->AddPage(); | |
$pdf->writeHTML($html); | |
// save the PDF to filesystem | |
$pdf->Output(getcwd().'/upload/'.$docRevision->id, 'F'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use this code to create the file as a note attachment | |
require_once 'custom/awesome_directory_name/CustomSugarpdf.php'; | |
// override the footer method in the core class to fix unwanted hr | |
$note = BeanFactory::newBean('Notes'); | |
$note->name = 'New File Attachment'; | |
$note->filename = 'New File Yaaay'; | |
$note->file_mime_type = 'application/pdf'; | |
$note->save(); | |
// create the pdf and save to file system | |
$pdf = new CustomSugarpdf(); | |
$pdf->SetAutoPageBreak(true, 5); | |
$pdf->setHeaderMargin(); | |
$pdf->setHeaderData(PDF_HEADER_LOGO, 60, $note->name); | |
$pdf->setfontsize(8); | |
$pdf->SetTopMargin(30); | |
$pdf->AddPage(); | |
$pdf->writeHTML($html); | |
// save the PDF to filesystem | |
$pdf->Output(getcwd().'/upload/'.$note->id, 'F'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment