i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pdf to html conversion in asp.net c#
12-23-2012, 02:02 PM
Post: #1
pdf to html conversion in asp.net c#
I created a sample web application to convert any given pdf document to html file. I used pdftohtml utility to perform this action. The positive thing about this utility is that it extract the pdf text and save into newly create html file without writing any extra code.

This utility required following command to execute to Convert the URL into PDF file.
Code:
pdftohtml file.pdf

here is some documentation about pdftohtml
to upload the pdf file to executable directory (the text file will also save on same location)
Code:
private void Upload_PDF_File(string filename)
    {
        FU_Pdf.PostedFile.SaveAs(GetFilePath() +"\\"+ filename.Trim());
    }

to create the above mentioned command, i wrote a method Construct_Command(...)
Code:
private void Construct_Command(string PDFPath)
    {
        string str_Command = string.Empty;
        string PDF_Server_Path = GetFilePath() + "\\" + PDFPath;
        str_Command = "pdftohtml " + PDF_Server_Path;

        //Execute command on pdftohtml
        Execute_Command(str_Command);
        GenerateHyperLink(PDFPath.Replace(".pdf", ".html"));
    }

To execute the above command on executable file, i wrote following method.
Code:
public void Execute_Command(string str_Command)
    {
        try
        {
            ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + GetFilePath() + "\\" + str_Command);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            Process proc = new Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            proc.WaitForExit();
        }
        catch (Exception objException)
        {
            // Log the exception
        }
    }

Live Demo:
http://converter.dotnetauthor.com/index....f-to-html/

the complete code is attached. please feel free to ask questions.




Attached File(s)
.zip  PDF_To_Html.zip (Size: 251.52 KB / Downloads: 234)

[Image: 2604595733.png]
Quote
04-01-2013, 12:42 PM
Post: #2
RE: pdf to html conversion in asp.net c#
html file is not created. when i click on "view html file", it says "no resource found".
Quote
04-01-2013, 07:51 PM
Post: #3
RE: pdf to html conversion in asp.net c#
I tested this code many times, but how did you test it? this problem usually occur when due to restriction, you can not able to execute commands on executable file. this also happened to me when i am uploading it. after giving proper rights to folder and executable file. the problem solved.

[Image: 2604595733.png]
Quote
09-20-2013, 03:55 AM
Post: #4
RE: pdf to html conversion in asp.net c#
I also get same error..file .html not found..how to solve the problem and what my mistake? when I check in the Executable folder the .pdf file was not convert to .html..I not change any code just download and test..and copy to my localhost and run it..
Quote
09-20-2013, 06:22 AM
Post: #5
RE: pdf to html conversion in asp.net c#
@Syafiq: Are you logged in as an Administrator? it could be due to some restriction and you may not allow to use executable file, the second problem could be because you may running it on C Drive, I already experienced such issue in Windows 8, I was unable to create Html File in C Drive, so If you have administrative rights then run the application from other drive. Or if you have any issue, please attach the screenshot as well.
Thanks

[Image: 2604595733.png]
Quote
09-20-2013, 08:27 AM
Post: #6
RE: pdf to html conversion in asp.net c#
Sorry..this code is working..have a technical problem..thank you for nice sharing Big Grin
Quote
12-16-2013, 07:16 AM
Post: #7
RE: pdf to html conversion in asp.net c#
There is another C#/.NET Library using which you can convert PDF to HTML and vice versa known as Aspoe.PDF for .NET Library. Try it, i hope you will like it too:

http://www.aspose.com/.net/pdf-component.aspx
Quote
04-06-2015, 03:03 PM
Post: #8
RE: pdf to html conversion in asp.net c#
Hi,

Thanks for this great post. I actually want to know what is this .exe file? Will it work for every pdf file on godaddy server too?

Also, html is not exactly with same format as the pdf itself. How can we convert with same format.

Thanks,
Kuldeep
Quote
04-10-2015, 06:02 AM
Post: #9
RE: pdf to html conversion in asp.net c#
@aravsoft: actually only few shred web hosting allow to execute command directly with executable file. if godaddy is not support the exe the request him for that specific executable file to run with permission, secondly it works with most of pdf files. but did not try with different kind of pdf generated by different tools.

[Image: 2604595733.png]
Quote
04-12-2016, 12:21 PM
Post: #10
RE: pdf to html conversion in asp.net c#
(04-06-2015 03:03 PM)aravsoft Wrote:  Hi,

Thanks for this great post. I actually want to know what is this .exe file? Will it work for every pdf file on godaddy server too?

Also, html is not exactly with same format as the pdf itself. How can we convert with same format.

Thanks,
Kuldeep
To fully preserve PDF formatting after conversion to HTML, you may try this tool: http://www.print2flash.com After several month's using I never met with a situation at which the generated HTML differed from an original PDF. To use it from C#, you need to use a print2flash SDK available at this download page: http://print2flash.com/download.php
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Html to pdf conversion in c# nisar87 13 43,198 09-06-2016 10:30 AM
Last Post: evopdf
  pdf to image conversion in asp.net c# nisar87 10 32,600 11-10-2015 02:01 AM
Last Post: dasccca
  Html to Xhtml conversion in c# nisar87 1 5,716 05-17-2015 11:38 PM
Last Post: raju
  PDF to Image Conversion in ASP.NET magnum_2007 7 11,070 07-25-2014 09:13 AM
Last Post: alxe_2014
  Html to Pdf conversion in asp.net c# nisar87 7 56,835 06-17-2014 06:31 AM
Last Post: dev_chirs



User(s) browsing this thread: 1 Guest(s)