Two Pilots™    Home  |  Navigation  |  Site Map  |  Products  |  Download  |  Prices  |  For Partners  |  Support


All forums · Statistics · Search ·

Two Pilots forum / For software developers / Margins and Page Breaks
Author Message
Randy Widell
Member
# Posted: 1 Apr 2011 17:07


I am having a great deal of trouble with PDF Creator Pilot + HTML2PDF. I have the latest versions of both, though, the latest versions do not seem to recognize our license key.

License key aside, I am seeing two completely different behaviors with the same code under Windows 7 SP1 (IE9) and Windows XP SP3 (IE7), both 32-bit. Neither is correct.

In both cases, I have the following in my HTML...

...
<head>
...
<style>
@media print {
HR.pgbrk {
PAGE-BREAK-AFTER: always;
VISIBILITY: hidden;
HEIGHT: 0px
}
}
@media screen {
HR.pgbrk {
PAGE-BREAK-AFTER: always;
BORDER-RIGHT: black 1px dotted;
BORDER-TOP: black 1px dotted;
DISPLAY: block; BORDER-LEFT: black 1px dotted;
BORDER-BOTTOM: black 1px dotted;
HEIGHT: 2px
}
}
</style>
</head>

Under Windows 7, HTML2PDF seems to completely ignore the page break and jams most of a nine page document on the first page using severe vertical scaling. Subsequent pages contain random parts of the document with varying vertical scaling.

Under Windows XP, HTML2PDF seems to honor the page breaks, but always creates a 2-3 inch margin on the right hand side. The top, left, and bottom margins are fine. Nothing I do affects the margins. No combination of changes to AutoAdjustPageWidth, AutoAdjustContentWidth, or the Margin properties actually seems to do anything.

The code is pretty straightforward:

IPDFDocument4* PDF = NULL;
CLSID clsid;
if(CLSIDFromProgID(OLESTR("PDFCreatorPilot.PDFDocu ment4"), &clsid) != S_OK)
return false;
if(CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(IPDFDocument4), (LPVOID *)&PDF) != S_OK)
return false;

IHTML2PDF2* HTML = NULL;
CLSID clsid2;
if(CLSIDFromProgID(OLESTR("HTML2PDFAddon.HTML2PDF2 "), &clsid2) != S_OK)
return false;
if(CoCreateInstance(clsid2, NULL, CLSCTX_ALL, __uuidof(IHTML2PDF2), (LPVOID *)&HTML) != S_OK)
return false;

if(PDF->SetLicenseData( ..., ...) != S_OK)
return false;

PDF->Compression = coFlate;
PDF->ProducePDFA = false;
PDF->PageSize = pfLetter;

HTML->StartHTMLEngine( ..., ...);
HTML->ConnectToPDFLibrary(PDF);
HTML->LoadHTMLFile(HTMLpath);
HTML->AutoAdjustContentWidth=VARIANT_FALSE;
HTML->AutoAdjustPageWidth=VARIANT_FALSE;
HTML->MarginBottom=10;
HTML->MarginTop=10;
HTML->MarginLeft=10;
HTML->MarginRight=10;
HTML->ConvertAll();

PDF->SaveToFile(PDFpath, false);

Randy Widell
Member
# Posted: 1 Apr 2011 17:15


Oh, I forgot to mention that this happens regardless of whether I use the @media CSS directives. Which brings up another point, it would be awesome if a future version allowed you to specify which CSS media to use. The HR.pgbrk elements have to be visible to the user when they are editing, but should not be visible when printing or creating a PDF.

max.f
# Posted: 5 Apr 2011 07:27


Hello Randy,

Give me please your order ID and I'll check why the latest version do not accept your license key.
Also, please, send us a minimal HTML file which demonstrates the problem you've described (please use our online form for it: http://www.colorpilot.com/support.php )

--
Max Filimonov,
max.f@colorpilot.org

Randy Widell
Member
# Posted: 12 Apr 2011 15:54


Max,

