<div style="color:black;font: 10pt arial;"><font size="2"><br>
Hi David,<br>
<br>
There are some cairo_show_page() functions that you don't need. Going from pixels to points for the PDF can be a challenge. See if the following is of any help getting it to work.<br>
<br>
</font>
<div><font size="2">Eric</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2"><br>
//gcc -Wall -g copy_surface2.c -o copy_surface2 `pkg-config --cflags --libs cairo`<br>
<br>
//Tested on Ubuntu18.04.<br>
<br>
#include<cairo.h><br>
#include<cairo-pdf.h><br>
#include<stdio.h><br>
<br>
//Width and height of drawings.<br>
static double width=400.0;<br>
static double height=400.0;<br>
//PDF's are in points so adjust the drawing if you want it the same size as the .png<br>
//on screen. Try different values here.<br>
static double ppi=100.0;<br>
<br>
int main()<br>
{<br>
//Create a recording surface.<br>
cairo_rectangle_t extents={.x=0.0, .y=0.0, .width=width, .height=height};<br>
cairo_surface_t *surface1=cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extents);<br>
cairo_t *cr1=cairo_create(surface1);<br>
//Paint the background white.<br>
cairo_set_source_rgba(cr1, 1.0, 1.0, 1.0, 1.0);<br>
cairo_paint(cr1);<br>
//Draw an x or other drawing in the recording surface.<br>
cairo_set_line_width(cr1, 10.0);<br>
cairo_set_source_rgba(cr1, 0.0, 1.0, 0.0, 1.0); <br>
cairo_move_to(cr1, 0.0, 0.0);<br>
cairo_line_to(cr1, 200.0, 200.0);<br>
cairo_stroke(cr1);<br>
cairo_move_to(cr1, 0.0, 200.0);<br>
cairo_line_to(cr1, 200.0, 0.0);<br>
cairo_stroke(cr1); <br>
<br>
//Save the recording surface to a .png and .pdf.<br>
printf("Save a_test.png\n");<br>
cairo_surface_t *surface2=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);<br>
cairo_t *cr2=cairo_create(surface2);<br>
cairo_set_source_surface(cr2, surface1, 0.0, 0.0);<br>
cairo_paint(cr2); <br>
cairo_surface_write_to_png(surface2, "a_test.png");<br>
<br>
printf("Save a_test.pdf\n");<br>
double points_scale=72.0/ppi;<br>
cairo_surface_t *surface3=cairo_pdf_surface_create("a_test.pdf", width*points_scale, height*points_scale);<br>
cairo_t *cr3=cairo_create(surface3);<br>
cairo_scale(cr3, points_scale, points_scale);<br>
cairo_set_source_surface(cr3, surface1, 0.0, 0.0);<br>
cairo_paint(cr3); <br>
<br>
//Clean up.<br>
cairo_destroy(cr1);<br>
cairo_destroy(cr2);<br>
cairo_destroy(cr3);<br>
cairo_surface_destroy(surface1);<br>
cairo_surface_destroy(surface2);<br>
cairo_surface_destroy(surface3);<br>
<br>
//For testing with valgrind.<br>
cairo_debug_reset_static_data();<br>
<br>
return 0;<br>
}<br>
<br>
</font></div>
</div>