Tāuta mPDF me te kore Kaitito i te tūmau – pūrongo PDF ki PHP

Te mPDF mahia PDF i CSS / HTML ki te ānau ako iti. Ko te ariā ki konei hei mahi mPDF me te kore tāuta i te kaitito ki te tūmau. Ka whakamahia paetata te kaitito, ā, ka tukua ā muri ake ki te tūmau.

TOKANGA: Ki te kore koe e hiahia tāuta i te kaitito ahakoa te aha, ehara tēnei akoranga māu. Ka whakamahia ki tēnei whakairinga te kaitito ā paetata, ā, ā muri ake ka tukua ki te tūmau, kāore he utanga.

whakataki

Enei e kore e kite i ahau papatono i waho te whakamahi i te kaitito. āhei te reira ki a koe te whakahaere ngā wā maha kōwae / hōtuhi hanga e te rōpū tuatoru, me te e wātea ana i roto i https://packagist.org/.

ki kaitito e kore e taea e koe tika tāuta me pōkai whakahou ngāwari, engari noho ano i roto i te tukutahi aunoa i tetahi ririki ki ētahi atu pōkai whakamahia i roto i te tono. I tua atu, He kē prontinho autoload, tuku tukuatu ratou akomanga PHP kahore hiahia ki te whakauru / rapu.

Otiia e kore e he te pou e pā ana ki tenei kaitito :P Kia kite a pehea ki te tāuta me te rere mPDF, he whare pukapuka PHP ki te whakaputa PDF te whakamahi i waehere HTML. Ko te mPDF reira kua ona raruraru, engari te mea ngā ko e waiwai hiahia tika koe ki te eke i tō HTML me ki kaha iti kē ka taea ki te tahuri i te reira ki PDF.

raruraru

Te āhua, te putanga hou, Ko reira tika kaitito ki te tāuta mPDF. reira, te tūtohu Ko e koutou mau haere ki te whakamahi i kaitito i roto i tona mahi whanaketanga.

No reira te pātai: a ki te mea kahore i ahau te tāuta kaitito nonserver? i roto i tenei take, ka whakamahi matou i te pūrere: tāuta kaitito rohe me te ka ara (tukuatu) ki te Tūmau kōpaki “kaihoko“. Fakatatau ki tona kaitito ka waiho te hawhe mate, engari ka tonu kia taea ai ki te whakamahi i mPDF.

otinga

Pērā i kōrerotia i te tīmatanga, ko te whakaaro hei mahi mPDF i runga i te tūmau me te kore tāuta ki te Tūmau. mo tenei, ka mahi mātou i tētahi utanga Paetata o te kaitito, kātahi ka tukua ki te tūmau.

tāuta mPDF e te kaitito E mea ohie roa. haere ki https pae://getcomposer.org/download/, tikiake me te tāuta i te Composer.

Kia whai koe i te kaitito tāuta, ranei Kāpeka tuwhera noa (whakahau) a te uru ki tō whaiaronga tono (i roto i te www / ranei htdocs /, hei tauira), a ka rere i te whakahau e whai ake nei:

$ kaitito rapu mpdf/mpdf

Kia mahara e i te pakiaka o koutou whaiaronga tono hanga te tahi mau kōnae, rite composer.json e composer.lock, rite pai rite te whaiaronga “kaihoko /“. Na te reira ngāwari! E kē koe nga mea katoa e hiahia ana koe mo tou mPDF mahi.

Tangohia kōpaki kaihoko a tukua atu ana e ia ki tou tūmau. kaua, tuu i te reira i roto i te pakiaka, me te waihanga i tētahi kōnae index.php (ano i te pakiaka) ki te whakamātau i te mPDF kei roto i te waehere e whai ake nei:

1
2
3
4
5
<?php
require_once __DIR__ . '/Vendor/autoload.php';
$mpdf = hou mPDF();
$mpdf->WriteHTML('<H1>Hello ao!</H1>');
$mpdf->huaputa();

mahi tenei, ki te haere katoa te pai, Ka pakū ake he PDF tuhituhi “Hello World!“.

pūrongo PDF ki PHP

e kore he kupu a te Komiti te whakaaro o tenei Post, engari tangohia ahau ki te tuhi i te tahi mea atu. Ki te hiahia koe ki te whakaputa pūrongo, kotahi kōwhiringa ko ki te whakaū i to koutou CSS / HTML te kōnae PHP a ka haere i te waehere mo mPDF mahi mahi pakeke, ko te kupu hei tauira (Tirohia te putanga Figure 1 i raro):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require_once __DIR__ . '/Vendor/autoload.php';
ob_start();
?>
<kāhua>
    ripanga, th, TD {
        rohe: 1px pango mārō;
        rohe-tiango: tiango;
        purpuru: 5px;
    }               
    tr ripanga:nth-tamaiti(rerekē) {
      papamuri-tae: #Eee;
    }  
    tr ripanga:nth-tamaiti(ara) {
      papamuri-tae: #fff;
    }   
    th tepu thead {
      papamuri-tae: #ccc;
    } 
    tepu TD tfoot {
      papamuri-tae: #ccc;
    } 
</kāhua> 
<H1>toku Report</H1>
<table align="center">
    <thead>
        <tr>
            <th>ingoa</th>
            <th>tau</th>
            <th>E-mēra</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="3" align="center">Copyright ® 2017</TD>
        </tr>
    </tfoot>>    
    <tbody>
        <tr>
            <TD>Taylor</TD>
            <td align="center">43</TD>
            <TD >taylor@amail.com</TD>
        </tr>
        <tr>
            <TD>Portela</TD>
            <td align="center">47</TD>
            <TD>portela@bmail.com</TD>
        </tr>        
    </tbody>
</ripanga>
<?php
$html = ob_get_contents();
$mpdf = hou mPDF;
$mpdf->WriteHTML($html);
$mpdf->huaputa();

Fig. 1 – kōnae putanga PDF mo te waehere werohia CSS / HTML (ake) tukatuka i te mPDF

Oia mau e taea pai koe hanganga i te waehere e whakatakoto i te CSS / HTML i roto i te kōnae tātauira motuhake, me te uta i reira ki te karanga mPDF.

te mutunga, inaianei ko reira ki runga ki a koutou! E mau ki te pānui i runga i meatia ā- mPDF ka whiwhi i roto i te ara o te whakamahi, me te hototahi.

maha Tapeke o täia: 34084

He arotake i runga i “Tāuta mPDF me te kore Kaitito i te tūmau – pūrongo PDF ki PHP

  1. Hori VB ka mea:

    I mahi tonu ahau i te hātepe pērā ki te whakaahuatanga, engari kāore i hangaia te PDF.
    Tohu ai kāore koe i kite i te tauaha mPDF.
    E mōhio ana ahau he aha te raruraru?

Waiho i te Reply

Ka kore e whakaputaina tō wāhitau īmēra. Kua tohua ngā āpure e hiahiatia ana ki *