IronPDF html query parameter - ironpdf

Does IronPDF support html query parameters, or is there an alternate method?
I've been using IronPDF to convert an html file to PDF using the following method: var pdf = ironRenderer.RenderUrlAsPdf(reportPath);
However, the html located at reportPath now requires a parameter userid. I have tried var pdf = ironRenderer.RenderUrlAsPdf(reportPath?userid=1); but that gives me the following error: CheckHtmlFilePath - File not found: .../index.html%3Fuserid=1'
I can't see any documentation in IronPdf that parameters are supported. Does anyone have any work arounds?

Instead of adding the parameter to the variable name, add it to the string. For example:
reportPath += "?userid=1";
var pdf = ironRenderer.RenderUrlAsPdf(reportPath);
Check the URL to see if there is already a parameter, and manipulate the URL string accordingly. If you posted more code I could have described more.

Related

merging two pdfs in to single and attaching in the email in apex

I have a requirement where I want to merge two pdfs in to a single pdf and attach in the attachements to the custom object in salesforce then this merged pdf is sent via email.
Here is my code snippet. Where contentPdf is one pdf and b is another pdf content which needs to be merged.
PageReference pdf = PageReference(/apex/FirstPDF?id='+ccId);
Blob contentPdf = pdf.getContent();
PageReference cadre = new PageReference('/apex/SecondPDF?id=' + ccId);
Blob b = cadre.getContentPdf();
String combinedPdf = EncodingUtil.convertToHex(contentPdf)+EncodingUtil.convertToHex(b);
Blob horodatagePdf = EncodingUtil.convertFromHex(combinedPdf);
Attachment attachment = new Attachment();
attachment.Body = horodatagePdf;
attachment.Name = String.valueOf('New pdf.pdf');
attachment.ParentId = ccId;
insert attachment;
But the problem is that it does not show the right documents merged instead it shows only one page in the final pdf saved in my machine. I have tried to use contentAsPdf() to retrieve content from pageReference but it does not work. Moreover the page is not well generated the one I get in the attachment. Or if there is any other way to do it quuickely.
I don't think you can merge PDF documents like that. It looks crazy. You can simply join text files together but anything more complex (JPEGs, PDFs...) has special structure... It's quite possible that your code works, in the sense that it generates a file which size is a sum of single files' sizes but it's not a valid document so only 1st part renders OK.
Try making another page which would just reuse the other 2 pages by calling them (use <apex:include>). Check if it renders close to what you're after (there might be style clashes for example) and if it's any good - call getContentAsPdf() on that?

How to fetch external file data like json format using angularjs service

Hi i need external file data using angular service.Here my code i want this data to json format.
Controller code:
$http.get('assets/scripts/modules/hawkColumnList.js').success (function(data){
console.log(data);
});
Services code:
hawkColumnList.js
var resourceColumns = [
/* aggregation functions */
"resource_id",
"resource_name",
"resource_details",
"resource_address",
"resource_address6",
"resource_group",
"resource_asset_criticality",
"compliance_asset",
"pulse_templates",
"class_name",
"class_type",
"eps_average",
"os_type_name",
"date_added",
"last_seen"
];
Try this
$http.get('assets/scripts/modules/hawkColumnList.js').success (function(data){
var dataJSON = JSON.parse(data.replace(/\r|\n/g, '').match(/(\[.*\])/)[1]);
console.log(dataJSON);
});
Explanation: The regular expression \[.*\] will grab everything from the string that is within square brackets, including the brackets. JSON.parse will parse that string into a JSON object (only working on standard browsers and IE>8)
Make sure that there are no syntax errors, which will result in parse errors leading to an undefined JSON object.
EDIT: Make sure that you remove the comment from the js file, because a comment inside a string is illegal with regards to JSON.parse. I edited the code above to remove line breaks first.
Check this working fiddle

Unable to translate bytes [...] at index ... from specified code page to Unicode when adding to index

I am using Newtonsoft.Json to create the JSON to update add items to an index, but I get the following error when I POST the request:
{"error":{"code":"","message":"The request is invalid.","innererror":{"message":"parameters : Unable to translate bytes [E3] at index 752 from specified code page to Unicode.\r\n","type":"","stacktrace":""}}}
I know the error occurs with some non letter characters in some of the strings in the data that I am serializing. The string data comes from SQL, so I'm guessing something is going on to do with encoding that I cannot figure out.
When I inspect the JSON string, and put it in manually construct a request with the same data in Fiddler it all works fine.
Does anyone have any idea what might be the problem, and how I can work around it?
I found my own solution after a bit more digging.
Adding "StringEscapeHandling.EscapeNonAscii" to the serialization options solves the problem:
jsonSettings = new JsonSerializerSettings
{
Formatting = Newtonsoft.Json.Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
};

Java 7: get Path of resource (as object of type Path)

I'm using the features of Java 7 to read in a file. For that purpose I need an object of type Path. In my code, I use the getResource() function to get the relative path (of type URL) to a file.
However, now I have the problem that I don't really now how to get from an object of type URL to an object of type Path easily (without having to go through castings to e.g. to URI then to File and from that to Path)?
Here an example to show you what I would like to do:
URL url = getClass().getResource("file.txt");
Path path = (new File(url.toURI())).toPath(); //is there an easier way?
List<String> list = Files.readAllLines(path, Charset.defaultCharset());
So is there an easier way to achieve that and not having to do that code mess on line 2?
How about
Path path = Paths.get(url.toURI());
It is not proper to create a File from your URL, since it's gotten from the classpath and the file may actually be within a jar.
In Scala would be
import java.nio.file.Paths
val resource = getClass.getResource("myfile.txt")
val path = Paths.get(resource.toURI)
In Java should be the same (with slightly different syntax)

How to export Rich Text fields as HTML from Notes with LotusScript?

I'm working on a data migration task, where I have to export a somewhat large Lotus Notes application into a blogging platform. My first task was to export the articles from Lotus Notes into CSV files.
I created a Agent in LotusScript to export the data into CSV files. I use a modified version of this IBM DeveloperWorks forum post. And it basically does the job. But the contents of the Rich Text field is stripped of any formatting. And this is not what I want, I want the Rich Text field rendered as HTML.
The documentation for the GetItemValue method explicitly states that the text is rendered into plain text. So I began to research for something that would retrieve the HTML. I found the NotesMIMEEntity class and some sample code in the IBM article How To Access HTML in a Rich Text Field Using LotusScript.
But for the technique described in the above article to work, the Rich Text field need to have the property "Store Contents as HTML and MIME". And this is not the case with my Lotus Notes database. I tried to set the property on the fields in question, but it didn't do the trick.
Is it possible to use the NotesMIMEEntity and set the "Store Contents as HTML and MIME" property after the content has been added, to export the field rendered as HTML?
Or what are my options for exporting the Notes database Rich Text fields as HTML?
Bonus information: I'm using IBM Lotus Domino Designer version 8.5
There is this fairly unknown command that does exactly what you want: retrieve the URL using the command OpenField.
Example that converts only the Body-field:
http://SERVER/your%5Fdatabase%5Fpath.nsf/NEW%5FVIEW/docid/Body?OpenField
Here is how I did it, using the OpenField command, see D.Bugger's post above
Function GetHtmlFromField(doc As NotesDocument, fieldname As String) As String
Dim obj
Set obj = CreateObject("Microsoft.XMLHTTP")
obj.open "GET", "http://www.mydomain.dk/database.nsf/0/" + doc.Universalid + "/" + fieldname + "?openfield&charset=utf-8", False, "", ""
obj.send("")
Dim html As String
html = Trim$(obj.responseText)
GetHtmlFromField = html
End Function
I'd suggest looking at Midas' Rich Text LSX (http://www.geniisoft.com/showcase.nsf/MidasLSX)
I haven't used the personally, but I remember them from years ago being the best option for working with Rich Text. I'd bet it saves you a lot of headaches.
As for the NotesMIMEEntity class, I don't believe there is a way to convert RichText to MIME, only MIME to RichText (or retain the MIME within the document for emailing purposes).
If you upgrade to Notes Domino 8.5.1 then you can use the new ConvertToMIME method of the NotesDocument class. See the docs. This should do what you want.
Alternativly the easiest way to get the Domino server to render the RichText will be to actually retrieve it via a url call. Set up a simple form that just has the RichText field and then use your favourite HTTP api to pull in the page. It should then be pretty straight forward to pull out the body.
Keep it simple.
Change the BODY field to Store contents as HTML and MIME
Open the doc in editmode.
Save.
Close.
You can now use the NotesMIMEEntity to get what you need from script.
You can use the NotesDXLExporter class to export the Rich Text and use an XSLT to transform the output to what you need.
I know you mentioned using LotusScript, but if you don't mind writing a small Java agent (in the Notes client), this can be done fairly easily - and there is no need to modify the existing form design.
The basic idea is to have your Java code open a particular document through a localhost http request (which is simple in Java) and to have your code capture that html output and save it back to that document. You basically allow the Domino rendering engine to do the heavy lifting.
You would want do this:
Create a form which contains only the rich-text field you want to convert, and with Content Type of HTML
Create a view with a selection formula for all of the documents you want to convert, and with a form formula which computes to the new form
Create the Java agent which just walks your view, and for each document gets its docid, opens a URL in the form http://SERVER/your_database_path.nsf/NEW_VIEW/docid?openDocument, grabs the http response and saves it.
I put up some sample code in a similar SO post here:
How to convert text and rich text fields in a document to html using lotusscript?
Works in Domino 10 (have not tested with 9)
HTMLStrings$ = NotesRichTextItem .Converttohtml([options] ) As String
See documentation :
https://help.hcltechsw.com/dom_designer/10.0.1/basic/H_CONVERTOHTML_METHOD_NOTESRICHTEXTITEM.html
UPDATE (2022)
HCL no longer support this method since version 11. The documentation does not include any info about the method.
I have made some tests and it still works in v12 but HCL recommended to not use it.
Casper's recommendation above works well, but make sure the ACL is such to allow Anonymous Access otherwise your HTML will be the HTML from your login form
If you do not need to get the Richtext from the items specifically, you can use ?OpenDocument, which is documented (at least) here: https://www.ibm.com/developerworks/lotus/library/ls-Domino_URL_cheat_sheet/
https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_ABOUT_URL_COMMANDS_FOR_OPENING_DOCUMENTS_BY_KEY.html
OpenDocument also allows you to expand sections (I am unsure if OpenField does)
Syntax is:
http://Host/Database/View/DocumentUniversalID?OpenDocument
But be sure to include the charset parameter as well - Japanese documents were unreadable without specifying utf-8 as the charset.
Here is the method I use that takes a NotesDocument and returns the HTML for the doc as a string.
private string ConvertDocumentToHml(Domino.NotesDocument doc, string sectionList = null)
{
var server = doc.ParentDatabase.Server.Split('/')[0];
var dbPath = doc.ParentDatabase.FilePath;
string viewName = "0";
string documentId = doc.UniversalID.ToUpper();
var ub = new UriBuilder();
ub.Host = server;
ub.Path = dbPath.Replace("\\", "/") + "/" + viewName + "/" + documentId;
if (string.IsNullOrEmpty(sectionList))
{
ub.Query = "OpenDocument&charset=utf-8";
}
else
{
ub.Query = "OpenDocument&charset=utf-8&ExpandSection=" + sectionList;
}
var url = ub.ToString();
var req = HttpWebRequest.CreateHttp(url);
try
{
var resp = req.GetResponse();
string respText = null;
using (var sr = new StreamReader(resp.GetResponseStream()))
{
respText = sr.ReadToEnd();
}
return respText;
}
catch (WebException ex)
{
return "";
}
}

Resources