Any information about the problem; were you able to reproduce it at all? I have seen everything work fine with the same HTML files and the same versions of PDFCreator and HTML2PDF under Windows XP SP3. I have not pinned down what is different between that system and my XP SP3 system yet, though.

max.f
# Posted: 16 Apr 2011 10:48


Yes, we were able to reproduce the problem but have not solved it yet.

--
Max Filimonov

Randy Widell
Member
# Posted: 17 May 2011 11:55


Any progress? Any ideas about why this is happening? Maybe there is something we can change in the HTML?

Any idea why the latest version still claims to be a demo version even with a valid key? Are the demo downloads supposed to become full versions when you give them a license key, or is there a separate download?

Randy Widell
Member
# Posted: 17 May 2011 12:19


By the way, I see the same issues with your HTML2PDF demo app. It seems to work OK under Windows XP, but mangles the PDF under Windows 7. I tried converting the web page:

http://www.biopdf.com/guide/index.php

This is a good example because it is long and spans multiple pages.

Under Windows 7, it looks like it puts the entire document on the first page. The second page contains the entire document minus the section that should have been on the first page. The third page contains the entire document minus what should have been on the first and second pages. Etc.

max.f
# Posted: 18 May 2011 07:40


All those problems appeared after IE9. It looks like they changed the way IE renders HTML content to EMF file (or to device context) and now we have such a problem.
Unfortunately the problem is not fixed yet.

--
Max Filimonov,
max.f@colorpilot.org

Randy Widell
Member
# Posted: 19 May 2011 10:54


IE9 may be the problem under Windows 7, but I still cannot get consistent behavior with IE 6, 7, or 8 under Windows XP.

I wrote a small test app and the code is below. Under XP, I noticed that, in some cases, I have to specify a DPI of 96 in order to get the PDF to look somewhat proper. Otherwise, it is scaled up and runs off of the page. Even with a DPI of 96, there always seems to be a 2" margin on the right. When the default DPI of 72 works, I usually get the 2" margin. Now, the test app you provide with HTML2PDF seems to get the scaling and margins correct on the same system. So, clearly there is something wrong with my test app code. I just don't see what I'm missing.

The other problem is that I cannot get HTML2PDF to consistently recognize HR elements with page-break-after:always set. Sometimes it works, sometimes it doesn't with the same HTML file. Your test app has the same issue.

--- TEST CODE ---

#include <iostream>
#include <string>
#include "getopt.h"
#import "./PDFCreatorPilot.dll"
#import "./HTML2PDF.dll"

#define IN2PX(_res, _in) ((long)((float)res*_in))

static const char *shortOpts="m:r:o:";

