Created
March 7, 2018 08:01
-
-
Save okkez/32bc15544caf0750ff5d5e11db57ddaf to your computer and use it in GitHub Desktop.
A link in PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <cairo/cairo.h> | |
#include <cairo/cairo-pdf.h> | |
void main() | |
{ | |
// Creating a cairo PDF Surface | |
cairo_surface_t *csurface = cairo_pdf_surface_create("/home/kenji/a.pdf", 500, 400); | |
// Creating a cairo context | |
cairo_t *ctx = cairo_create(csurface); | |
// Creating rectangle in PDF | |
cairo_rectangle(ctx, 0.0, 0.0, 400, 300); | |
// Changing rectangle bacground color to Blue | |
cairo_set_source_rgb(ctx, 0.0, 0.0, 0.5); | |
cairo_fill(ctx); | |
// Moving to (10, 10) position in PDF | |
cairo_move_to(ctx, 10.0, 10.0); | |
// Changing text color to Yellow | |
cairo_set_source_rgb(ctx, 1.0, 1.0, 0.0); | |
// Writing some text to PDF | |
cairo_tag_begin(ctx, CAIRO_TAG_LINK, "uri='https://google.com/'"); | |
cairo_show_text(ctx, "Hello PDF :-)"); | |
cairo_tag_end(ctx, CAIRO_TAG_LINK); | |
cairo_show_page(ctx); | |
// Destroying cairo context | |
cairo_destroy(ctx); | |
cairo_surface_flush(csurface); | |
// Destroying PDF surface | |
cairo_surface_destroy(csurface); | |
// Opening PDF File | |
if (!fork()) { | |
execlp("xdg-open", "xdg-open", "/home/kenji/a.pdf", NULL); | |
exit(0); | |
} | |
} |
Author
okkez
commented
Mar 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment