mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-27 17:07:51 +01:00
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
This commit is contained in:
parent
e77e8764cb
commit
113767476a
4 changed files with 208 additions and 4 deletions
3
README
3
README
|
@ -4,7 +4,8 @@ zathura is a pdf viewer based on the poppler pdf rendering library
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
poppler-glib (0.10.7)
|
poppler-glib (0.10)
|
||||||
|
cairo (1.8.8)
|
||||||
gtk2 (2.17.2)
|
gtk2 (2.17.2)
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
|
|
2
config.h
2
config.h
|
@ -63,12 +63,14 @@ Shortcut shortcuts[] = {
|
||||||
Command commands[] = {
|
Command commands[] = {
|
||||||
// command, function
|
// command, function
|
||||||
{"export", cmd_export},
|
{"export", cmd_export},
|
||||||
|
{"form", cmd_form},
|
||||||
{"goto", cmd_goto},
|
{"goto", cmd_goto},
|
||||||
{"info", cmd_info},
|
{"info", cmd_info},
|
||||||
{"links", cmd_links},
|
{"links", cmd_links},
|
||||||
{"open", cmd_open},
|
{"open", cmd_open},
|
||||||
{"print", cmd_print},
|
{"print", cmd_print},
|
||||||
{"rotate", cmd_rotate},
|
{"rotate", cmd_rotate},
|
||||||
|
{"save", cmd_save},
|
||||||
{"quit", cmd_quit},
|
{"quit", cmd_quit},
|
||||||
{"zoom", cmd_zoom},
|
{"zoom", cmd_zoom},
|
||||||
};
|
};
|
||||||
|
|
118
zathura.1
Normal file
118
zathura.1
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
.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
|
89
zathura.c
89
zathura.c
|
@ -110,12 +110,14 @@ void sc_quit(Argument*);
|
||||||
|
|
||||||
/* command declarations */
|
/* command declarations */
|
||||||
void cmd_export(int, char**);
|
void cmd_export(int, char**);
|
||||||
|
void cmd_form(int, char**);
|
||||||
void cmd_goto(int, char**);
|
void cmd_goto(int, char**);
|
||||||
void cmd_info(int, char**);
|
void cmd_info(int, char**);
|
||||||
void cmd_links(int, char**);
|
void cmd_links(int, char**);
|
||||||
void cmd_open(int, char**);
|
void cmd_open(int, char**);
|
||||||
void cmd_print(int, char**);
|
void cmd_print(int, char**);
|
||||||
void cmd_rotate(int, char**);
|
void cmd_rotate(int, char**);
|
||||||
|
void cmd_save(int, char**);
|
||||||
void cmd_quit(int, char**);
|
void cmd_quit(int, char**);
|
||||||
void cmd_zoom(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_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));
|
gtk_widget_modify_bg(GTK_WIDGET(Zathura.drawing_area), GTK_STATE_NORMAL, &(Zathura.Settings.default_bg));
|
||||||
|
|
||||||
|
|
||||||
/* inputbar */
|
/* inputbar */
|
||||||
gtk_entry_set_inner_border(Zathura.inputbar, NULL);
|
gtk_entry_set_inner_border(Zathura.inputbar, NULL);
|
||||||
gtk_entry_set_has_frame(Zathura.inputbar, FALSE);
|
gtk_entry_set_has_frame(Zathura.inputbar, FALSE);
|
||||||
|
@ -709,7 +710,6 @@ sc_search(Argument *argument)
|
||||||
GList* results;
|
GList* results;
|
||||||
GList* list;
|
GList* list;
|
||||||
|
|
||||||
|
|
||||||
if(argument->data)
|
if(argument->data)
|
||||||
search_item = (char*) 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.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document);
|
||||||
Zathura.PDF.file = file + strlen("file://");
|
Zathura.PDF.file = file;
|
||||||
|
|
||||||
set_page(0);
|
set_page(0);
|
||||||
draw();
|
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
|
void
|
||||||
cmd_goto(int argc, char** argv)
|
cmd_goto(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -972,6 +1046,15 @@ cmd_rotate(int argc, char** argv)
|
||||||
sc_rotate(&argument);
|
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
|
void
|
||||||
cmd_zoom(int argc, char** argv)
|
cmd_zoom(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue