|
Rank: Newbie Groups: Member
Joined: 2/15/2017 Posts: 2
|
Hi, What I need is something that has very high performance (around 100-300ms per document). I see that acm pdf creator has very fast performance especially compared to the html to pdf converter. However I want to retain the flexibility of being able to create my pdf templates in html i.e can I generate the document ACM content model using the html to pdf api beforehand cache that somewhere then just use cached acm model when doing my data population say within a web request?
Kind Regards, Damo
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Yes. You can do that. You would just pass the template document to the AcmRender object. For example, you will find all the ACM sample code uses a new PdfDocument object such as:
Code: C#
//Create an empty PDF document
PdfDocument doc = new PdfDocument();
//Create an ACM Render
AcmRender render = new AcmRender(doc);
You would just change it to:
Code: C#
//Load the template PDF document
PdfDocument doc = new PdfDocument(your_template_file.pdf);
//Create an ACM Render
AcmRender render = new AcmRender(doc);
Here your_template_file.pdf would the result file of a previous HTML to PDF conversion. You can also add marker elements in your HTML so that after the HTML to PDF conversion, you can use the marker elements to get the exact location/size of those elements. Such information maybe useful as to where to output your ACM objects. You would get such information through the HtmlToPdfResult object returned by the HTML to PDF converter. Hope this helps. Please feel free to let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 2/15/2017 Posts: 2
|
Thanks for the quick reply. This is awesome. Can you please also tell me how do I navigate a PdfDocument object once loaded? for example say I have a <div id="name">{name to be replaced from model}</div> once this is converted to a PdfDocment how to do I find that particular object to populate its text?
Cheers.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, You won't be able to navigate a PdfDocument once it loaded. You can only navigate the result of a HTML to PDF conversion. So for example, if you have code like this:
Code: C#
//Convert HTML to PDF
PdfDocument doc = PdfDocument();
HtmlToPdfResult result = HtmlToPdf.ConvertHtml("<div id='test'>hello</div>", doc);
//Get the location and size of the 'test' DIV
EO.Pdf.HtmlElement e = result.HTMLDocument.GetElementById("test");
EO.Pdf.PdfPageLocation location = e.Location;
System.Drawing.SizeF size = e.Size;
Since your template file and the final file is not necessary generated together, you may want to save the location and size somewhere so that you can use them when you fill in the final files. Hope this helps. Thanks!
|
|