|
PDF_setcolor
Set fill and stroke color
()
Related Examples ( Source code ) » pdf_setcolor Examples ( Source code ) » Create a PDF document containing a pie chart Code Examples / Notes » pdf_setcolorenyo vel cora
This seems a little less complicated: this is the color you want to use : 'FF11AA' <?php pdf_setcolor ($pdf, 'both', 0xFF / 255, 0x11 / 255, 0xAA / 255); ?> psychosos
If you want to change the font color you need to set type to "fill", not "stroke" ("both" also works, of course).
php
Here's a function for converting HTML hexadecimal colors to RGB decimals suitable for this function: $color_hex = "FF0000"; ## whatever hex color you want $color = convert_hexcolor_rgbdec($color_hex); pdf_setcolor($pdf, 'fill', 'rgb', $color['r'], $color['g'], $color['b']); function convert_hexcolor_rgbdec($color_hex) { $color['r'] = hexdec(substr($color_hex, 0, 2))/255; $color['g'] = hexdec(substr($color_hex, 2, 2))/255; $color['b'] = hexdec(substr($color_hex, 4, 2))/255; return $color; } -Derek _meto alt+q web.de
Damn, this took me some real long time! Maybe it's helpfull for those who even have no idea of color-Schemes like me ;) If u want to generate PDF's for Print Offices u need to set all the colors in CMYK. Here is a Function that will convert RGB to CMYK <? function hex2rgb($hex) { $color = str_replace('#','',$hex); $rgb = array('r' => hexdec(substr($color,0,2)), 'g' => hexdec(substr($color,2,2)), 'b' => hexdec(substr($color,4,2))); return $rgb; } function rgb2cmyk($var1,$g=0,$b=0) { if(is_array($var1)) { $r = $var1['r']; $g = $var1['g']; $b = $var1['b']; } else $r=$var1; $cyan = 255 - $r; $magenta = 255 - $g; $yellow = 255 - $b; $black = min($cyan, $magenta, $yellow); $cyan = @(($cyan - $black) / (255 - $black)) * 255; $magenta = @(($magenta - $black) / (255 - $black)) * 255; $yellow = @(($yellow - $black) / (255 - $black)) * 255; return array('c' => $cyan / 255, 'm' => $magenta / 255, 'y' => $yellow / 255, 'k' => $black / 255); } $color=rgb2cmyk(hex2rgb('#FF0000')); pdf_setcolor($pdf, "both", "cmyk", $color['c'], $color['m'], $color['y'], $color['k']); ?> U can call it with parameters (r,g,b) or just an array(r,g,b) that contains these values. Hope it works correct. All testing was fine. maurice dot anglebert
Bonjour, Cette fonction est utilisable pour définir une couleur de police. Hello, I search for the way of setting colors for the font in pdf and I find this. Hope it could help. <?php /** * set font color * maurice.anglebert@free.fr */ // path for the pdf file and string to show $pdfFilePath = $_SERVER[DOCUMENT_ROOT]."/the_dir_of_the_file/test.pdf"; $string = "The new color of my font"; $pdf = pdf_new(); pdf_open_file($pdf, $pdfFilePath); pdf_set_info($pdf, "Title", "Test pdf"); // A4 page pdf_begin_page($pdf, 595, 842); // set up of the font $font = pdf_findfont($pdf, "Courier", "host", FALSE); if (isset($font)) { pdf_setfont($pdf, $font, 10) or die ("unknown font"); } pdf_setColor($pdf, "fill", "rgb",0, 0, 1); // this for blue color // pdf_setColor($pdf, "fill", "rgb",1, 0, 0) for red pdf_set_value($pdf, "textrendering", 0); // show at the top of the page center pdf_show_boxed($pdf, $string, 0, 832, 595, 10, "center", ""); // resets graphic state pdf_initGraphics($pdf); // end of page and pdf_object pdf_end_page($pdf); pdf_close($pdf); pdf_delete($pdf); // use header to get the file header("Content-type: application/pdf"); header("Content-length: ".filesize($pdfFilePath)); header("Content-disposition: inline; filename=test.pdf"); readfile($pdfFilePath); ?> steven dot gould If you encounter errors of the form function 'PDF_setcolor' must not be called in 'path' scope this generally means that you've called the PDFLib functions in the wrong order. For example, the following would be *incorrect* because PDF_rect marks the beginning of the "path scope", and set_color must not be called in path scope: // THIS CODE WILL PRODUCE AN ERROR PDF_rect($pdf,0,0,$width,$height); PDF_setcolor($pdf,$red,$green,$blue); PDF_fill($pdf); The correct order of function calls is as follows: // Correct order of function calls PDF_setcolor($pdf,$red,$green,$blue); PDF_rect($pdf,0,0,$width,$height); PDF_fill($pdf); |
Change LanguagePDF_activate_item PDF_add_annotation PDF_add_bookmark PDF_add_launchlink PDF_add_locallink PDF_add_nameddest PDF_add_note PDF_add_outline PDF_add_pdflink PDF_add_table_cell PDF_add_textflow PDF_add_thumbnail PDF_add_weblink PDF_arc PDF_arcn PDF_attach_file PDF_begin_document PDF_begin_font PDF_begin_glyph PDF_begin_item PDF_begin_layer PDF_begin_page_ext PDF_begin_page PDF_begin_pattern PDF_begin_template_ext PDF_begin_template PDF_circle PDF_clip PDF_close_image PDF_close_pdi_page PDF_close_pdi PDF_close PDF_closepath_fill_stroke PDF_closepath_stroke PDF_closepath PDF_concat PDF_continue_text PDF_create_3dview PDF_create_action PDF_create_annotation PDF_create_bookmark PDF_create_field PDF_create_fieldgroup PDF_create_gstate PDF_create_pvf PDF_create_textflow PDF_curveto PDF_define_layer PDF_delete_pvf PDF_delete_table PDF_delete_textflow PDF_delete PDF_encoding_set_char PDF_end_document PDF_end_font PDF_end_glyph PDF_end_item PDF_end_layer PDF_end_page_ext PDF_end_page PDF_end_pattern PDF_end_template PDF_endpath PDF_fill_imageblock PDF_fill_pdfblock PDF_fill_stroke PDF_fill_textblock PDF_fill PDF_findfont PDF_fit_image PDF_fit_pdi_page PDF_fit_table PDF_fit_textflow PDF_fit_textline PDF_get_apiname PDF_get_buffer PDF_get_errmsg PDF_get_errnum PDF_get_font PDF_get_fontname PDF_get_fontsize PDF_get_image_height PDF_get_image_width PDF_get_majorversion PDF_get_minorversion PDF_get_parameter PDF_get_pdi_parameter PDF_get_pdi_value PDF_get_value PDF_info_font PDF_info_matchbox PDF_info_table PDF_info_textflow PDF_info_textline PDF_initgraphics PDF_lineto PDF_load_3ddata PDF_load_font PDF_load_iccprofile PDF_load_image PDF_makespotcolor PDF_moveto PDF_new PDF_open_ccitt PDF_open_file PDF_open_gif PDF_open_image_file PDF_open_image PDF_open_jpeg PDF_open_memory_image PDF_open_pdi_page PDF_open_pdi PDF_open_tiff PDF_pcos_get_number PDF_pcos_get_stream PDF_pcos_get_string PDF_place_image PDF_place_pdi_page PDF_process_pdi PDF_rect PDF_restore PDF_resume_page PDF_rotate PDF_save PDF_scale PDF_set_border_color PDF_set_border_dash PDF_set_border_style PDF_set_char_spacing PDF_set_duration PDF_set_gstate PDF_set_horiz_scaling PDF_set_info_author PDF_set_info_creator PDF_set_info_keywords PDF_set_info_subject PDF_set_info_title PDF_set_info PDF_set_layer_dependency PDF_set_leading PDF_set_parameter PDF_set_text_matrix PDF_set_text_pos PDF_set_text_rendering PDF_set_text_rise PDF_set_value PDF_set_word_spacing PDF_setcolor PDF_setdash PDF_setdashpattern PDF_setflat PDF_setfont PDF_setgray_fill PDF_setgray_stroke PDF_setgray PDF_setlinecap PDF_setlinejoin PDF_setlinewidth PDF_setmatrix PDF_setmiterlimit PDF_setpolydash PDF_setrgbcolor_fill PDF_setrgbcolor_stroke PDF_setrgbcolor PDF_shading_pattern PDF_shading PDF_shfill PDF_show_boxed PDF_show_xy PDF_show PDF_skew PDF_stringwidth PDF_stroke PDF_suspend_page PDF_translate PDF_utf16_to_utf8 PDF_utf32_to_utf16 PDF_utf8_to_utf16 |