Commit 11376747 authored by Moritz Lipp's avatar Moritz Lipp

Edit form fields and export PDF

Added following functionality:
  * Save the PDF file
  * Show and edit form fields

Fixes and other changes:
  * Fixed internal saved file path

Other:
  * Added manpage
parent e77e8764
......@@ -4,7 +4,8 @@ zathura is a pdf viewer based on the poppler pdf rendering library
Requirements
------------
poppler-glib (0.10.7)
poppler-glib (0.10)
cairo (1.8.8)
gtk2 (2.17.2)
Configuration
......
......@@ -63,12 +63,14 @@ Shortcut shortcuts[] = {
Command commands[] = {
// command, function
{"export", cmd_export},
{"form", cmd_form},
{"goto", cmd_goto},
{"info", cmd_info},
{"links", cmd_links},
{"open", cmd_open},
{"print", cmd_print},
{"rotate", cmd_rotate},
{"save", cmd_save},
{"quit", cmd_quit},
{"zoom", cmd_zoom},
};
.TH ZATHURA 1 zathura\-0.0
.SH NAME
zathura \- a pdf viewer
.SH SYNOPSIS
.B zathura
.RB [\fIFILE\fR] [\fIPASSWORD\fR]
.SH DESCRIPTION
zathura is a pdf viewer based on the poppler pdf rendering library
.SH USAGE
.SS Commands
.TP
.B export
export images, the pdf or attachments to a specified directory
.TP
.B form
show and edit form fields
.TP
.B goto
go to a given page
.TP
.B info
show the document properties
.TP
.B links
show existing links on the page
.TP
.B open
open a pdf document
.TP
.B print
print the document or specific sites of it
.TP
.B quit
close the program
.TP
.B rotate
rotate the page
.TP
.B zoom
set the zoom level
.SS Shortcuts
.TP
.B ^f
next page
.TP
.B ^b
previous page
.TP
.B ^-
zoom in
.TP
.B ^+
zoom out
.TP
.B ^0
original size
.TP
.B ^r
rotate right
.TP
.B ^e
rotate left
.TP
.B ^q
quit program
.TP
.B ^p
print
.TP
.B n
search forwards
.TP
.B N
search backwards
.TP
.B h
scroll left
.TP
.B j
scroll down
.TP
.B k
scroll up
.TP
.B l
scroll right
.TP
.B PgUp
scroll to the top of the page
.TP
.B PgDown
scroll to the bottom of the page
.TP
.B i
best fit
.TP
.B u
adjust width
.TP
.B :
focus inputbar
.TP
.B o
open command
.TP
.B r
rotate command
.TP
.B z
zoom command
.TP
.B g
go to command
.TP
.B /
search
.SH CONFIGURATION
the complete configuration (appearance, shortcuts, commands and other settings) are stored in a seperate file (config.h) where you are able to change and edit everything according to your wishes
......@@ -110,12 +110,14 @@ void sc_quit(Argument*);
/* command declarations */
void cmd_export(int, char**);
void cmd_form(int, char**);
void cmd_goto(int, char**);
void cmd_info(int, char**);
void cmd_links(int, char**);
void cmd_open(int, char**);
void cmd_print(int, char**);
void cmd_rotate(int, char**);
void cmd_save(int, char**);
void cmd_quit(int, char**);
void cmd_zoom(int, char**);
......@@ -193,7 +195,6 @@ init()
gtk_widget_set_events(Zathura.drawing_area, GDK_BUTTON_PRESS_MASK);
gtk_widget_modify_bg(GTK_WIDGET(Zathura.drawing_area), GTK_STATE_NORMAL, &(Zathura.Settings.default_bg));
/* inputbar */
gtk_entry_set_inner_border(Zathura.inputbar, NULL);
gtk_entry_set_has_frame(Zathura.inputbar, FALSE);
......@@ -709,7 +710,6 @@ sc_search(Argument *argument)
GList* results;
GList* list;
if(argument->data)
search_item = (char*) argument->data;
......@@ -785,7 +785,7 @@ cmd_open(int argc, char** argv)
}
Zathura.PDF.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document);
Zathura.PDF.file = file + strlen("file://");
Zathura.PDF.file = file;
set_page(0);
draw();
......@@ -863,6 +863,80 @@ cmd_export(int argc, char** argv)
}
}
void
cmd_form(int argc, char** argv)
{
if(argc == 0 || !Zathura.PDF.document || !Zathura.PDF.page)
return;
if(strcmp(argv[0], "show") == 0)
{
double page_width, page_height;
int form_id = 0;
GList* form_mapping = g_list_reverse(poppler_page_get_form_field_mapping(Zathura.PDF.page));
GList* forms;
poppler_page_get_size(Zathura.PDF.page, &page_width, &page_height);
for(forms = form_mapping; forms; forms = g_list_next(forms))
{
/* draw rectangle */
PopplerFormFieldMapping *form = (PopplerFormFieldMapping*) forms->data;
PopplerRectangle *form_rectangle = &form->area;
if(!poppler_form_field_is_read_only(form->field))
{
form_rectangle->y1 = page_height - form_rectangle->y1;
form_rectangle->y2 = page_height - form_rectangle->y2;
highlight_result(form_rectangle);
/* draw text */
cairo_t *cairo = cairo_create(Zathura.PDF.surface);
cairo_select_font_face(cairo, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cairo, 10);
cairo_move_to(cairo, form_rectangle->x1 + 1, form_rectangle->y1 - 1);
cairo_show_text(cairo, g_strdup_printf("%i", form_id));
}
form_id++;
}
poppler_page_free_form_field_mapping(form_mapping);
}
else if(strcmp(argv[0], "set") == 0)
{
if(argc <= 2)
return;
GList* form_mapping = g_list_reverse(poppler_page_get_form_field_mapping(Zathura.PDF.page));
int form_id = atoi(argv[1]);
PopplerFormFieldMapping *form = (PopplerFormFieldMapping*) g_list_nth_data(form_mapping, form_id);
PopplerFormFieldType type = poppler_form_field_get_field_type(form->field);
if(type == POPPLER_FORM_FIELD_TEXT)
{
char *text = "";
int i;
for(i = 2; i < argc; i++)
text = g_strdup_printf("%s %s", text, argv[i]);
poppler_form_field_text_set_text(form->field, text);
}
else if(type == POPPLER_FORM_FIELD_BUTTON)
{
if(argv[2][0] == '0')
poppler_form_field_button_set_state(form->field, FALSE);
else
poppler_form_field_button_set_state(form->field, TRUE);
}
draw();
}
}
void
cmd_goto(int argc, char** argv)
{
......@@ -972,6 +1046,15 @@ cmd_rotate(int argc, char** argv)
sc_rotate(&argument);
}
void
cmd_save(int argc, char** argv)
{
if(argc == 0 || !Zathura.PDF.document)
return;
poppler_document_save(Zathura.PDF.document, g_strdup_printf("file://%s", argv[0]), NULL);
}
void
cmd_zoom(int argc, char** argv)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment