Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:31:39+00:00 2026-06-16T04:31:39+00:00

I have written a script in php that is used for generating pdf’s out

  • 0

I have written a script in php that is used for generating pdf’s out of html. Basically it get’s the html string, saves it as a .html file and finally renders the page in phantomjs and joins the pdfs to one file with imagemagick. Now I need to have it working for the enterprisey people, which means rewriting this to C# and making it runnable on MS servers. I’ve never did any C# programming, nor used .net, asp etc so I need some resources how and where to start with. What should I use as a server, how to setup it and then how to code in C# for the web.

This is my php script :

<?php
    function curPageURL() {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
            $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    }

    $currentURL  = curPageURL();
    $break       = explode('/', $currentURL);
    $currentURL  = str_replace($break[count($break) - 1], '', $currentURL); 

    $cmd         = '';
    $phantomOut  = array();
    //name of the created single PDF file
    $out         = '-exported'.microtime().'.';
    //path were temporary pdf files will be created
    $outputPath  = dirname(__FILE__);
    //command to run phantomjs in console/terminal
    $phantomPath = 'phantomjs';

    if(isset($_POST['html'])){
        $html        = json_decode($_POST['html'], true);
        $out         = $range.$out.'pdf';        
        $l           = 0;        

        $myFile = $outputPath."/printHtml".microtime().".html";
        $fh     = fopen($myFile, 'w');

        //check if file is writable
        if(is_writable($myFile)){
            fwrite($fh, $html[$i]['html']);
            fclose($fh);
            $myFile = str_replace($outputPath.'/', '', $myFile);
        } else {
            echo '{"success": false, "msg": "Can\'t create or read file."}';
            return 0;
        }

        //check if phantomjs is installed and reachable
        exec($phantomPath.' -v', $phantomOut);
        if (empty($phantomOut)){
            echo '{"success": false, "msg": "PhantomJS not installed or not reachable."}';
            return 0;
        }

        $phantomOut = array();

        //run PhantomJs with parameters : temporary html filenames sent, format of the page and page orientation
        $command = $phantomPath.' '.$outputPath.'/render.js "'.$myFile.'" "'.$currentURL.'"';

        exec($command, $phantomOut);

        //delete temp html file
        unlink($myFile[$i]);

        if (file_exists($phantomOut[0]) && filesize($phantomOut[0]) > 0){
            //return url of the created file
            echo '{"success": true, "path": "'.$outputPath.'/'.$phantomOut[0].'"}';            
        } else {
            echo '{"success": false, "msg": "There was some problem creating the file"}';
        }
    } else {
        echo '{"success": false, "msg": "Error in request data."}'; 
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:31:40+00:00Added an answer on June 16, 2026 at 4:31 am

    There are plenty of options in .NET to achieve what you are trying to do.

    If you have no experience in .NET whatsoever I would suggest you doing a tutorial to get you started. Is quite simple to develop a web application in C# .NET. Just google ASP.NET C# Tutorial.
    After you get your first web application done in .NET and want to use a library to transform HTML to PDF, you can check this post you will find several options.

    Just to help you out more, the first thing I suggest you to do is to Download a free version of Visual Studio if you don’t already have it installed. Visual Studio is a complete IDE and you will not need a server while you are developing because it comes with its own webserver, so when you write some code you just click the Run button and it will be executed.

    Finally, when you get your application developed you can however publish it on a Linux Server using Mono Project which I do not recommend. Or you can install it in a Windows server (whatever version you have) and the Web Server in microsoft is called IIS, so instead of Apache you will use IIS, is also really simple to configure.

    Hope this helps you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a written a script in PHP that reads from data from a
I have written a php script that generates a list of links that match
Starting out with php, I have written a basic authentication script which prints out
I have written a PHP script that checks whether a domain is available for
I have written a php script that returns an arbitrary number of specific ids
Possible Duplicate: Php.Advance weekly calendar one week I have written a script that displays
I have a script, written in PHP that uses the AWS Dynamo PHP API.
I have written a script image.php that is quite long, but I've just copied
I have written a PHP script that I use for authentication with e-mail and
I have written a PHP script that I would like to use on several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.