I am creating a pdf from HTML using Rotativa, and my code looks like this
var CustomSwitches = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";
var rotativaOptions = new DriverOptions { CustomSwitches = CustomSwitches,PageSize = Size.A4};
return new ViewAsPdf("~/Views/Partials/Report/SummaryReportspdf.cshtml")
{
RotativaOptions = rotativaOptions
};
All looks good to me, but when there is more than one page, page breaks even. And it looks like below image
How can I solve this issue?
I solved this problem using the latest version of wkhtmltopdf (currently version 0.12.5)
You can download it from here: https://wkhtmltopdf.org/downloads.html
Hope it helps!
Syncfusion HTML to PDF converter in C# provides an option to convert HTML to PDF without text and image split across the pages. Refer the help documentation for more information
https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#split-text
Note: I work for Syncfusion.
Related
I need to create a application which loads a html "template" file and parse them with current data values. So far no problemm but does anyone knows how to load the parsed html value into the cefsharp browser ?
I found some old topics here with an "loadHtml()" function. But this function isnt there anymore.
Thanks in advance
You need to add a using CefSharp; statement to your code to access the LoadHtml extensions methods.
chromiumWebBrowser.LoadHtml(html);
const string html = "<html><head><title>Test</title></head><body><h1>Html Encoded in URL!</h1></body></html>";
var base64EncodedHtml = Convert.ToBase64String(Encoding.UTF8.GetBytes(html));
browser.Load("data:text/html;base64," + base64EncodedHtml);
From the project wiki on github: Loading HTML/CSS/JavaScript/etc from disk/database/embedded resource/stream
One pdf is generated and I am adding link of website in some text of pdf using aspose and below code,
var link = new Aspose.Pdf.Annotations.LinkAnnotation(document.Pages[t.p], userSignRect)
{
Action = new Aspose.Pdf.Annotations.GoToURIAction(requestHostAddress.Replace("http://", "https://") + "/document-details/" + documentId)
};
Now I want to append pdf's modified date run time in hyperlink.
Example : https://document-details/documentId/ ModifiedDateofPdfRuntime
Please help me/guide me how to do that.
Edit: I do not want current modified date.
Usecase : We have generated pdf and given to user with our basic hyperlink url in pdf.(which is a happy scenario)
But if someone is altering my pdf then i won't know and pdf's url will still route to my website.
To overcome same i want to append PDF's modified date object in url which will fetch pdf info and get date.
something like this, is it possible ?
This should work.
Action = new Aspose.Pdf.Annotations.GoToURIAction(requestHostAddress
.Replace("http://", "https://") + "/document-details/" + documentId + "_" + DateTime.Now.ToString())
I guess you are looking for something like this
DateTime creation = File.GetCreationTime(#"C:\test.txt");
DateTime modification = File.GetLastWriteTime(#"C:\test.txt");
and then you can add checks to check if file is modified or not.
code is copied from here.
You need to use ModDate property from PdfFileInfo class:
using Aspose.Pdf.Facades;
//...
var fileInfo = new PdfFileInfo(dataDir + "GetFileInfo.pdf");
var modificationDate = fileInfo.ModDate;
Hope it helps. Otherwise, feel free to ask me.
Note: I am working as Developer Evangelist at Aspose.
In the DocX library available at : https://github.com/WordDocX/DocX
It is possible to add some hyperlink but i haven't found a way to add internal link.
Does anyone know how to add a link to specific paragraph or to a bookmark ?
The way I've found is:
synthesisDocument.AddHyperlink("Link",new Uri("file:///path/to/doc/file.doc#MY_BOOKMARK"));
synthesisDocument.Paragraphs[0].InsertHyperlink(h)
That way resolve your problem, but only in doc format, when you export to PDF it doesn't work.
I hope it helps
As mentioned #BookMark does work if the Uri is created with the UriKind.Relative flag:
var uri = new Uri("#" + BookMark,UriKind.Relative);
var hyperLink = doc.AddHyperlink(textToDisplay, uri );
Now to use the hyperlink on a paragraph, p:
p.InsertHyperlink(hyperLink,indexToInsertAt);
I achieved exactly the result I wanted using this in both .docx and .pdf
Hope it works for you,
Nick
I have c# dynamic aspx page after new property add I create for record brochure
http://veneristurkey.com/admin/Brochure.aspx?Admin=PropertiesBrochureA4&id=36
but I want to this convert image file I am searching on internet but all with webbrowser and windows forms. I need on page load show not css type also image file. jpg, png or tiff how i can do this. i need to see sample code..
saving aspx page into an image 2
As I mentioned in my comment, your best bet is to opt for attempting to render HTML to an image.
Here is the link for a library that will allow your to render html to an image:
http://htmlrenderer.codeplex.com/
Here is code that does exactly what you're asking:
http://amoghnatu.wordpress.com/2013/05/13/converting-html-text-to-image-using-c/
Now all you have left is to get the html, since I'm assuming you don't want this to render to the browser prior to generating this image - you should look into grabbing the rendered html from the aspx page on the server prior to returning it, and then just return the image. To render a page:
https://stackoverflow.com/a/647866/1017882
Sorted.
If you do not mind using a commandline tool you can have a look at wkhtmltopdf. The package include a wkhtmltoimage component that can be used to convert HTML to image, using
wkhtmltoimage [URL] [Image Path]
Codaxy also wrote a wkhtmltopdf c# wrapper available through the NuGet package manager. I'm not sure if the wkhtmltoimage component was included, but it should be easy enough to figure out how they wrap the wkhtml components.
i fixed my problem with screenshot machine API they are my code..
public void resimyap()
{
var procad = WS.Satiliklars.Where(v => v.ForSaleID == int.Parse(Request.QueryString["id"])).FirstOrDefault();
var imageBytes = GetBytesFromUrl("http://api.screenshotmachine.com/?key=xxxxxx&size=F&url=http://xxxxxxx.com/a4.aspx?id=" + procad.ForSaleID);
string root = Server.MapPath("~/");
// clean up the path
if (!root.EndsWith(#"\"))
root += #"\";
// make a folder to store the images in
string fileDirectory = root + #"\images\a4en\";
// create the folder if it does not exist
if (!System.IO.Directory.Exists(fileDirectory))
System.IO.Directory.CreateDirectory(fileDirectory);
WriteBytesToFile( fileDirectory + + procad.ForSaleID + ".png", imageBytes);
Yes i also try wkhtmltopdf c# wrapper but in pdf or image converting time my computer fan goin crayz. also i must upload server exe file and my hosting firm didnt support them
For a simple reciept system I need to somehow define a template document with simple formatting, fill it with data and print it on a standard windows printer. It has to work on a windows service. What technology should I best use?
EDIT:
I tried using PDF-Forms. I defined a couple of text boxes and filled them in with iTextSharp. It worked until the point where I had to print them, which is really hard, as you have to essentially use the reader executable directly.
An alternative which seems to be better integrated into .NET seems to be to use XPS. Does XPS provide a similar functionality?
Create your own receipt template using html or plain text.
Example using html:
HTML
<html>
<head>
<title>Receipt</title>
</head>
<body>
<div>The price: <%Price%></div>
<div>The time: <%Time%></div>
<div>Payment Method: <%PaymentMethod%></div>
</body>
</html>
C#
static void Main(string[] args)
{
CreateReceipt("€1.50", "09.30", "Cash");
}
private static void CreateReceipt(string price, string time, string paymentMethod)
{
string bodyFile;
string template = System.IO.Directory.GetCurrentDirectory() + "\\template.html";
using (StreamReader reader = new StreamReader(template))
{
bodyFile = reader.ReadToEnd();
bodyFile = bodyFile.Replace("<%Price%>", price);
bodyFile = bodyFile.Replace("<%Time%>", time);
bodyFile = bodyFile.Replace("<%PaymentMethod%>", paymentMethod);
}
FileStream fs = File.OpenWrite(System.IO.Directory.GetCurrentDirectory() + "\\receipt.html");
StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
writer.Write(bodyFile);
writer.Close();
}
}
Use Mustache to create HTML templates and populate them.
The .Net interfaces are very easy to use.
Once you've got the HTML, you can use a WebBrowser control - offscreen - to print.
There are various ways;
Create a text file and search and replace keywords with appropriate values. Save/Print this.
Create a html file and search and replace keywords with appropriate values. Save/Print this.
Create a PDF file with built-in fields and replace these with appropriate values. Save/Print this.
And more...
Just for an Idea if you haven't seen this, You can print HTML DIV
How do I print part of a rendered HTML page in JavaScript?
You could try ActiveReports
Link to ComponentOne
It's not for free.. but it works for printing stuff as you wish.
Just create Templates and embedd them in your code.
We endet up using the format of the EPSON TM-Intelligent series.