Print orientation using JavaScript, CSS, HTML or PHP

2

Can I "preset" the page orientation when the user is printing is already marked as landscape? (Landscape)

My case is as follows, I'm having code similar to this example

  

link

I'm exporting my HTML to Excel and in this part everything is ok, but the user does not want to lose their precious seconds by setting the page there in Excel printer properties, either when printing the page already is oriented as "landscape" (Landscape) have as using some language of those cited?

    
asked by anonymous 08.09.2015 / 16:38

3 answers

1

If the server platform is Windows. What you can do is create a macro in VBS to do this. Create the file: worksheet.vbs

$file = 'seu_arquivo.xls';
$path = "C:\temp\";
$fp = fopen($path.'worksheet.vbs', 'w');

$content = '
 Sub setUpPage(sheet) 
       With Workbooks("'.$file.'")
          .Sheets (sheet).PageSetup
          .Orientation = xlLandscape 
          .PaperSize = xlPaperA4 
          .Zoom = False
          .FitToPagesWide = 1 
          .FitToPagesTall = False 
       End With 
     End Sub 
';

fwrite($fp, $content);
fclose($fp);

Or without passing file, create without writing:

Sub Macro()
    With ActiveSheet.PageSetup
        .Orientation = xlLandscape
    End With
End Sub

And in PHP, run it:

if (file_exists("{$path}worksheet.vbs")) {
    $WshShell = new COM("WScript.Shell");
    $obj = $WshShell->Run("cscript {$path}worksheet.vbs", 0, true); 
}

Here has more information.

    
16.09.2015 / 15:18
0

I ended up using the JasperServer solution with PHP integration in git that makes this connection is very simple

An example snippet:

try {
    $jasper = new Adl\Integration\RequestJasper();
    /*
    To send output to browser
    */
    header('Content-type: application/pdf');
    echo $jasper->run('/reports/samples/AllAccounts');

    /*
    To Save content to a file in the disk
    The path where the file will be saved is registered into config/data.ini
    */
    //$jasper->run('/reports/samples/AllAccounts','PDF', null, true);

} catch (\Exception $e) {
    echo $e->getMessage();
    die;
}   
    
16.09.2015 / 15:46
-1

I've done this in CSS once and a JS plugin called printElement.js , but it's not necessary if it's a simple page.

Print Element

CSS

@media print{

    @page{
        size: landscape;
    }

    #image-example{
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
    }

}

From the page that will be printed, just call the CSS file with:

media='print'

    
08.09.2015 / 16:49