2adbdfda by Jeff Balicki

wiziwig

1 parent 76e79207
......@@ -34,6 +34,9 @@ class PdfController extends Controller
$pdffile = $searchpath.'/'.$rows[0]->file;
//$outfile="";
$title = "Test Pages";
$pageHeight = $rows[0]->pheight;
$pageWidth = $rows[0]->pwidth;
$storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
$outfile = $storagePath.$searchpath."/new_".$rows[0]->file;
$download = 'http://localhost:8888/pdf-customizer/public/fileentry/getPDF/'.$searchpath."/new_".$rows[0]->file;
......@@ -81,7 +84,8 @@ try {
die("Error: " . $p->get_errmsg());
/* Dummy page size; will be adjusted later */
$p->begin_page_ext(10, 10, "");
$p->begin_page_ext($pageWidth, $pageHeight , "");
/* Place the imported page on the output page, and
* adjust the page size */
......@@ -93,11 +97,19 @@ try {
$pageNumber = $row->pages;
if($pageNumber == $pageno ) {
if ($row->change_type == 'text') {
if ($row->change_type == 'textflow') {
//Get font var from row
$textline = $row->content;
$textline = str_replace('<p>','<nextparagraph leading=100%>', $textline);
$textline = str_replace('</p>','', $textline);
$textline = str_replace('<br />','<nextline leading=80%>', $textline);
$textline = str_replace('<strong>','<fakebold=true>', $textline);
$textline = str_replace('</strong>','<fakebold=false>', $textline);
$textline = str_replace('<em>','<italicangle=-12>', $textline);
$textline = str_replace('</em>','<italicangle=0>', $textline);
$textline = str_replace('&amp;','&', $textline);
$textLUp = $row->locationUp;
$textwidth = $row->width;
$textheight = $row->height;
......@@ -107,6 +119,7 @@ try {
$fontAlignment = $fontStyles["alignment"];
$fontFamily = $fontStyles["font-family"];
$fontSize = $fontStyles["font-size"];
if(isset($fontStyles["font-color"])) {
$fontColor = $fontStyles["font-color"];
}else{
......@@ -122,16 +135,55 @@ try {
die("Error: " . $p->get_errmsg());
}
$p->setfont($font, $fontSize);
$num_optlist = "fontname=".$fontFamily." fontsize=".$fontSize." encoding=unicode alignment=".$fontAlignment." fillcolor={".$fontColor." }";
$num_optlist = "fontname=".$fontFamily." fontsize=".$fontSize." encoding=unicode alignment=".$fontAlignment." fillcolor={".$fontColor." } ";
$textline = $p->create_textflow($textline , $num_optlist);
$fit_optlist = "firstlinedist=capheight";
$fit_optlist = "firstlinedist=capheight ";
$result = $p->fit_textflow($textline, $textLRight, $textLUp, ($textwidth + $textLRight) ,($textheight + $textLUp) ,$fit_optlist);
} else if ($row->change_type == 'text') {
$yoff = 50;
//Get font var from row
$textline = $row->content;
$textLUp = $row->locationUp;
$textwidth = $row->width;
$textheight = $row->height;
$textLRight = $row->locationRight;
$fontStyles = unserialize($row->style);
$fitmethod = $fontStyles["fitmethod"];
$fontAlignment = $fontStyles["alignment"];
$fontFamily = $fontStyles["font-family"];
$fontSize = $fontStyles["font-size"];
if(isset($fontStyles["font-color"])) {
$fontColor = $fontStyles["font-color"];
}else{
$fontColor = 'cmyk 0.75 0.68 0.67 0.90';
}
/// Load and insert text and font
$p->set_option("FontOutline={" . $fontFamily . "=" . $storagePath . $folder . "/" . $fontFamily . ".otf}");
/* For PDFlib Lite: change "unicode" to "winansi" */
$font = $p->load_font($fontFamily, "unicode", "embedding");
if ($font == 0) {
die("Error: " . $p->get_errmsg());
}
$p->setfont($font, $fontSize);
//$num_optlist = "fontname=".$fontFamily." fontsize=".$fontSize." encoding=unicode alignment=".$fontAlignment." fillcolor={".$fontColor." }";
if($fitmethod == ''){$fitm ="";
}else{ $fitm = "fitmethod=".$fitmethod;}
$num_optlist = "fillcolor={".$fontColor." } position={".$fontAlignment."} boxsize={" . $textwidth." ".$textheight . "} fontsize=".$fontSize." ".$fitm. "showborder ";
$result = $p->fit_textflow($textline, $textLRight, $textLUp, $textwidth ,$textheight ,$fit_optlist);
$p->fit_textline($textline, $textLRight, $textLUp, $num_optlist);
}
} else if ($row->change_type == 'img') {
else if ($row->change_type == 'img') {
//Get image var from row
......@@ -140,9 +192,15 @@ try {
$imgLRight = $row->locationRight;
$bw = $row->width;
$bh = $row->height;
$ImageStyles = unserialize($row->style);
//var_dump($ImageStyles);
$ImagePosition = $ImageStyles["position"];
$ImageFitmethod = $ImageStyles["fitmethod"];
$ImageScale = $ImageStyles["scale"];
$ImagesOrientate = $ImageStyles["orientate"];
//Load and insert the images
$buf = "boxsize={" . $bw . " " . $bh . "} position={center} fitmethod=meet";
$buf = "boxsize={" . $bw . " " . $bh . "} position={".$ImagePosition."} scale=".$ImageScale." orientate=".$ImagesOrientate." fitmethod=".$ImageFitmethod." ";
$image = $p->load_image("auto", $storagePath . $imagefile, "");
if ($image == 0) {
die("Error: " . $p->get_errmsg());
......@@ -150,7 +208,45 @@ try {
$p->fit_image($image, $imgLRight, $imgLUp, $buf);
}else if ($row->change_type == 'texthidden') {
$yoff = 50;
//Get font var from row
$textline = $row->content;
$textLUp = $row->locationUp;
$textwidth = $row->width;
$textheight = $row->height;
$textLRight = $row->locationRight;
$fontStyles = unserialize($row->style);
$fontAlignment = $fontStyles["alignment"];
$fontFamily = $fontStyles["font-family"];
$fontSize = $fontStyles["font-size"];
$fitmethod = $fontStyles["fitmethod"];
if(isset($fontStyles["font-color"])) {
$fontColor = $fontStyles["font-color"];
}else{
$fontColor = 'cmyk 0.75 0.68 0.67 0.90';
}
/// Load and insert text and font
$p->set_option("FontOutline={" . $fontFamily . "=" . $storagePath . $folder . "/" . $fontFamily . ".otf}");
/* For PDFlib Lite: change "unicode" to "winansi" */
$font = $p->load_font($fontFamily, "unicode", "embedding");
if ($font == 0) {
die("Error: " . $p->get_errmsg());
}
$p->setfont($font, $fontSize);
//$num_optlist = "fontname=".$fontFamily." fontsize=".$fontSize." encoding=unicode alignment=".$fontAlignment." fillcolor={".$fontColor." }";
if($fitmethod == ''){$fitm ="";
}else{ $fitm = "fitmethod=".$fitmethod;}
$num_optlist = "fillcolor={".$fontColor." } position={".$fontAlignment."} fitmethod=".$fitmethod." boxsize={" . $textwidth." ".$textheight . "} fontsize=".$fontSize."";
$p->setfont($font, $fontSize);
$p->fit_textline($textline, $textLRight, $textLUp, $num_optlist);
}
}
......
......@@ -119,7 +119,7 @@ class pdfModel extends Model
$fileName = explode('.', $fileName);
$pdfId = DB::table('PDF')->insertGetId(
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg','pheight' => $json->pdf[0]->pageHeight, 'pwidth' => $json->pdf[0]->pageWidth)
);
foreach($json->changes as $change) {
......