I want to export/print only a form in PDF.
This is the entire form
and I want to print just the those inside the box.
the main form is app.blade.php and it includes the side panel,header and the mid content(the data inside the red "box")
this is the code I've done so far:
public function exportToPDF($projectID){
$project = Project::find($projectID);
$users = $project->users;
$pdf = PDF::loadView('admin.projects.more', compact('project','users'));
return $pdf->download('invoice.pdf');
}
it shows no error and downloads the file, but it is like this:
I don't understand why it even gets all the other stuff, when I've declared only projects.more
any idea?
Use Inline CSS ,I have same issue Dompdf doesn't support external css
Related
I want to create a pdf page from html file in Laravel but I do not know how to do it. You can help me
https://github.com/barryvdh/laravel-dompdf
// Import in top of controller file
use Barryvdh\DomPDF\Facade as PDF;
// use below code to generate and download pdf file
$pdf = PDF::loadView('bladefilename', ['arrayname' => $array]);
return $pdf->download('filename.pdf');
Write Above code in the controller file
In Blade file (HTML file) set array data.
Show Below Link : https://github.com/barryvdh/laravel-dompdf/issues/126
I know I am a little bit late but hopefully this will help someone.
There are 2 ways:
Create HTML page and use jspdf to print this page. The best way is to use html2pdf: https://github.com/eKoopmans/html2pdf.js
You can use this one to convert html to canvas and print to pdf. All css will be kept but you have to change the page to fix the space between pages as there may be some bad cut at the end of each page.
Print the page using latex. You have to use laravel latex compiler: https://github.com/fvhockney/latexcompiler
It is a little bit harder to styling the page but there is no problem with paging.
I am trying to put html and save it as pdf. however, it seems the content inside pdf not rendered well. I am using plugin from maatwebsite. Here is the code I've tried
Controller
Excel::create('test',function($file){
$file->sheet('Sheet1', function ($sheet){
$sheet->loadView('excel');
$sheet->setAutoSize(true);
});
})->store('pdf',storage_path('uploaded-excel'));
View
<body>
<p>test</p>
<img src="images/hierarchy.png"/>
</body>
Result
But when I remove img tag, the size itself looks normal
What am I missing?
I use https://github.com/barryvdh/laravel-dompdf plugin instead of using inbuilt function from maatwebsite
I am using yii2 and want to convert my html view to pdf format, for that I have use
mPDF yii2 install .
In my controller action , I am doing this:
public function actionPdf(){
Yii::$app->response->format = 'pdf';
$this->layout = '//print';
return $this->render('myview', []);
}
When I remove Yii::$app->response->format = 'pdf'; this line from action. I always get my correct view with css.
But when I use Yii::$app->response->format = 'pdf'; this for pdf generation , I get only pdf view without css.
I have included my CSS file in layout. What should I have to do for getting my correct pdf view?
Have you included the CSS inline?
Is the CSS you expect allowed by mPDF?
Basically, yii2-pdf is a thin wrapper around the mPDF library. It will not include your styles if they are required through a <link, only if they are included as a <style tag.
**Controller** : Test
**View where the form resides** : index.ctp
**View containing fpdf code** : pdf.ctp
I generate a pdf file using FPDF but the pdf file is not rendering properly. I have confirmed that the FPDF code is error free.
On URL
localhost/project/test
I will fill up a form and press submit. This will submit to
localhost/project/test/pdf
But here the pdf is not rendering properly. It just keeps on telling Loading.
If i submit it to some other folder/pdf.php file (same fpdf code in php file)
Everything is ok
localhost/fpdf/pdf.php
I'm answering my questions myself. Come on people HELP ME!!
The problem was that the output was not rendering as pdf. I used this controller to solve my problem.
public function pdf()
{
$this->response->type('pdf');
}
This is the case:
I have a form where the user has to fill in 5 fields. I also have a PDF template with some layout with 5 empty colored boxes.
Now when the user fills in the form a PDF should be generated from the pdf template and the fields that the user has given in should be added to the template.
Now my question what's the best and easiest way to do this? I've look at the library laravel-dompdf but it didn't look like it's working with templates.
Did anybody had to do this? If yes, how did you do it? I'm working with laravel 5.0 .
I've used the packages fpdf and fpdi to work with pdf templates.
I use the "vsmoraes/laravel-pdf": "^1.0" package and it does well for us.
use Vsmoraes\Pdf\Pdf;
private $pdf;
public function __construct(Pdf $pdf)
{
$this->middleware('auth');
$this->pdf = $pdf;
}
public function pdfMaker($data)
{
$html = view('pdf.shippinglabel')->with('purchase', $purchase)->with('products', $products)->render();
$label = $this->pdf->load($html)->output();
file_put_contents(storage_path()."/ftp/po/label_".$id.".pdf",$label);
}
And then I have the formatted pdf with embedded CSS and not including external CSS file linking.
here's the github url: https://github.com/vsmoraes/pdf-laravel5
Dompdf doesn't work with pdf templates, but it works with HTML templates.
So, you can do this way:
Prepare a HTML template and place some placeholders( i.e: {field1}, {field2}, ecc ) where you want to print the values you'll get from the form
When the form is submitted, load the html template into a string, replace the placeholders in the string with the actual values you got from the form
Pass the string (that will contain valid html) to dompdf and it will generate a PDF file
With the Laravel package from Barry (https://github.com/barryvdh/laravel-dompdf) you can load views. So in that way it is possible to make a template using the Blade views.