int main(
int _argc,
char* _argv[])
{
std::string htmlFile, pdfFile;
PDFCreatorPilotLib::IPDFDocument4 *pdf=0;
HTML2PDFAddOn::IHTML2PDF2 *html=0;
IUnknown *unk=0;
CLSID clsid;
int mode=0;
int res=0;
int opt=0;
char *ptr=0;

if(!SUCCEEDED(CoInitialize(0))){
std::cerr << "Failed to initialize COM.n";
return 0;
}

for(;;){
opt=getopt(_argc, _argv, shortOpts);

if(opt==-1)
break;

switch(opt){
case 'm':
switch(*optarg){
case 'p': mode=1; break;
case 'c': mode=2; break;
}

break;
case 'r':
res=(int)strtol(optarg, &ptr, 10);

if(ptr==optarg)
res=72;

break;
case 'o':
pdfFile=optarg;
break;
}
}

if(optind==_argc){
std::cerr << "No input file specified.n";
return 0;
}

htmlFile=_argv[optind];

if(pdfFile.empty()){
pdfFile=htmlFile;
pdfFile.append(".pdf");
}

if(!SUCCEEDED(CLSIDFromProgID(
OLESTR("PDFCreatorPilot.PDFDocument4"),
&clsid)))
{
std::cerr << "Failed to get PDFDocument4 CLSID.n";
return 0;
}

if(!SUCCEEDED(CoCreateInstance(
clsid,
0,
CLSCTX_ALL,
__uuidof(PDFCreatorPilotLib::IPDFDocument4),
(void**)&pdf)))
{
std::cerr << "Failed to get PDFDocument4 object.n";
return 0;
}

if(!SUCCEEDED(CLSIDFromProgID(
OLESTR("HTML2PDFAddon.HTML2PDF2"),
&clsid)))
{
std::cerr << "Failed to get HTML2PDF2 CLSID.n";
return 0;
}

if(!SUCCEEDED(CoCreateInstance(
clsid,
0,
CLSCTX_ALL,
__uuidof(HTML2PDFAddOn::IHTML2PDF2),
(void**)&html)))
{
std::cerr << "Failed to get HTML2PDF2 object.n";
return 0;
}

if(!SUCCEEDED(pdf->SetLicenseData( ... , ...)))
std::cerr << "Failed to set PDF Creator license data.n";

pdf->Compression=PDFCreatorPilotLib::coFlate;
pdf->ProducePDFA=VARIANT_FALSE;
pdf->PageSize=PDFCreatorPilotLib::pfLetter;
pdf->PageOrientation=PDFCreatorPilotLib::pPortrai t;
pdf->PageResolution=res;

if(!SUCCEEDED(html->StartHTMLEngine( ... , ...)))
std::cerr << "Failed to set HTML2PDF license data.n";

pdf->QueryInterface(IID_IUnknown, (void**)&unk);
html->ConnectToPDFLibrary(unk);
unk->Release();
unk=0;

html->AutoAdjustPageWidth=(mode==1 ? VARIANT_TRUE : VARIANT_FALSE);
html->AutoAdjustContentWidth=(mode==2 ? VARIANT_TRUE : VARIANT_FALSE);
html->MarginBottom=IN2PX(res, 0.5f);
html->MarginLeft=IN2PX(res, 0.5f);
html->MarginTop=IN2PX(res, 0.5f);
html->MarginRight=IN2PX(res, 0.5f);
html->MinimalWidth=IN2PX(res, 8.5f);

if(!SUCCEEDED(html->LoadHTMLFile(htmlFile.c_str() ))){
std::cerr << "Failed to load HTML file.n";
html->Release();
pdf->Release();
return 0;
}

if(!SUCCEEDED(html->ConvertAll())){
std::cerr << "Failed to convert HTML file.n";
html->Release();
pdf->Release();
return 0;
}

html->DisconnectFromPDFLibrary();
html->Release();
html=0;

if(!SUCCEEDED(pdf->SaveToFile(pdfFile.c_str(), VARIANT_FALSE))){
std::cerr << "Failed to save PDF file.n";
pdf->Release();
return 0;
}

pdf->Release();
pdf=0;

return 0;
}

max.f
# Posted: 20 May 2011 07:37


Randy,

yes, the better way is to keep PDF's resolution the same as your monitor's. Because IE will make EMF files depending on monitor's DPI. Later those EMFs will be converted to PDF.

What about <HR> with style = "page-break-after:always" - I guess it is one more surprise from IE. We use DOM to gel all HTML elements and read all its styles. If we found "page-break" we use it.

--
Max Filimonov,
max.f@colorpilot.org

Randy Widell
Member
# Posted: 9 Aug 2011 09:32


Max,

So, I did a lot of work with this back in June and it looks like I need to do two things to make the HTML to PDF conversion work reliably. The first was, as you suggested, getting the screen resolution.

The second was switching to IPDFDocument3 instead of IPDFDocument4. There still seem to be some features that do not work (notably: setting the left and right margins has no effect while setting the top and bottom margins works fine), however the conversion seems to have been working reliably for the past month and a half or so on all systems.

I am testing the new versions you released on July 14, and the only issue I appear to be having is that neither library recognizes our license code. If you could help me out with that, we should be all good.

Artem
Member
# Posted: 10 Aug 2011 11:12


Hello Randy,

Send us your order information via http://www.colorpilot.com/support.php

--
Best regards,
Artem Golubnicenko

Two Pilots
http://www.colorpilot.com

 

 

Powered by miniBB 2.0 RC7 © 2001-2004 Page creation time (sec.): 0.014

 

Page top