I Already Digging for 5 hours but nothing to found. Is there any way to generate the rdlc into HTML. I tried RDLC to Image but my problem is, the generated image is slice in half.
Finally found solution(even though is not best answer). So basically, convert first to Excel then convert the excel into html then read all the text. I use the FreeSprite.XLS to convert the excel into html.
Freespire.xls Link
here is my code
private string GenerateHTMLReport(ReportViewer rv)
{
string mimeType,
encoding,
fileNameExtension;
Warning[] warnings=null;
string[] streamIds=null;
//Export report
byte[] exportBytes = rv.LocalReport.Render("Excel", null, out mimeType, out encoding,
out fileNameExtension, out streamIds, out warnings);
//convert to excel
FileStream fs = new FileStream("report.xls", FileMode.Create);
fs.Write(exportBytes, 0, exportBytes.Length);
fs.Close();
Workbook workbook = new Workbook();
workbook.LoadFromFile("report.xls");
//convert Excel to HTML
Worksheet sheet = workbook.Worksheets[0];
sheet.SaveToHtml("report.html");
string html =System.IO.File.ReadAllText("report.html");
return "";
}
generated HTML Code.
generated HTML in Preview.
Hopefully someone will found it helpful.
Related
I am creating pdf files from generated html file by using PdfSelect, the problem is that images are not show on the pdf but is generated on the html.
Dim converter As New HtmlToPdf()
' set converter options
converter.Options.PdfPageSize = PdfPageSize.A4
converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait
' create a new pdf document converting an url
Dim doc As SelectPdf.PdfDocument = converter.ConvertUrl(htmlFilePath)
' get image path
Dim imgFile As String = "C:\Users\Stefan\Desktop\Acczone General\statements\leda.jpg"
' save pdf document
doc.Save(pdfFilePath)
' close pdf document
doc.Close()
I tried some coding but it does not work, can someone please help me so that the images show on the pdf?
My html works 100% it is just the pdf, i am using SelectPdf
Use this format:
Dim imgFile As String = "file:///C:\Users\Stefan\Desktop\Acczone General\statements\leda.jpg"
The code below is generating the HTML report fine on a new browser window, but it is writing the HTML file on the app server. Is there a way to generate an HTML report in Jasper without having to write the HTML file to the app server?
I can do it in PDF using JasperRunManager.runReportToPdfStream(), but there's no such method for HTML. Any ideas?
//For HTML file
String reportPath = JasperRunManager.runReportToHtmlFile(sourceFileName, parameters, conn);
File reportHtmlFile = new File(reportPath);
FileInputStream fis = new FileInputStream(reportHtmlFile);
byte[] bytes = new byte[(int)reportHtmlFile.length()];
fis.read(bytes);
response.setHeader("Content-Disposition","inline; ");
response.setContentType("text/html");
response.setContentLength(bytes.length);
servletOutputStream.write(bytes, 0, bytes.length);
servletOutputStream.flush();
servletOutputStream.close();
I've researched for days but I can not find anything to resolve this issue that I am having.
I have an excel file in .xlsx format that is updated through out the day. What I need to do is call a batch that converts it to .html. I will be taking that HTML file and copying it to a folder that automatically publishes it for internal uses at my company.
If anyone out there can help it would be greatly appreciated.
Excel lets you save as a web page natively. It also has a "single file" web page that combines all images/etc into a single file. It uses the mht or mhtml extension.
Const xlHtml = 44
Const xlWebArchive = 45
' Create an instance of Excel and open the workbook...
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "C:\Folder\MyWorkbook.xlsx"
' Save the workbook as an HTML or MHTML page...
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.html", xlHtml
' -or-
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.mhtml", xlWebArchive
' Close Excel...
objExcel.Quit
If Some one looking for C#
Add Reference -> COM -> Look for Microsoft Excel, Microsoft Office then
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelToSinglePageWeb
{
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(#"C:\Users\name\Desktop\Work In Progress.xlsx");
xlWorkbook.SaveAs(#"C:\Users\name\Desktop\SomePage.mhtml", 45);
xlApp.Quit();
}
}
}
I am converting a html document to a pdf document and send it with java mail.
I want to insert an image on the top of the pdf document with:
<img alt="Logo" class="logo" src="https://www.somesite.org/images/logo.png"/>
But it isnt shown in the pdf document.
The link is working correctly, i tried it in my browser.
When i put in a absolute path to the image on my server he finds the path, but the email programm doesnt have access to our server of course, except of the link i want to use...
Isnt it possible to use such links?
EDIT:
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setValidating(false);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
builder.setEntityResolver(FSEntityResolver.instance());
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
String filename = wrapper.GetHtmlFilename(this.getClass().getName());
String html = wrapper.GetHtmlFile(filename, "UTF-8");
String result = wrapper.GetBody(html);
document = builder.parse(new ByteArrayInputStream(result.getBytes("UTF-8")), "UTF-8");
baos = new ByteArrayOutputStream();
renderer = new ITextRenderer();
renderer.setDocument(document, null);
renderer.layout();
renderer.createPDF(baos);
I'm trying to create a "report" by generating a PDF based on HTML.
At first, I simply attempted to write raw encoded HTML to a document and then print that document using Javascript. However, this gave me little to no control involving headers and footers.
I attempted using thead and tfoot elements, which worked reasonably well in most browsers, however I wasn't able to get the formatting that I was looking for.
Currently - I am trying to work on a server-side solution using iTextSharp in MVC3, however I am a bit lost as to how to proceed, having not worked with iTextSharp much.
Input and Description of Output:
There will be 4 items used in creating the Report:
Report Content (which is currently encoded HTML, as I am unsure if decoding will change any formatting)
Report Title (will simply be the name of the PDF generated)
Report Header (will be displayed at the upper-left of each page)
Report Footer (will be displayed at the lower-left of each page)
Controller Action:
//This will be accessed by a jQuery Post
[HttpPost]
public FileStreamResult GeneratePDF(string id)
{
//Grab Report Item
ReportClass report = reportingAgent.GetReportById(id);
Document doc = new Document();
//Do I need to decode the HTML or is it possible to use the encoded HTML?
//Adding Headers / Footers
//Best method of returning the PDF?
}
iTextSharp cannot convert HTML to PDF. It's not what it was designed to do. It was designed to create PDF files from scratch, not converting between various formats into PDF. If you want to convert HTML into PDF you could for example use the the flying-saucer library which is based on iText. I have blogged about how this could be done in .NET using IKVM.NET Bytecode Compiler (ikvmc.exe).
So your controller action might look something along the lines of:
[HttpPost]
public FileStreamResult GeneratePDF(string id)
{
ReportClass report = reportingAgent.GetReportById(id);
return PdfResult(report.Html);
}
where PdfResult could be a custom action result taking the raw HTML and outputting the PDF into the response stream:
public class PdfResult : ActionResult
{
private readonly string _html;
public PdfResult(string html)
{
_html = html;
}
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.ContentType = "application/pdf";
var builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
using (var bais = new ByteArrayInputStream(Encoding.UTF8.GetBytes(_html)))
using (var bao = new ByteArrayOutputStream())
{
var doc = builder.parse(bais);
var renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
renderer.createPDF(bao);
var buffer = bao.toByteArray();
response.OutputStream.Write(buffer, 0, buffer.Length);
}
}
}