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
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
I want to add a header and a footer, which becomes repeated, to my PDF which becomes created by iText7 by converting the HTML.
However, all examples I found so far on the internet describes how to create a blank PDF by code with header and footer.
Does anybody know how I can achive this? I already tried to use the CSS print media queries to specify some areas but it seems those are ignored by iText7.
The conversion is really simple:
string input = "Bestellung.html";
string output = "Bestellung.pdf";
HtmlConverter.ConvertToPdf(new FileInfo(input), new FileInfo(output));
bestellung.html is just a plain HTML file with some demo content.
See mediaDeviceDescription under ConverterProperties.
If your input file uses this feature, then you can simply tell pdfHTML
to interpret the relevant set of rules:
ConverterProperties props = new ConverterProperties();
props.setMediaDeviceDescription(new
MediaDeviceDescription(MediaType.PRINT));
Then you call the method with this signature:
static void convertToPdf(InputStream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties)
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.
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.
I'm trying to extract image from *.doc file without using of Microsoft.Office.Interop.Word. I found library like FreeSpire.Doc, but It seems the free version of library isn't able to extract images. Can someone help me with this problem?
[Attached *.doc file with the image I need][1]
[1]: https://mega.nz/#!5nITyQzT!aesEA0akirlpKSEEDceNDjifOAFKlNZSmgTwfhFm36M
Thank you
The only library i found which can extract Images from .doc Document is Aspose. There is an example in their documentation how you can Export Images.
I ended up with this solution. I found a library named GemBox.Document. Unluckily this library is free only for documents containing up to 20 paragraphs. So I had to remove extra paragraphs and then I used this code to get first picture in document.
public void CreateSubnestImageFromNestingReport(string picturePath,string docPath)
{
var fileDir = Path.GetDirectoryName(picturePath);
Directory.CreateDirectory(fileDir);
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var document = DocumentModel.Load(docPath, LoadOptions.DocDefault);
var pict = document.GetChildElements(true).Single(el => el.ElementType == ElementType.Picture) as Picture;
File.WriteAllBytes(picturePath, pict.PictureStream.ToArray());
}