0

I am creating an application to convert HTML Pages to an ePub format. I tried converting the file to PDF Since I require Table Of Contents as the first page of the ePub file. I have used Spire PDF and Spire DOC for this purpose. To convert to ePub, I referred many sites and found that we cannot directly convert it to ePub. so I tried converting to doc and then from doc to ePub. Here is the code.

PDF to Word

public void WordCreation()
{
    PdfDocument pdfdoc = new PdfDocument();
    pdfdoc.LoadFromFile(@"D:\DocFilesConvert\Pdffiles\Merge.pdf");
    pdfdoc.SaveToFile(@"D:\DocFilesConvert\DocFiles\FinalMerge.docx", Spire.Pdf.FileFormat.DOCX);
}

Word to ePub

public void GetEpub()
{
    Spire.Doc.Document document = new Spire.Doc.Document();
    document.LoadFromFile(@"D:\DocFilesConvert\DocFiles\FinalMerge.docx");
    document.SaveToFile(@"D:\DocFilesConvert\EPubFiles\Final.epub", Spire.Doc.FileFormat.EPub);
    System.Diagnostics.Process.Start(@"D:\DocFilesConvert\EPubFiles\Final.epub");
}

But I am not getting Table of Contents to be Clickable and also I am not getting the desired format. Is there any direct way to convert to ePub directly from PDF?

icebat
  • 4,696
  • 4
  • 22
  • 36
Shubashree Ravi
  • 261
  • 1
  • 16
  • What is it now? Title says PDF=>ePub, first line says "HTML=>ePub" then you throw in Word=>ePub ? – Fildor Feb 22 '18 at 12:27
  • Maybe you should check that Spire documentation, that is a propietary api downloable thu nuget. https://www.e-iceblue.com/Introduce/pdf-for-net-introduce.html#.Wo63kK7iaHt – Cleptus Feb 22 '18 at 12:30
  • Checked in that also. There is only option to convert word to ePub @bradbury9 – Shubashree Ravi Feb 22 '18 at 12:33
  • 3
    Reading again: You have HTML. HTML is a markup format, so you should be able to _easily_ create a transformation that produces a TOC html from the header tags. Then you have all you need to fill an ePub container with life ... no pdf needed, no word needed. – Fildor Feb 22 '18 at 12:34
  • I need to convert HTML to ePub only with table of contents. @Fildor – Shubashree Ravi Feb 22 '18 at 12:34
  • As I wrote: Have a look at the ePub format. You should be able to create all needed files from the HTML you already have without secondary conversions like html=>pdf or html=>word. – Fildor Feb 22 '18 at 12:38
  • ok. I have got an idea from this. Thank you – Shubashree Ravi Feb 22 '18 at 12:39
  • You can add clickable TOC on Calibre it's manual work but very easy. – Shahinur Alam DXer Jul 08 '19 at 14:41

1 Answers1

-2

You can use Aspose.PDF for PDF to EPUB conversion, without installing any third party editor.

Aspose.PDF Cloud SDK for .NET - REST API Solution:

// Get AppKey and AppSID from https://dashboard.aspose.cloud/
PdfApi pdfApi = new PdfApi("xxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx");
string fileName = "README.pdf";
pdfApi.UploadFile("README.pdf", System.IO.File.OpenRead(@"C:\\Temp\\" + fileName));
string resFileName = "README.epub";
//Save resultant file to storage
//var response = pdfApi.PutPdfInStorageToEpub(fileName, resFileName);
//Get resultant file in response(as stream)
var response = pdfApi.GetPdfInStorageToPptx(fileName);
var fileStream = System.IO.File.Create("C:\\Temp\\"+resFileName);
response.CopyTo(fileStream);
fileStream.Close();

Aspose.PDF for .NET - On Premise API Solution:

// Load PDF document
Document pdfDocument = new Document(dataDir + "PDFToEPUB.pdf");
// Instantiate Epub Save options
EpubSaveOptions options = new EpubSaveOptions();          
// Save the ePUB document
pdfDocument.Save(dataDir + "PDFToEPUB_out.epub", options);

I'm developer evangelist at Aspose.

Tilal Ahmad
  • 940
  • 5
  • 9
  • This is a third party paid tool. How can you say "without installing any third party editor" ? – Leandro Bardelli Aug 15 '22 at 18:16
  • @LeandroBardelli sorry for the confusion. Yes it is paid tool but it offers 150 monthly free API calls. And about third party editor, it means it has no dependency on some other PDF editor like Adobe Acrobat etc., while processing the documents. – Tilal Ahmad Aug 18 '22 at 05:03