html image to pdf (images not showing) - selectpdf - html

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"

Related

Send RDLC in Email as Body

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.

Flying Saucer - Open an attachment from pdf link

I would like to know if there is a way to create a link (Using HTML) to open an attachment embedded in the pdf document.
Something like this...
Open the attachment file or Open the attachment file
Any suggestion or recommendation?
Thanks
I have been able to implement this scenario after reading the next useful post
https://groups.google.com/forum/#!topic/flying-saucer-users/KuwPoTjaQYU
Steps:
Check out the next repository https://github.com/osnard/flyingsaucer
Analyse the file ITextOutputDevice.java, method processLink(RenderingContext c, Box box)
Make changes based on your needs
Build the project and use the jar file generated
Here the code to create an embedded file based on base64 content.
Java
...String doEmbedFile = handler.getAttributeValue( elem, "data-fs-embed-file" );
if ("true".equals(doEmbedFile.toLowerCase())) {
String fileName = new File(uri).getName();
String content = handler.getAttributeValue( elem, "content" );
com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
if (targetArea == null) {
return;
}
try {
if (!_attachments.contains(fileName)) {
byte[] fileBytes = Base64.getDecoder().decode(content.getBytes("UTF-8"));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(_writer, null, fileName, fileBytes);
fs.addDescription(fileName, true);
_writer.addFileAttachment(fs);
_attachments.add(fileName);
}
targetArea.setBorder(0);
targetArea.setBorderWidth(0);
//This only works on Adobe Acrobat Reader
PdfAction action = PdfAction.javaScript(
"this.exportDataObject({cName:\"" + fileName + "\", nLaunch:2});",
_writer
);...
HTML
<body><div id='div1'><p><a href='test.png' data-fs-embed-file='true' content='iVBORw0KGgoAAAANSUhEU...'>open test.png file</a></p></div><div id='div2'><p><a href='test.pdf' data-fs-embed-file='true' content='JVBERi0xLjUNCiW1tbW1D...'>open test.pdf file</a></p></div><div id='div3'><p><a href='test.txt' data-fs-embed-file='true' content='VEVFRUVFRUVFRVNUIFRYVA=='>open test.txt file</a></p></div></body>
*base64 content truncated
Output
Greetings and I hope it can help others
just open it on new tab, add attribute target="_blank" in your anchor tag
Open attachment

Convert xlsx file to HTML with VBscript or batch script

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();
}
}
}

HTML from Database to PDF

I need to generate pdf from html dynamically using asp.net. HTML is stored in database. HTML has tables and css, upto 10 pages. I have tried iTextSharp by directly passing html, it produces pdf which is not opening. Destination pdf.codeplex.com has no documentation, it produces PDF with styles from parent page.
Any other solution will be helpful.
I've tried many HTML to PDF solutions including iTextSharp, wkhtmltopdf and ABCpdf (paid)
I'm currently settled on PhantomJS a headless, open-source, WebKit-based browser. It is scriptable with a javascript API which is reasonably well documented.
The only disadvantage I found was that attempting to use stdin to pass HTML into the process was unsuccessful because the REPL still has some bugs. I also found that using stdout seemed to be a lot slower than simply allowing the process to write to disk.
The code below avoids stdin and stdout by creating the javascript input as a temp file, executing PhantomJS, copying the output file to a MemoryStream and cleaning up the temporary files at the end.
using System.IO;
using System.Drawing;
using System.Diagnostics;
public Stream HTMLtoPDF (string html, Size pageSize) {
string path = "C:\\dev\\";
string inputFileName = "tmp.js";
string outputFileName = "tmp.pdf";
StringBuilder input = new StringBuilder();
input.Append("var page = require('webpage').create();");
input.Append(String.Format("page.viewportSize = {{ width: {0}, height: {1} }};", pageSize.Width, pageSize.Height));
input.Append("page.paperSize = { format: 'Letter', orientation: 'portrait', margin: '1cm' };");
input.Append("page.onLoadFinished = function() {");
input.Append(String.Format("page.render('{0}');", outputFileName));
input.Append("phantom.exit();");
input.Append("};");
// html is being passed into a string literal so make sure any double quotes are properly escaped
input.Append("page.content = \"" + html.Replace("\"", "\\\"") + "\";");
File.WriteAllText(path + inputFileName, input.ToString());
Process p;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = path + "phantomjs.exe";
psi.Arguments = inputFileName;
psi.WorkingDirectory = Path.GetDirectoryName(psi.FileName);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
p = Process.Start(psi);
p.WaitForExit(10000);
Stream strOut = new MemoryStream();
Stream fileStream = File.OpenRead(path + outputFileName);
fileStream.CopyTo(strOut);
fileStream.Close();
strOut.Position = 0;
File.Delete(path + inputFileName);
File.Delete(path + outputFileName);
return strOut;
}

IText html to pdf img

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);