Using CIMG and JAGPDF to print a grid

0

I need to print a grid like the one in the photo on a PDF documentSample grid I am using CIMG to create the image in bmp, then save it as jpg and paste it in the PDF using JagPDF

The code for the graph is as follows:

int lineseparation=3;
int lineseparationbold=lineseparation*5;
CImg<unsigned char> graph1;
graph1.assign(50*lineseparationbold+1, 28*lineseparationbold+1, 1, 3, 255);
static const unsigned char black[] = { 0, 0, 0 }, white[] = { 255, 255, 255 };
static const unsigned char gray2[] = { 110, 110, 110 }, ngray[] = { 35, 35, 35 }, gray[] = { 220, 220, 220 };
static const unsigned char red[] = { 255, 200, 200 }, bred[] = { 255, 100, 100 };

graph1.draw_grid(lineseparation, lineseparation, 0, 0, false, true, red, 10.0f, 0xFFFFFFFF, 0xFFFFFFFF);
graph1.draw_grid(lineseparationbold, lineseparationbold, 0, 0, false, true, bred, 10.0f, 0xFFFFFFFF, 0xFFFFFFFF);
graph.save("plot.bmp");

Then after saving it as JPG I put it in the PDF using jagPDF this way:

pdf::Document doc(pdf::create_file("report.pdf"));
doc.page_start(pagewidth, pageheight);
pdf::Image imag2 = doc.image_load_file("plot1.jpg");
doc.page().canvas().image(imag2, 10, 50);
doc.page_end();
doc.finalize();

I need the grid to be 1mm separation between the lines (5mm the bold ones), when I put 3 pixels as separation when I print it is a little more than 1mm and if I put 2 pixels then is less than 1mm.

Putting non integers (e.g int lineseparation=2.9;) as input allow me to get bold lines closer to 5mm but the small lines are uneven. Saving the figure as BMP and resizing it is messing with the grid.

How can I make it print in the correct size?

Note: BMP and JPG have same size in pixels. I do the convertion without any resizing (although I tried that too).

c++
jpeg
bmp
cimg
asked on Stack Overflow Mar 28, 2019 by Diego Fernando Pava • edited Mar 28, 2019 by Diego Fernando Pava

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0