I am trying to wkhtmltopdf for download my data to pdf getting an errors below.
Any help would be really appreciated.
An uncaught Exception was encountered
Type: Exception
Message: System error
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[=======> ] 12%
Warning: SSL error ignored
[========> ] 14%
[=========> ] 16%
[==========> ] 18%
[============> ] 20%
[=============> ] 23%
[===============> ] 25%
[================> ] 27%
[=================> ] 29%
[==================> ] 31%
[===================> ] 33%
[=====================> ] 35%
[======================> ] 38%
[========================> ] 40%
[=========================> ] 43%
[===========================> ] 45%
[============================> ] 47%
[=============================> ] 49%
[=====================================> ] 63%
[==========================================> ] 70%
[=============================================> ] 76%
[=================================================> ] 83%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[==============================> ] Page 1 of 2
[============================================================] Page 2 of 2
Done
Filename: application/libraries/Wkhtmltopdf.php
Line Number: 866
Backtrace:
File: /var/www/admin/index.php
Line: 315
Function: require_once
Here's the line from my PHP codeigniter file that's sending the error in case that helps:
$html = $this->load->view('report/view_course_summary_pdf', $data, true);
$pdfFilePath = "Course_Summary_Report.pdf";
$options['path'] = $myPath;
$options['orientation'] = 'Landscape';
$options['commandOptions'] =
array(
'useExec' => true, // Can help if generation fails without a useful error message
'procEnv' => array(
// Check the output of 'locale' on your system to find supported languages
'LANG' => "'" . $this->session->userdata('lang_code') . "_US.utf-8" . "'",
)
);
$this->load->library('wkhtmltopdf', $options);
$this->wkhtmltopdf->setTitle($this->common_lang->get_lang_token('course_summary_report'));
$this->wkhtmltopdf->setOptions(['ignoreWarnings' => true]);
$this->wkhtmltopdf->setHtml($html); // $html can be a url or html content.
$this->wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD, $pdfFilePath);
A bunch of people have talked about similar issues that are related to using WKPDF with an SSL, but I don't think that's causing my problems since it says the SSL error was ignored... Any help would be really appreciated. Whenever I try doing it, there my HTML is download but it corrupted format using above Codeginter code.
Related
Very new to php unit and can't exactly work out whats wrong. My class is as follows:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/assets/php/global_php_includes.php';
use PHPUnit\Framework\TestCase;
final class PesticideTests extends TestCase {
public function addPesticideTest() {
$data = array(
"code" => randomString(16),
"created_by" => $_SESSION['userCode'],
"company_code" => "TEST_COMPANY",
"crop_code" => "TEST_CROP",
"content" => "TEST_CONTENT",
"comments" => "TEST_COMMENTS",
"function" => "TEST_FUNCTION",
"pcs_no" => 0123,
"phi" => "TEST_PHI",
"product_name" => "TEST_PRODUCT",
"substance" => "TEST_SUBSTANCE",
"date_of_reg_review" => "01-01-0001",
"use_by_date" => "01-01-0001",
"off_label_approval" => "TEST_OFF_LABEL_APPROVED",
"latest_time_of_application" => "TEST_LATEST_TIME_OF_APPLICATION",
"max_individual_dose" => "TEST_MAX_INDIVIDUAL_DOSE",
"max_total_dose" => "TEST_MAX_TOTAL_DOSE",
"max_no_applications" => "TEST_MAX_NO_APPLICATIONS",
"method_of_application" => "TEST_METHOD_OF_APPLICATION",
"status" => 'inactive'
);
$result = addPesticide($connection, $data);
$this->assertEquals(1, $result);
}
}
the command I run to test it is ./vendor/bin/phpunit tests/PesticideTests.php
and the error I get is
PHP Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHP Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 00:00.014, Memory: 4.00 MB
There was 1 warning:
1) Warning
No tests found in class "PesticideTests".
WARNINGS!
Anyone have any idea what I'm doing wrong? If I also run it as just ./vendor/bin/phpunit tests then I get the error "No tests found". Pretty confused
EDIT:
I have fixed the test not being found by naming it by the wrong convention, still getting an error for the include file
When running your code withing phpunit there is no $_SERVER['DOCUMENT_ROOT'] set. This only gets set when running in the context of a webserver. Just replace this with the directory where the assets directory is.
I am working on a functional test to check a specific user can't update a resource, in this case the API replays with a 404 error. This is the test:
static::createClient()->request(
'PUT',
'/api/bookings/' . $bookingIdToUpdate,
[
'auth_bearer' => $token,
'json' => [
'requestedBy' => 'a new value for this field',
],
]
);
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND, 'This user is not expected to be able to update this booking');
when I run this test, I get a 404 response, which is fine:
Testing App\Tests\Integration\BookingTest
2020-01-21T15:00:07+00:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Not Found" at /var/www/html/vendor/api-platform/core/src/EventListener/ReadListener.php line 116
. 1 / 1 (100%)
Time: 38.89 seconds, Memory: 42.50 MB
OK (1 test, 1 assertion)
so the test is passing but the console is still displaying the exception. so I added this just before client call:
$this->expectException(NotFoundHttpException::class);
and this is the result:
Testing App\Tests\Integration\BookingTest
2020-01-21T15:15:05+00:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Not Found" at /var/www/html/vendor/api-platform/core/src/EventListener/ReadListener.php line 116
F 1 / 1 (100%)
Time: 41.39 seconds, Memory: 42.50 MB
There was 1 failure:
1) App\Tests\Integration\BookingTest::testUserCantUpdateABookingFromAnotherOrganisation
Failed asserting that exception of type "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" is thrown.
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
as you can see the exception is thrown, but at the same time I am getting an error saying it was not. Any idea how to catch this?
Ensure you call the following method first:
$client->catchExceptions(false);
For example:
public function testUserCantUpdateABookingFromAnotherOrganisation()
{
$this->expectException(NotFoundHttpException::class);
$client = static::createClient();
$client->catchExceptions(false);
$client->request('GET', '/foo/bar');
$client->request(
'PUT',
'/api/bookings/' . $bookingIdToUpdate,
[
'auth_bearer' => $token,
'json' => [
'requestedBy' => 'a new value for this field',
],
]
);
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND, 'This user is not expected to be able to update this booking');
}
Short:
What do I have to do with the result of the sendEmail() method of the SES-API from Amazon AWS?
Long:
I have successfully installed the "aws/aws-sdk-php": "^3.38" via composer in a PHP project.
I have successfully sent emails over the formula:
$client = new SesClient( $sesParameters );
$result = $client->sendEmail( $emailSesArgs );
It works.
I receive a result like this one:
Result {#433 ▼
-data: array:2 [▼
"MessageId" => "0102015fd3c21fd2-98a104e2-0c3f-4078-90ed-0be3a12ae812-000000"
"#metadata" => array:4 [▼
"statusCode" => 200
"effectiveUri" => "https://email.eu-west-1.amazonaws.com"
"headers" => array:4 [▼
"x-amzn-requestid" => "e27b7805-cd11-11e7-9d57-cd9600d88c96"
"content-type" => "text/xml"
"content-length" => "326"
"date" => "Sun, 19 Nov 2017 10:10:35 GMT"
]
"transferStats" => array:1 [▼
"http" => array:1 [▼
0 => []
]
]
]
]
}
Questions
The questions are...
What should I do with this result, further than exploring the 200 OK result in real time?
What operations can I perform afterwards using this MessageId?
I've observed that if I send an email to an invalid address, this also returns 200 OK. Probably this is more an "acknowledge" that the send-email "request" has been submitted than actually processing of it. Can I use the result to further read the "status" of the deilvey itself via API to discover if the email was successfully delivered?
Thanks!
What I do is I track message deliveries, bounces and complaints using the message ID by configuring SNS topics (SES > Domains > example.com > Notifications) that trigger an AWS Lambda function (SNS > Topics > Subscriptions), which in turn stores/updates the delivery status in a DynamoDB table for later query operations.
I m trying to implement Knp SNappy Bundle to display an html page as a pdf from my controller.
I'm stuck with this error :
The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==========> ] 18%
Warning: Failed to load file:///slick/slick.css (ignore)
Warning: Failed to load file:///slick/slick-theme.css (ignore)
Warning: Failed to load file:///clovis-app/style.css (ignore)
Warning: Failed to load file:///clovis-app/estimate.css (ignore)
Warning: Failed to load file:///clovis-app/res/clovis.png (ignore)
Warning: Failed to load file:///js/collection.js (ignore)
Warning: Failed to load file:///clovis-app/script.js (ignore)
Warning: Failed to load file:///clovis-app/estimate.js (ignore)
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[===================> ] Page 1 of 3
[=======================================> ] Page 2 of 3
[============================================================] Page 3 of 3
Done
Exit with code 1 due to network error: ContentOperationNotPermittedError"
stdout: ""
command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --lowquality "C:\Users\Razgort\AppData\Local\Temp\knp_snappy55ae6cc4ad0353.17775155.html" "C:\Users\Razgort\AppData\Local\Temp\knp_snappy55ae6cc4ad41d0.64896673.pdf".
Here is my configuration file :
knp_snappy:
pdf:
enabled: true
binary: "\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\""
options: []
image:
enabled: true
binary: "\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe\""
options: []
and here is how i render the view :
$html = $this->renderView('CompanyBundle:Estimate:edit.html.twig', array(
'estimate' => $estimate,
'estimateForm' => $estimateForm->createView(),
'articleForm' => $articleForm->createView(),
'articleSelectForm' => $articleSelectForm->createView(),
'manpowerForm' => $manpowerForm->createView(),
'manpowerSelectForm' => $manpowerSelectForm->createView(),
'workSelectForm' => $workSelectForm->createView(),
'workForm' => $workForm->createView(),
'bundleForm' => $bundleForm->createView(),
'bundleSelectForm' => $bundleSelectForm->createView(),
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
I eard there is problems on MAMP, i use wamp, didn't see any issue with it.
I'll really appreciate some help on this =)
Edit :
I modified some things in order to generate a pdf first. And i did. But the pdf only contents my login page. Then i added the access to my session and it worked. But when i try to send it as a response like that :
$session = $this->get('session');
$session->save();
session_write_close();
$pageUrl = $this->generateUrl('estimate_preview', array('id' => $id), true);
return new Response(
$this->get('knp_snappy.pdf')->getOutput($pageUrl, array('cookie' => array($session->getName() => $session->getId()))),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
it doesn't seem to work either... Does someone have an idea why ?
Try by using forward (getContent()) method instead render.
$html = $this->forward('CompanyBundle:Estimate:edit.html.twig', array(
'estimate' => $estimate,
'estimateForm' => $estimateForm->createView(),
'articleForm' => $articleForm->createView(),
'articleSelectForm' => $articleSelectForm->createView(),
'manpowerForm' => $manpowerForm->createView(),
'manpowerSelectForm' => $manpowerSelectForm->createView(),
'workSelectForm' => $workSelectForm->createView(),
'workForm' => $workForm->createView(),
'bundleForm' => $bundleForm->createView(),
'bundleSelectForm' => $bundleSelectForm->createView(),
))->getContent();
$pdf =$this->get('knp_snappy.pdf')->getOutputFromHtml($html);
First check by printing $pdf and then you can return it as a response.
Do this for all your CSS files in your Twig:
<link rel="stylesheet" href="{{ app.request.scheme ~'://'~ app.request.httpHost ~ asset('css/my_custom_stylesheet.css') }}" />
The CSS folder must be directly under /web
Knp SNappy Bundle is a wrapper. In your symphony side you do all right.
But in your HTML-to-render you have relative URLs, that is not absolute to HTTP-server. So when wkhtmltopdf see in your HTML url like '/dsasdaasd/sdaasd.wtf', it does not know, that it's your site.
1st option. Render PDF by URL (pass some option like "use print styles").
2nd: Use in your HTML absolute pathes to assets.
Anyway there is no absolute correct HTML, so you can meet in the future more errors like this -- even if in huge HTML there will be only one not-found-image. So try to find some options in snappy to ignore these errors as in the result pdf will be generated ok.
I'm trying to set up my first Kohana web page, using this tutorial - http://kohana-tutorial.blogspot.co.uk/2010/10/lesson-1-getting-started.html
After following the instructions, I am left with this error - Undefined property: Request::$action on line 49.
This is the code related to that line, in DefaultTemplate.php
48 if (!$view){
49 $view = 'pages/'.$this->request->controller().'/'.$this->request->action.'_tpl';
50 }
51 $this->template->content = View::factory($view, $this->data);
52 }
53 }
54 ?>
This is called by News.php, which is a standard call to render something.
class Controller_News extends Controller_DefaultTemplate {
public function __construct(\Request $request, \Response $response) {
parent::__construct($request, $response);
}
public function action_index(){
$this->render();
}
}
The complete list of programs used to get to this error is :
APPPATH/classes/Controller/DefaultTemplate.php [ 49 ] » Kohana_Core::error_handler(arguments)
APPPATH/classes/Controller/News.php [ 13 ] » Controller_DefaultTemplate->render()
SYSPATH/classes/Kohana/Controller.php [ 84 ] » Controller_News->action_index()
{PHP internal call} » Kohana_Controller->execute()
SYSPATH/classes/Kohana/Request/Client/Internal.php [ 97 ] » ReflectionMethod->invoke(arguments)
SYSPATH/classes/Kohana/Request/Client.php [ 114 ] » Kohana_Request_Client_Internal- >execute_request(arguments)
SYSPATH/classes/Kohana/Request.php [ 997 ] » Kohana_Request_Client->execute(arguments)
DOCROOT/index.php [ 118 ] » Kohana_Request->execute()APPPATH/classes/Controller/News.php [ 13 ] » Controller_DefaultTemplate->render()
SYSPATH/classes/Kohana/Controller.php [ 84 ] » Controller_News->action_index()
{PHP internal call} » Kohana_Controller->execute()
SYSPATH/classes/Kohana/Request/Client/Internal.php [ 97 ] » ReflectionMethod->invoke(arguments)
SYSPATH/classes/Kohana/Request/Client.php [ 114 ] » Kohana_Request_Client_Internal->execute_request(arguments)
SYSPATH/classes/Kohana/Request.php [ 997 ] » Kohana_Request_Client->execute(arguments)
DOCROOT/index.php [ 118 ] » Kohana_Request->execute()
Any help would be gratefully recieved.
This tutorial is 4 years old, so it is probably a little outdated.
With current version of Kohana, You can access to the protected property $request->_action with the following:
$this->request->action();
Don't hesitate to check the online documentation or even the source code in system/classes/Kohana, which is clear and well commented.