Tools to Capture and Convert the Web
GrabzIt's Online Community

ConvertHTML - difference between PDF and PNG/JPG

Hi

I've been using ConvertHTML with PNG successfully and now I have been trying to use my same code (modified slightly for the PDF parameters) to have the option for PDF export as well but PDF export gives a slightly different result that is not quite right. The PDF export puts some extra white space (not margins) on the right and bottom of my HTML.  I have tested the exact same HTML with the code below. Any ideas why I am getting different export?  The only thing I can think of is when I convert pixels to mm, I have to round. 

Thanks

Here is the code I have for PNG:

GrabzIt("").ConvertHTML(whatToConvert, {
     "target": "#captureThis",
     "address": theAddress,
     "format": "png",
     "transparent": 1,
     "bwidth": 1200,
     "bheight": 628,
     "width": 1200,
     "height": 628,
     "displayid": "finalImage",
}).DataURI(dataURLAfterGrabzIt);

 

And here is the code for PDF:

GrabzIt().ConvertHTML(whatToConvert, {
     "target": "#captureThis",
     "address": theAddress,
     "format": "pdf",
     "width": 317,  //Pixels converted to mm
     "height": 166,  //Pixels converted to mm
     "displayid": "finalImage",
     "mtop": 0,
     "mleft": 0,
     "mbottom": 0,
     "mright": 0
}).DataURI(dataURLAfterGrabzIt);

 

Asked by Corey Alderin on Monday, 16 December, 2019 04:07:51 PM

Hi Corey,

Yes they probably will be slightly different. This is because one is creating an exact image of whats in the browser and then cutting it to the target element. The other is converted to PDF elements and then correct PDF element is cut out.

Also for PDF I don't think you should be specifying width and height. 

Kind Regards

Answered by GrabzIt Support on Monday, 16 December, 2019 04:19:07 PM

Thanks.  So is it possible to get the same results?  I have been testing lots of different things with no success.  Will I need to use a PNG to PDF converter instead?  I was trying to avoid that but maybe that is the only solution.

 

If I don't specify height and width, Then it adds even more white space.  I have tried different combinations of specifying only width and only height and they all give different results but not the correct results. 

 

Thanks

 

 

Answered by Corey Alderin on Monday, 16 December, 2019 04:46:17 PM

Could you provide the HTML you are trying to capture. It would probably make sense to email it to us.

Answered by GrabzIt Support on Monday, 16 December, 2019 04:50:29 PM

Sure, I can send that.  Where should I send it to?

Answered by Corey Alderin on Monday, 16 December, 2019 05:18:45 PM

Ok, I think I can see what you are getting at. At the moment when you capture a target as a PDF. It will still return the page size you asked for so if you asked for a page size of A4 you would get the target croped and left sitting in a A4 page.

However, you seem to want the targetted HTML element on its own with the page size set to the HTML element page size.

Is this correct? If so this will need a code change. I think we can do it by allowing a -1 to be passed to the page size parameter in a similar way to the creating a targetted image.

Answered by GrabzIt Support on Monday, 16 December, 2019 05:23:33 PM

Yes, that is correct.  That would be great if that would be an option.  Thanks

Answered by Corey Alderin on Monday, 16 December, 2019 05:26:45 PM