Reputation: 271
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?
Upvotes: 0
Views: 2424
Reputation: 939
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.
Upvotes: -2