Itext not supporting bookmarks in pdf - itext

iText5 does not support inline bookmark href when pdf is generated from HTML
content. However, it is working for external links.
Is there any way we can handle inline links to other pages in the same pdf while generating pdf from HTML content?
<a href='#last'>Last div content</a> <!--Not working in pdf-->
<br />
<a href='https://www.google.com'>External link</a> <!--working in pdf-->
<br />
<div id="last">last content</div>

iText 5 XMLWorker is clearly marked as deprecated on their product page.
The best alternative would be to switch to iText7 + pdfHTML
public void createPdf(String html, String dest) throws IOException {
HtmlConverter.convertToPdf(html, new FileOutputStream(dest));
}

Related

Image url inside an email template changes and the image does not show properly [duplicate]

This question already has answers here:
Gmail's new image caching is breaking image links in newsletter
(15 answers)
Closed 3 years ago.
I have created the following email template and send email to clients from my website (ASP.NET MVC, C#) using SendGrid. Note that there is an envelope icon at the end of the email.
<!DOCTYPE html>
<html>
<head></head>
<body>
<p>Some email content</p>
<hr/>
<p>reply info: </p>
<p>
<img src='https://prod-shopless-cdn.s3-ap-southeast-2.amazonaws.com/icons/email-icon.svg' alt='email' height='20' style='vertical-align: middle; padding-right: 5px;'>
<a rel='nofollow' ymailto='mailto:john#some-domain.com' href='mailto:john#some-domain.com'>john#some-domain.com</a>
</p>
</body>
</html>
When I send the email to a yahoo address, I see the following is prepended to the image url: https://ecp.yusercontent.com/mail? but the image still shows fine:
<p>
<img src="https://ecp.yusercontent.com/mail?url=https%3A%2F%2Fprod-shopless-cdn.s3-ap-southeast-2.amazonaws.com%2Ficons%2Femail-icon.svg&t=1577343946&ymreqid=eab30077-9a08-b7e9-1c70-820001015100&sig=idgsn8ycGFqhWibk5cnXTQ--~C" alt="email" height="20" style="vertical-align:middle;padding-right:5px;">
<a rel="nofollow" ymailto="mailto:john#some-domain.com" target="_blank" href="mailto:john#some-domain.com">john#some-domain.com</a>
</p>
When I send the email to a Gmail account, I see the following is prepended to the image url: https://ci5.googleusercontent.com/proxy/fMePoJvSwECei02DF_cx9SKczcRDRDa9XeJs263AGBRUysoCNxeZhErF834cSHBLcBGkDR-JWdfqhZkW878P9A3gM7nh8dRfdNxjVpBrGiNBBJCoRnNmBrkSAoF-TBu3IQ=s0-d-e1-ft# and the image no longer shows.
<p>
<img src="https://ci5.googleusercontent.com/proxy/fMePoJvSwECei02DF_cx9SKczcRDRDa9XeJs263AGBRUysoCNxeZhErF834cSHBLcBGkDR-JWdfqhZkW878P9A3gM7nh8dRfdNxjVpBrGiNBBJCoRnNmBrkSAoF-TBu3IQ=s0-d-e1-ft#https://prod-shopless-cdn.s3-ap-southeast-2.amazonaws.com/icons/email-icon.svg"
alt="email" height="20" style="vertical-align:middle;padding-right:5px" class="CToWUd">
<a rel="nofollow" href="mailto:john#some-domain.com" target="_blank">john#some-domain.com</a>
</p>
How can I resolve this issue?
The change of image URL on both Yahoo and Gmail is because they use their image caching, more info about Gmail Image Proxy
I found the answer to my problem here, it appears that Google Image Proxy works with standard image types (.jpg, .png and .gif)... my image type was .svg, I changed the template to use .png and it works fine now.

clientlibs.min.js: Uncaught TypeError: $(...).autocomplete is not a function

Created a simple search component in AEM and added following code in its JSP.
Also added autocomplete plugin and jquery plyugin file in clientlib node. But getting error "autocomplete is not a function" every time I try to run the page with this component. Is it not compatible to be used with AEM?
Using AEM 6.0 SP2
<% #include file="/libs/foundation/global.jsp"%>
<cq:includeClientLib categories="jquerysamples" />
<html>
<head>
<script>
$(function() {
var availableTutorials = [
"ActionScript",
"Boostrap",
"C",
"C++",
];
$( "#searchInput" ).autocomplete({
source: availableTutorials
});
});
</script>
</head>
<body>
<div class="formDiv">
<form id="form" >
<input type="text" id="searchInput" name="searchbox">
<div id="searchResults"/>
</form>
</div>
</body>
</html>
I recommend understanding how browsers parse HTML documents. http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/#HTML_Parser is an introductory resource.
You have a JS script tag inside the head of your document. (this is immediate parse & execute)
there is a cq:includeClientLib outside of the document. I don't believe HTML5 behavior defines how this should behave.
no jQuery document onLoad is defined, so the browser attempts to run JavaScript before any DOM has been built.
I recommend:
Try moving the cq:includeClientLib inside the head.
Use the HTML5 doctype <!doctype html>. This should "kick" browsers into a consistent parsing mode (especially avoiding IE's myriad of quirks modes).
Move your script block to just inside the end of by body. Even better, wrap the JS with an onload handler to cause the JS to run AFTER the HTML has been parsed & the DOM has been built.
I got the solution. It was not binding the jquery-ui plugin. I added dependency of "cq:includeClientLib" for plugin folder to the js file I was using for autocomplete. It is working like a charm now.

Is it possible to use google webfonts in a MailChimp template?

I've been trying to incorporate google webfonts in MailChimp and can't get any solutions to work.
I've tried the approach listed on Campaign Monitor's site using #import:
http://www.campaignmonitor.com/blog/post/3897/using-web-fonts-in-email
but I get this error when trying to preview:
An error occurred parsing your template CSS:
Cannot find a CSS file at: http://fonts.googleapis.com/css?family=Montserrat
Has anyone been able to use custom fonts within MailChimp?
It turns out it's not possible through the #import syntax. It does work using tag:
<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
I use custom fonts in all of my emails but not through google. If your having trouble using Google's webfonts I recommend you host the file on your own server and try to use that instead.
For me, I import my webfonts stylesheet like so:
#import url('https://www.mydomain.com/en/img/cms/mail/_a/fonts/fonts.css');
I also add a conditional-comments below my style declarations to enhance webfont fallbacks in outlook. Without this, Outlook will likely substitute your webfont for whatever it feels like, and not respect your fallback font. But if you declare this conditional comment and then wrap your text with an additional span with the class, Outlook will respect your fallback and use the font you decide.
<!--[if gte mso 9]>
<style>
.flowerpwr { font-family:Arial,sans-serif; }
.proxima { font-family:Arial,sans-serif;font-weight:normal; }
.proxima_novasemibold { font-family:Arial,sans-serif;font-weight:normal; }
</style>
<![endif]-->
The html markup looks like this:
<td align="center" style="font-family:'proxima_novaregular',Arial,sans-serif;font-size:16px;letter-spacing:0.04em;color:#333333;">
<span class="proxima">Text here</span>
</td>
This even works for styling image alt text like so:
<td>
<a href="https://www.mylink.com/" target="_blank" style="display:block;font-family:'proxima_novaregular',Arial,sans-serif;color:#666666;font-size:16px;text-align:center;letter-spacing:0.04em;text-decoration:none;outline:none;">
<span class="proxima">
<img src="a3.jpg" alt="STYLED ALT TEXT WITH WEBFONT AND OUTLOOK MAINTAINED FALLBACK" border="0" style="display:block;">
</span>
</a>
</td>
I have been building emails a lot using mailchimp recently and I had been scratching my head over this for a while. These are my findings:
works for google fonts.
#import works for fonts hosted through other sites then google (for ex. your personal site)
using something like:
<link href='http://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
using #import for google fonts gives you an error in mailchimp (like the one horizens posted).
base64 works as well. But the code can get way to long and cause other problems.
Firefox blocks the fonts in Mailchimp preview (because it's https).
PS: different but related topic: Making responsive emails is not as terrible as the people of the internet claim.

Is there a way to render Partial Views in WebForms?

I'm touching an old WebForms project but I'm long gone from it and I'm now to used to MVC. I'm trying to refractor the project and come up with a simple issue that is making me crazy...
What would be the best way to include an .aspx file within another?
I don't want to end up having a lot of Master Files just for this, all I'm after is something like #Html.RenderPartial("MyFileName") kind'a thingy or
it's that hard to include a file in some existing files?
Use UserControl Tutorial on UserControl. They are files with .ascx extension and you can include them in your pages
//UserControl1.ascx
<% # Control Language="C#" ClassName="UserControl1" %>
<div>
My Custom Control: I can use any Server controls, html tags etc
</div>
Include it in your .aspx page
<%# Page Language="C#" %>
<%# Register TagPrefix="uc" TagName="MyCustomControl" Src="~/Controls/UserControl1.ascx" %>
<html>
<body>
<form runat="server">
<uc:MyCustomControl id="MyPartialView"
runat="server" />
</form>
</body>

multiple HTML in Phonegap applications

Can we have multiple HTML files in Phonegap application?
Yes, you can. Here's an example from their git repo:
http://github.com/phonegap/phonegap-iphone/blob/master/PhoneGapTutorial/www/index.html
<a href="geolocation.html">
<div class="item">
<h2>GeoLocation</h2>
</div>
</a>
Definitely. Just link to it from your html (anchor tag), and the html file should be in your www folder. Don't forget to add "phonegap.js" in a script tag like your index.html file if you want to access Phonegap functions.