I'm using ABCpdf 9.1 x64 .Net with Coldfusion to create PDF's based on HTML content. Each PDF document has a different header and footer which are generated as HTML with some Coldfusion code. The header is identical for every page where the footer is slightly different for every page (because it shows the page number). Here's the main part of my code:
// add content
theDoc.Get_Rect().Set_String("67 80 573 742");
theContentID = theDoc.AddImageHTML(pdfContent);
while (true) {
if (!theDoc.Chainable(theContentID)) {
break;
}
theDoc.Set_Page(theDoc.AddPage());
theContentID = theDoc.AddImageToChain(theContentID);
}
// add header & footer on each page
for (i=1; i <= theDoc.Get_PageCount(); i++) {
// set page
theDoc.Set_PageNumber(i);
// HEADER
theDoc.Get_Rect().Set_String("67 755 573 809");
theDoc.AddImageHTML(headerContent);
// FOOTER
theDoc.Get_Rect().Set_String("67 0 573 65");
theDoc.AddImageHTML(replace(footerContent, "[page]", i));
}
As you can see, the AddImageHTML() method gets called 2 times for every page and once for the content. So if I have content which creates 6 pages, the method gets called 13 times. This isn't ideal because the method consums a lot of time.
Is there a more efficient way to add a header and footer from HTML? There's a method AddImageCopy() but it doesn't work with objects created by AddImageHtml() .
Just for understandig: Those getter and setter methods are created by Coldfusion to access .Net properties.
If your HTML is relatively simple and does not rely on CSS, you can perhaps tweak it to HTML Styled text and use use AddHtml instead of AddImageHtml. AddHtml should perform much faster than AddImageHtml. As a side benefit you will be able to use referenced (not system-installed) fonts and CMYK colors if necessary.
Since your header is identical on every page, perhaps you could use AddImageHtml on a secondary Doc object, then add that as an image on each page. This would cut the calls for the header from one per page to one only per file.
Since the footer is different on each page, I don't see how you can avoid a call to something on each page.
I used this approach where the header is the same across all pages
doc.PageNumber = 1;
doc.Rect.Rectangle = headerRect; //headerrect should define the rect where the header is
doc.AddImageHtml(headerHtml); //perform addimage html once
//repeat for other pages (clones the header. much faster than calling addImageHtml every time)
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.AddImageDoc(doc, 1, doc.Rect);
}
Related
Just tried out the blueimp "out of the box" files.
With a few hurdles, I got the plugin to work on my site.
In my application, I want to store the uploaded files in specific directories based on the file name.
The PHP code to do this is pretty straight forward:
function StoreAudioFiles()
{
$TempFileName = $_FILES['file']['tmp_name'];
$OriginalFileName= $_FILES['file']['name'];
$TheFolderName=MyCustomFunction($OriginalFileName);
move_uploaded_file($TempFileName,$TheFolderName.$OriginalFileName);
}
I have no idea where to modify the 'out-of-the-box' file "UploadHandler.php" to insert my code.
Given the fact that the file is 55 pages long when opened in Word, any help would be appreciated.
David
I worked out a solution and am posting it here for others to use.
In the index.php file that comes with blueimp, add functions after the object is created. Here's what I did:
require('UploadHandler.php');
$upload_handler = new UploadHandler();
//Now Add whatever custom functionality you want from here on.
MoveFiles();
function MoveFiles()
{
$UploadDir="files/";
$TheHandle=opendir($UploadDir);
while (False !== ($FileName = readdir($TheHandle))) MoveThisFile($FileName);
}
function MoveThisFile($TheFileName)
{
if(strlen($TheFileName)<4) return;
$UploadFilePath='mysite/server/php/files/';
$TheFolderName=MyCustomFolderName($TheFileName);
$OriginalFileName=$UploadFilePath.$TheFileName;
$TargetFileName=$TheFolderName.$TheFileName;
rename($OriginalFileName,$TargetFileName);
}
When you render jade templates in express you can configure your application with 'view options', { layout: true } and the templates rendered will automatically get plugged into the body local of the layout template.
I'm trying to achieve the equivalent behavior rendering files from node.js, but without the express framework (I'm just building static files as part of a larger pipeline).
There appear to be two options:
Load both the main template and the layout, convert to functions, render the template first and then pass the results to the layout function
Use the standard template inheritance and block structure, but then I'm explicitly using named blocks
Are these the only options (which, fair enough, are still awesome), or am I missing some trick?
Edit
Here's a rough cut of the first option in case anyone is interested:
// Load jade
var jade = require('jade');
// Load actual template text
var layout = fs.readFileSync('layout-path', 'utf8')
tpl = fs.readFileSync('tpl-path', 'utf8');
// Compile template rendering function
layout = jade.compile(layout, { pretty: true, filename: 'layout-path' });
tpl = jade.compile(tpl, { pretty: true, filename: 'tpl-path' });
// Render jade template, passing in the info
var output = layout({ body: tpl({ local1: some_var, local2: some_var }) }
// Write rendered content to file
fs.writeFileSync('output.html', output);
I believe the answer is "no", you're not missing any trick. The two options you outline seem to me the two most straightforward ways to use jade to generate your file. Of course there are plenty of non-jade approaches as well. For example, you could merge the contents with the plates approach, good old String.replace, or split your layout into separate header ad footer fragment files and just concatenate them in head, body, foot order.
I've been looking over the Sitecore documentation for HtmlControls and WebControls, but none of the items have any meaningful descriptions or example code to show how they're used or what they produce.
I understand how to use simple controls like Text, Date, Image, and Link:
<sc:Text runat="server" ID="content" Field="Content" />
Is there a resource that includes examples for more advanced controls like WebControls.ItemList or HtmlControls.TreePicker to show how they'd be used and what output they produce?
The SDN has some code examples. Essentially, WebControls are .NET server controls where you write all business logic and front-end code via C#. Here's the series on the SDN called "Web Controls":
Part 1
Part 2
Part 3
Here's a sample TextControl:
protected override void DoRender(HtmlTextWriter output) {
if (ClassAttribute.Length > 0) {
output.AddAttribute(HtmlTextWriterAttribute.Class, ClassAttribute);
}
if (StyleAttribute.Length > 0) {
output.AddAttribute(HtmlTextWriterAttribute.Style, StyleAttribute);
}
output.RenderBeginTag(HtmlTextWriterTag.Div);
string val = string.Empty;
if(_text.Length == 0) {
val = GetFieldValue(_textField);
} else {
val = _text;
}
output.AddAttribute(HtmlTextWriterAttribute.Class, TextClass);
output.AddAttribute(HtmlTextWriterAttribute.Style, TextStyle);
output.RenderBeginTag(HtmlTextWriterTag.Div);
output.Write(val);
output.RenderEndTag();
output.RenderEndTag();
}
EDIT: To understand how internal built-in Sitecore components work:
Sitecore is not going to provide the details of how their controls are built. Sitecore is not open source. That being said, I've been told several times by people from Sitecore that if you need to understand how something works to extend it, use the .NET Reflector to de-compile the kernel (Sitecore.Kernel.dll). I've done this many times to figure out how the internal things work. In your case, you can decompile the assembly and look at the classes under Sitecore.Web.UI.WebControls etc.
I'm using the Chromium port of WebKit on Windows and I'm trying to retrieve a list of all of the images in my document. I figured the best way to do this was to implement WebKit::WebFrameClient::didFinishLoading like so:
WebNodeList list = document->getElementsByTagName(L"img");
for (size_t i = 0; i < list.length(); ++i) {
// Manipulate images here...
}
However, when this delegate fires, list.length() returns 0. The only times I've seen it return a list of non-zero length is when I substitute "body" or "head" for "img". Strangely enough, if I call getElementsByTagName(L"img") outside of the delegate, it works correctly.
I'm guessing that the DOM isn't fully loaded when didFinishLoading is called, but that would seem to contradict the delegate's name. Does anyone know what I may be missing here?
It turns out that the mistake was purely on my side. I was caching a pointer to the DOM document in my frame wrapper. Of course, since a frame can outlive a DOM document, I ended up referencing an out-of-date document once I loaded a new page.
I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:
http://www.codeproject.com/KB/menus/changemru.aspx
http://www.microsoft.com/msj/0899/c/c0899.aspx
It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:
void CMyWinApp::SetMRUListSize( int size )
{
// size guaranteed to be between 1 and 16
delete m_pRecentFileList ;
LoadStdProfileSettings( size ) ;
}
What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?
My CApp derives from CWinApp. In initInstance, you have this line:
LoadStdProfileSettings(10);
At the end of InitInstance, add this code:
m_pmf->m_pRecentFileList = m_pRecentFileList;
Here m_pmf is my MainFrame class and I created a member CMainFrame::m_pRecentFileList of type CRecentFileList which is in the MFC source file filelist.cpp. m_pRecentFileList on the right is protected and CMainFrame doesn't have access to it from outside InitInstance, but you can make a functional copy here.
At the end of CMainFrame::OnClose, force a registry update by:
m_pRecentFileList->WriteList();
// Force registry update on exit. This doesn't work without forcing.
I don't even have to rebuild m_pRecentFileList, the MRU mechanism updates it correctly. Example: 5 MRU items, the first is moved to another directory and can no longer be found. Stepping through the code in the debugger shows that the bad entry is removed from the list. For some reason, the updated list isn't saved correctly unless I force it as explained above. I originally thought the problem might have something to do with privileges (64-bit Win7), but running the app as admin didn't help.
Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.
Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:
m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
bReturn = TRUE;
// Reload list of MRU files from registry
m_pRecentFileList->ReadList();
}
[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?
There's another CodeProject example which might help too.