libharu / libharu Goto Github PK
View Code? Open in Web Editor NEWlibharu - free PDF library
Home Page: http://libharu.org
License: zlib License
libharu - free PDF library
Home Page: http://libharu.org
License: zlib License
Hi,
I had a look at the repo check out but did not find any example code as to how one can use libharu to create a PDF file embedding U3D.
Cheers
I am using libharu for iPad pdf functionality and i want to display german text (specially Umlaut characters) on pdf using HPDF_Page_TextRect. i have tried various combinations in code but not get success to display umlaut characters (üöäÄÜÖß).
If you have any solution for my issue please provide me.
Do you have a compiled dll? I would like to use this with c# and the .net 3.5, is this supported?
There is a HPDF_Page_SetLeading() which allows setting the leading if using libharu to write whole blocks of text.
Similarly, there is HPDF_Font_GetAscent() and HPDF_Font_GetDescent() to read the maximum vertical extent of a particular font at a particular size.
However, there is no way to obtain the leading or line gap height of a font to know much vertical space to apply between baselines of successive lines of text.
I need this because I am typesetting a Bible with lots of typeface size changes, super-scripts and sub-scripts and the like, and the HPDF_Page_TextRect() doesn't meet my need. For example, I need to work out how much vertical space will be consumed on a page if I include an extra line of text, taking into account the additional cross-reference and foot-note text that will be rendered in a separate area of the page.
The provision of a simple HPDF_Font_GetLeading() or HPDF_Font_GetLineGap() function would meet my need. In the meantime, I may link my application against libfreetype for the sole purpose of obtaining the font leading/line gap information.
Paul.
When using HPDF_Image_LoadRawImageFromMem
with a 1bpp image, the resulting PDF is corrupted and cannot be opened by Acrobat Reader (other readers like Foxit are able to open it, but some image data is missing).
The issue is due to an error when computing the data size from the image dimensions on line 361 of hpdf_image.c
: this line should be:
size = ((width * bits_per_component + 7) / 8) * height;
(And a similar change should be made on lines 365 and 370).
I am not sure this was on purpose or not but it would be nice to have the libraries name be consistent between the shared and static libraries.
This can be fixed by adding the following line to your src/CMakeLists.txt:
set_target_properties(${LIBHPDF_NAME_STATIC} PROPERTIES OUTPUT_NAME ${LIBHPDF_NAME})
This would go after the line:
add_library(${LIBHPDF_NAME_STATIC} STATIC ${LIBHPDF_SRCS})
Under Mac OSX a lot of fonts have only the cmap platform 0, encoding 3, format 4 (unicode platform, unicode encoding) and not the platform 0, encoding 3, format 4. Since the format 4 is already know, could we load this cmap as the one for platform 1 (windows platform, unicode encoding)?
I did some tests, and it seem to work, but I'm don't know the differences between the two encodings. Just a couple of fonts (i.e. Chalkduster), that doesn't have the table 'cvt ' doesn't work.
--- hpdf_fontdef_tt.c (5622)
+++ hpdf_fontdef_tt.c (5623)
@@ -874,6 +874,7 @@
HPDF_UINT16 num_cmap;
HPDF_UINT i;
HPDF_UINT32 ms_unicode_encoding_offset = 0;
+ HPDF_UINT32 up_unicode_encoding_offset = 0;
HPDF_UINT32 byte_encoding_offset = 0;
HPDF_PTRACE ((" HPDF_TTFontDef_ParseCMap\n"));
@@ -936,6 +937,10 @@
if (platformID == 1 && encodingID ==0 && format == 1)
byte_encoding_offset = offset;
+ /* Unicode-Unicode-CMAP will be used if MS-Unicode-CMAP is not found */
+ if (platformID == 0 && encodingID ==3 && format == 4)
+ up_unicode_encoding_offset = offset;
+
ret = HPDF_Stream_Seek (attr->stream, save_offset, HPDF_SEEK_SET);
if (ret != HPDF_OK)
return ret;
@@ -948,6 +953,9 @@
} else if (byte_encoding_offset != 0) {
HPDF_PTRACE((" found byte encoding cmap.\n"));
ret = ParseCMAP_format0(fontdef, byte_encoding_offset + tbl->offset);
+ } else if (up_unicode_encoding_offset != 0) {
+ HPDF_PTRACE((" found unicode platform unicode encoding cmap.\n"));
+ ret = ParseCMAP_format4(fontdef, up_unicode_encoding_offset + tbl->offset);
} else {
HPDF_PTRACE((" cannot found target cmap.\n"));
return HPDF_SetError (fontdef->error, HPDF_TTF_INVALID_FOMAT, 0);
When will you release next version of libharu that will support UTF-8?
I need UTF-8 in my php application, because all content is multilingual. Will you release new extension for PHP? LibHaru is great alternative for paid PDF library for PHP.
When trying to include this package in yocto, qa_configure step reports failure if it finds the below string pattern in config.log
grep -e 'CROSS COMPILE Badness:' -e 'is unsafe for cross-compilation'
This issue is applicable for both 2.2.1 and 2.3.0RC2 series. I'll send a pull request shortly
I've noticed a potential bug in the HPDF_Info_SetInfoDateAttr().
According to the documentation, if the ind member of HPDF_Date is ' ' the members off_hour and off_minutes are ignored. However, according to the actual code, as seen in the code below, in hpdf_info.c (lines 109 - 119), this is not really so.
if (value.month < 1 || 12 < value.month ||
value.day < 1 ||
23 < value.hour ||
59 < value.minutes ||
59 < value.seconds ||
(value.ind != '+' && value.ind != '-' && value.ind != 'Z' &&
value.ind != ' ') ||
23 < value.off_hour ||
59 < value.off_minutes) {
return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
}
A close look reveals that AS LONG AS either value.off_hour is NOT less than 23 or value.off_minutes is NOT less than 59, HPDF_INVALID_DATE_TIME will be returned.
The bug was found in a Release Build of a project that uses the libharu library because in Release mode the members off_hour and off_minutes, when uninitialized, carry an arbitrary large positive value.
In debug builds the issue was never seen because the members, when uninitialized, carry an arbitrary large negative value.
Which also brings up another issue: the code section does not check for invalid negative values.
Below is a suggested fix:
if (value.month < 1 || 12 < value.month ||
value.day < 1 ||
23 < value.hour ||
59 < value.minutes ||
59 < value.seconds ||
(value.ind != '+' && value.ind != '-' && value.ind != 'Z' &&
value.ind != ' ') ||
(23 < value.off_hour && value.ind != ' ') ||
(59 < value.off_minutes && value.ind != ' ')
) {
return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
}
The issue can be avoided in code that calls HPDF_Info_SetInfoDateAttr() buy initializing the members off_hour and off_minutes to 0 if ind == ' ', which is what I have done in my code. I had not bothered initializing them because I took the documentation literally on the "are ignored" part..
I make command:
D:\Program Files\Microsoft Visual Studio\VC98\Bin>
nmake -f d:\LibHaru\ClassLibCo
de\libharu-RELEASE_2_2_0\script\Makefile.mingw_dll
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
NMAKE : fatal error U1073: don't know how to make 'src/hpdf_utils.o'
Stop.
Currently, HPDF_TextAlignment has LEFT, RIGHT, CENTER and JUSTIFY options. Would be nice to have TOP, BOTTOM and MIDDLE as well.
Commit 256dfd3 has the necessary changes.
Changed HPDF_Page_TextRect to support multiple flags. For example, to place text in the center-middle of a rectangle, HPDF_TALIGN_CENTER | HPDF_TALIGN_MIDDLE can be passed to HPDF_Page_TextRect.
libharu 2.3.0RC2
OS: dragonflyBSD
configure OK
make OK
ldd says:
/usr/local/lib/libhpdf.so:
libz.so.3 => /usr/lib/libz.so.3 (0x800e20000)
libpng16.so.16 => /usr/pkg/lib/libpng16.so.16 (0x801034000)
libc.so.7 => /usr/lib/libc.so.7 (0x80081d000)
libm.so.3 => /usr/lib/libm.so.3 (0x801276000)
BUT
HPDF_LoadPngImageFromFile() says:
0x1062 "unsupported function"
Hi,
I'm planning to modify the 'HPDF_Page_TextRect' function so it would count the used lines to print the entire text, and multiply that value with the textheight+linespacing to calculate the bottom value.
This should allow a program to print a variable text length and draw a box/border around it.
But i can't seem to figure out how to HPDF_Box uses the bottom-value.
Any help or pointers on this matter are highly appreciated!
With kind Regards,
DeJakke.
Hi.
I think the function HPDF_Page_SetDash is wrong. In PDF documents, the elements of the dash pattern array can be real numbers.
The dash phase can be a real number also. Maybe the libharu function must be changed to operate correctly.
Regards,
Dome
The font name MS-Mincyo and MS-PMincyo in file /libharu/demo/jpfont_demo.c is giving exception. It should be MS-Mincho and MS-PMincho.
Build instructions do not work under GNU/Linux; there is no file named "config" anywhere in the tarball libharu-libharu-22e741e.tar.gz.
I found that libharu version 2.3 RC1 has this issue:
Added support for 3dMeasures of subtype PD3 and 3DC, projection annotations, ExData and javascript attached to a U3D model. (Robert Würfel)
I can't find the example of doing this.
Can anyone help me with utilizing u3d and javascript files?
Where can I get the examples of these?
Thank you.
Anybody would like to help me ? Please describe detailed .Thanks a lot!
The link to the docs at /doc/README is broken.
I am using bcc32 and have been able to compile and link libhpdf.dll
However, when I try to run the makefile with the "demo" switch, I get an error:
Error E2303 include\hpdf.h 464: Type name expected
File hpdf.h:
459 HPDF_EXPORT(HPDF_XObject)
460 HPDF_Page_CreateXObjectFromImage (HPDF_Doc pdf,
461 HPDF_Page page,
462 HPDF_Rect rect,
463 HPDF_Image image,
464 HPDF_Boolean zoom);
HPDF_Boolean is defined in hpdf_objects.h as a pointer to a structure:
typedef struct _HPDF_Boolean_Rec *HPDF_Boolean;
typedef struct _HPDF_Boolean_Rec {
HPDF_Obj_Header header;
HPDF_BOOL value;
} HPDF_Boolean_Rec;
What is wrong here?
Tried installing verions 2.2.0 and 2.2.1 from source to Fedora server. In both cases, errors:
hpdf_image_png.c: In function âReadPngData_Interlacedâ:
...
hpdf_image_png.c:138:44: error: dereferencing pointer to incomplete type
hpdf_image_png.c: In function âReadPngDataâ:
hpdf_image_png.c:159:44: error: dereferencing pointer to incomplete type
hpdf_image_png.c: In function âReadTransparentPaletteDataâ:
...
hpdf_image_png.c:215:61: error: dereferencing pointer to incomplete type
hpdf_image_png.c:222:37: error: dereferencing pointer to incomplete type
hpdf_image_png.c: In function âReadTransparentPngDataâ:
...
hpdf_image_png.c:291:29: error: dereferencing pointer to incomplete type
hpdf_image_png.c:294:25: error: dereferencing pointer to incomplete type
hpdf_image_png.c:309:37: error: dereferencing pointer to incomplete type
hpdf_image_png.c: In function âLoadPngDataâ:
...
hpdf_image_png.c:629:24: error: dereferencing pointer to incomplete type
make[1]: *** [hpdf_image_png.lo] Error 1
make[1]: Leaving directory `/etc/libharu-2.2.0/src'
make: *** [all-recursive] Error 1
Used version of libharu/libpdf: 2.3.0RC2
gcc 4.7.1
compilation flags: -Wall -Wstrict-aliasing=2 -Werror -O3
I usually use a bleeding edge distro (ArchLinux in this case) and new compilers with paranoic flags to discover
bugs early.
I got:
hpdf_encrypt.c: In function ‘HPDF_MD5Update’:
hpdf_encrypt.c:107:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
hpdf_encrypt.c:116:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
hpdf_encrypt.c: In function ‘HPDF_MD5Final’:
hpdf_encrypt.c:154:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
hpdf_encrypt.c:165:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
hpdf_encrypt.c:166:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
hpdf_encrypt.c:168:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
cc1: all warnings being treated as errors
Hotfix in include/pdf_types.h (this only tames the compiler errors, the root problem persists):
typedef signed int HPDF_INT32;
typedef unsigned int MAY_ALIAS HPDF_UINT32;
hpdf_font_cid.c:644:19: error: variable ‘last_btype’ set but not used [-Werror=unused-but-set-variable]
added to hpdf_font_cid.c:
and
HPDF_UNUSED( last_btype );
in function 'MeasureText'.
hpdf_image_png.c: In function ‘LoadPngData’:
hpdf_image_png.c:303:27: error: ‘row’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
hpdf_image_png.c:243:22: note: ‘row’ was declared here
Not sure, if initializing row to 0 is the right thing to do?
hpdf_u3d.c:165:24: error: ‘type’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
This is a rather annoying one, as the code is pretty ok. Dummy initialization of '*type = NULL' in Get3DStreamType
silences the warning.
I would like to create pdf file using C.
I installed haru library as per the installation step.
But I could not able to build sample code in Ubuntu12.04.
I use command to run sample code is ,
gcc-o result.o test_code.c
I found following error,
/tmp/ccCzocHH.o: In function main': test_code.c:(.text+0xbf): undefined reference to
HPDF_New'
test_code.c:(.text+0xfc): undefined reference to HPDF_Free' test_code.c:(.text+0x112): undefined reference to
HPDF_AddPage'
test_code.c:(.text+0x122): undefined reference to HPDF_Page_GetHeight' test_code.c:(.text+0x132): undefined reference to
HPDF_Page_GetWidth'
test_code.c:(.text+0x14b): undefined reference to HPDF_Page_SetLineWidth' test_code.c:(.text+0x18b): undefined reference to
HPDF_Page_Rectangle'
test_code.c:(.text+0x197): undefined reference to HPDF_Page_Stroke' test_code.c:(.text+0x1b3): undefined reference to
HPDF_GetFont'
test_code.c:(.text+0x1d4): undefined reference to HPDF_Page_SetFontAndSize' test_code.c:(.text+0x1e8): undefined reference to
HPDF_Page_TextWidth'
test_code.c:(.text+0x1f8): undefined reference to HPDF_Page_BeginText' test_code.c:(.text+0x232): undefined reference to
HPDF_Page_TextOut'
test_code.c:(.text+0x23e): undefined reference to HPDF_Page_EndText' test_code.c:(.text+0x24a): undefined reference to
HPDF_Page_BeginText'
test_code.c:(.text+0x267): undefined reference to HPDF_Page_SetFontAndSize' test_code.c:(.text+0x294): undefined reference to
HPDF_Page_TextOut'
test_code.c:(.text+0x2a0): undefined reference to HPDF_Page_EndText' test_code.c:(.text+0x2ac): undefined reference to
HPDF_Page_BeginText'
test_code.c:(.text+0x2d1): undefined reference to HPDF_Page_MoveTextPos' test_code.c:(.text+0x309): undefined reference to
HPDF_GetFont'
test_code.c:(.text+0x32a): undefined reference to HPDF_Page_SetFontAndSize' test_code.c:(.text+0x345): undefined reference to
HPDF_Page_ShowText'
test_code.c:(.text+0x363): undefined reference to HPDF_Page_MoveTextPos' test_code.c:(.text+0x380): undefined reference to
HPDF_Page_SetFontAndSize'
test_code.c:(.text+0x394): undefined reference to HPDF_Page_ShowText' test_code.c:(.text+0x3b2): undefined reference to
HPDF_Page_MoveTextPos'
test_code.c:(.text+0x3d6): undefined reference to HPDF_Page_EndText' test_code.c:(.text+0x3ea): undefined reference to
HPDF_SaveToFile'
test_code.c:(.text+0x3f6): undefined reference to `HPDF_Free'
collect2: ld returned 1 exit status
can anybody help me?
Hello.
I have noticed that one of the items in the HPDF_LineCap enum is not correct.
The HPDF_PROJECTING_SCUARE_END
item should be HPDF_PROJECTING_SQUARE_END
.
Fixing this would break the API so perhaps it is a good idea to do it in a major version release.
Filling an closed polygon with a gradient color is very common, but this is not supported, I wish you can add this function.
Hi, I downloaded the tar.gz file from http://libharu.org/. When looking for a "configure" file, there's none. I tried buildconf.sh and think I got a good one, however, I now can't find a Makefile...
I was following the "configure && make && make install" instructions.
Thank you.
By the way, I'm on linux/gcc
HPDF_REAL_LEN's is defined as 11, under some circumstance, this is too small. 20 will be good.
The source code tree is missing the configure script for Linux.
In Libharu 2.2.1
Non-initialized local variable, isize, in the service HPDF_GetContents
When a font is "Bold" or "Italic" or "BoldItalic", the base_font is assigned with 'font name'+'style name', this causes lots of problems.
for example: font Arial Gras, its unique real name is "Arial-BoldMT", which Adobe's software use it as internal font name. but in here the base_font is "Arial-BoldMT,Bold", why add the subfamily name on it? "Arial-BoldMT" is enough.
I wish you can remove the extra part.
Hello,
I need to restrict the text that can be written in a block. To do so, I use HPDF_Page_MeasureText
to get the number of char that can be written in my rect. I also need to find out the height of my text so I can know the number of lines that I will be able to write (number of char * number of lines).
I tried to use HPDF_Font_GetCapHeight
but this gave me a huge number (725 or something) , this is for sure not the height of the text I try to print.
To summarise, I know the font, the font size of my text and I need to know the height of it before printing it.
Any pointers ?
Cheers
whenever I have multiple number of page to be created every time I get from pdf. HPDF_SaveToFile (pdfDoc,fileName); funcation is 0x1025,while in case single page pdf is created.
I am using haru pdf generator in an Android app.
Hi there,
thanks for your nice library.
I encountered a small mistake while drawing a composite character, such as сyrillic characters Ё
, which consists of a number of nested composite characters.
Recursive call CheckCompositGryph should solve this problem:
CheckCompositGryph
if (glyph_index > 0 && glyph_index < attr->num_glyphs) {
HPDF_INT32 pos = HPDF_Stream_Tell(attr->stream);
if (!attr->glyph_tbl.flgs[glyph_index])
CheckCompositGryph (fontdef, glyph_index);
HPDF_Stream_Seek (attr->stream, pos, HPDF_SEEK_SET);
attr->glyph_tbl.flgs[glyph_index] = 1;
}
Hi.
I'm using HPDF_LoadTTFontFromFile with embedding=HPDF_TRUE. I noticed that Libharu embeds all the glyph data (used and used) in the resulting pdf file. I think it should embed only those portion of the TrueType font that are need for the generation of the document and not only mark them with a width of 0 in the font dictionary.
What's this piece of CMake code supposed to do?
install(FILES README CHANGES INSTALL DESTINATION .)
if(NOT DEVPAK)
install(DIRECTORY if DESTINATION .)
endif(NOT DEVPAK)
for me it installs if
directory and documentation into ${PREFIX}, (e.g. /usr/{README,CHANGES,INSTALL,if), I really doubt that is indented behavior.
I've never built libharu on this system, and I suspect that the following line, from demo/CMakeLists.txt, is trying to locate libharu from standard linker search paths (i.e., a previously built/installed version)
If this is true, then you might be able to set a CMake variable that points to ${CMAKE_BINARY_DIR}/libharu.[a|so] during the build of the library, and later link directly to that when building the demo.
At any rate, building using CMake without having libharu installed fails to find libharu for linking:
/usr/bin/ld: cannot find -llibharu
unfortunately the font_measure function does not split the words correctly.
although i set the wordwrap boolean HPDF_TRUE the function returns splitted words.
Hi
Courier and Courier-Bold fonts don't display C WITH CARON , AND c WITH CARON in WIN1250 encoding.
Other fonts (HELVETICA,TIMES,..) are OK.
Regards,
Franček
HPDF_COMP_NONE
;HPDF_Image_LoadRaw1BitImageFromMem
or HPDF_LoadRawImageFromMem
(actually, the two are equivalent since the latter calls the former when it is given a binary image);A PDF file containing an uncompressed binary image.
A PDF file containing some noise and a large white area. Analysis of this PDF suggests that the image data was compressed with CCITT but that the corresponding /Filter
was not set.
Version: 2.3.0
For some PNGs "png_get_tRNS" returns num_trans=1 and trans=NULL. In that case an access violation occurs in function ReadTransparentPaletteData becase there is a "<num_trans" check that will be true for 0. hpdf_image_png.c, line 224:
smask_data[width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
I have fixed this by adding following lines after "png_get_tRNS". hpdf_image_png.c, line 491:
if (trans == NULL)
goto no_transparent_color_in_palette;
The reason why the problem happens is because PNG_COLOR_TYPE_PALETTE is defined as (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE). But the code only supports the PNG_COLOR_MASK_PALETTE case but not the PNG_COLOR_MASK_COLOR one.
Hi Tony,
I' m getting trouble with HPDF_Page_TextRect
based on Chinese text (cp936) if the input Chinese line exceed rectangle width, it return HPDF_PAGE_INSUFFICIENT_SPACE
.
demo/mbtext/cp936_t.txt include:
早上好,多关照。早上好,多关照。早上好,多关照。
Test code based on text_demo2
:
HPDF_UseCNSEncodings (pdf);
HPDF_UseCNSFonts (pdf);
HPDF_Font font = HPDF_GetFont (pdf, "SimSun", "GB-EUC-H");
HPDF_Rect rect;
/* HPDF_TALIGN_LEFT */
rect.left = 25;
rect.top = 545;
rect.right = 200;
rect.bottom = rect.top - 40;
HPDF_Page_SetCMYKStroke(page,0,1,1,0.07);
HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
rect.top - rect.bottom);
HPDF_Page_Stroke (page);
HPDF_Page_BeginText (page);
HPDF_STATUS ret = HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
text, HPDF_TALIGN_LEFT, NULL);
if (ret != HPDF_OK) printf("Bad return code=%d!\n", ret);
HPDF_Page_EndText (page);
However, with below input, it worked:
早上好,多关照。早上好,多关照。早上好,多 关照。
^
Note: ^ denote space between 2 Chinese word.
I didn't see multibyte lang demo of exceeding rectangle width. Within text_demo2
, it only demoed English Character.
Have a basic debug, I found this issue came from multibyte calculation issue in hpdf_font_cid.c
:
static HPDF_UINT
MeasureText (HPDF_Font font,
const HPDF_BYTE *text,
HPDF_UINT len,
HPDF_REAL width,
HPDF_REAL font_size,
HPDF_REAL char_space,
HPDF_REAL word_space,
HPDF_BOOL wordwrap,
HPDF_REAL *real_width)
sorry, I am new to font encoding, pls help look into this issue.
Thanks and Regards
njman
There is a bug in the lookup table HPDF_UNICODE_MAP_WIN_ANSI (at position 176). Degree sign is defined as Unicode character 0x02DA which is a "Ring Above" instead a degree sign (0x00B0). It works if you define "CP1252" instead of "WinAnsiEncoding" because there is a table HPDF_UNICODE_MAP_CP1252 that overwrites the degree sign. However the PDF standard defines "WinAnsiEncoding" as "CP1252" therefore HPDF_UNICODE_MAP_CP1252 should not exist at all (see Adobe Document management, Portable document format, Part 1: PDF 1.7).
On Windows, I'm getting Error:1017 when try to save to file one pdf doc in a path with japanese username.
Hi, I know this to be a very noob question but I dont know how to use libharu in my Eclipse C++ and use it in my project. My OS is windows. I downloaded libharu-RELEASE_2_2_0 and dont know where to read further instructions. Thanks in advance
here is a patch to fix it:
diff --git a/src/hpdf_doc_png.c b/src/hpdf_doc_png.c
index bad87c6..f1daf26 100644
--- a/src/hpdf_doc_png.c
+++ b/src/hpdf_doc_png.c
@@ -155,15 +155,21 @@ LoadPngImageFromStream (HPDF_Doc pdf,
HPDF_BOOL delayed_loading)
{
HPDF_Image image;
HPDF_PTRACE ((" HPDF_LoadPngImageFromStream\n"));
image = HPDF_Image_LoadPngImage (pdf->mmgr, imagedata, pdf->xref,
delayed_loading);
// is there an alpha layer? then compress it also
smask = HPDF_Dict_GetItem(image, "SMask", HPDF_OCLASS_DICT);
if (smask) smask->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
return image;
}
I have a several PNG files that libharu fails to load.
One of them (crash.png) causes a crash.
After calling
...
HPDF_Image image = HPDF_LoadPngImageFromFile(pdf, filepath);
if(image == 0)
{
HPDF_Free(pdf); // crash here!!!
}
...
The other two files (fail_to_load1.png, fail_to_load2.png) do not crash when 'HPDF_Free()' is call.
p.s I have no problem opening and seeing these three files using image viewer applications, or Photoshop.
(gdb) bt
#0 0x00007ffff4903d37 in HPDF_String_Cmp (s1=0x65c5a0, s2=0x0) at hpdf_string.c:199
#1 0x00007ffff48f51e1 in HPDF_NameTree_Add (tree=0x660e40, name=0x65c5a0, obj=0x65bb50) at hpdf_namedict.c:154
#2 0x00007ffff48dba01 in HPDF_AttachFile (pdf=0x651010, file=0x6552b8 "./attach.bin") at hpdf_doc.c:1970
#3 0x000000000040191b in main (argc=<optimized out>, argv=<optimized out>) at testharu.cpp:101
(gdb) p s1
$1 = (HPDF_String) 0x65c5a0
(gdb) p s2
$2 = (HPDF_String) 0x0
(gdb) f 1
#1 0x00007ffff48f51e1 in HPDF_NameTree_Add (tree=0x660e40, name=0x65c5a0, obj=0x65bb50) at hpdf_namedict.c:154
154 if (i == 0 || HPDF_String_Cmp(name, elem) < 0) {
(gdb) p elem
$3 = (HPDF_String) 0x0
(gdb) f 2
#2 0x00007ffff48dba01 in HPDF_AttachFile (pdf=0x651010, file=0x6552b8 "./attach.bin") at hpdf_doc.c:1970
1970 ret += HPDF_NameTree_Add (ntree, name, efile);
(gdb) p ntree
$4 = (HPDF_NameTree) 0x660e40
(gdb) p name
$5 = (HPDF_String) 0x65c5a0
(gdb) p efile
$6 = (HPDF_EmbeddedFile) 0x65bb50
Apparently in the following code, elem can end up being NULL:
116 HPDF_STATUS
117 HPDF_NameTree_Add (HPDF_NameTree tree,
118 HPDF_String name,
119 void *obj)
120 {
121 HPDF_Array items;
122 HPDF_INT32 i, icount;
123
124 if (!tree || !name)
125 return HPDF_INVALID_PARAMETER;
126
127 items = HPDF_Dict_GetItem (tree, "Names", HPDF_OCLASS_ARRAY);
128 if (!items)
129 return HPDF_INVALID_OBJECT;
130
131 /* "The keys shall be sorted in lexical order" -- 7.9.6, Name Trees.
132 * Since we store keys sorted, it's best to do a linear insertion sort
133 * Find the first element larger than 'key', and insert 'key' and then
134 * 'obj' into the items. */
135
136 icount = HPDF_Array_Items(items);
137
138 /* If we're larger than the last element, append */
139 if (icount) {
140 HPDF_String last = HPDF_Array_GetItem(items, icount - 2, HPDF_OCLASS_STRING);
141
142 if (HPDF_String_Cmp(name, last) > 0) {
143 HPDF_Array_Add(items, name);
144 HPDF_Array_Add(items, obj);
145 return HPDF_OK;
146 }
147 }
148
149 /* Walk backwards through the list until we're smaller than an element=
150 * That's the element to insert in front of. */
151 for (i = icount - 4; i >= 0; i -= 2) {
152 HPDF_String elem = HPDF_Array_GetItem(items, i, HPDF_OCLASS_STRING);
153
154 if (i == 0 || HPDF_String_Cmp(name, elem) < 0) {
155 HPDF_Array_Insert(items, elem, name);
156 HPDF_Array_Insert(items, elem, obj);
157 return HPDF_OK;
158 }
159 }
160
161 /* Items list is empty */
162 HPDF_Array_Add(items, name);
163 HPDF_Array_Add(items, obj);
164 return HPDF_OK;
165 }
Steps to reproduce:
HPDF_AttachFile (pdf, "./att/part0.bin");
HPDF_AttachFile (pdf, "./att/part1.bin");
HPDF_AttachFile (pdf, "./att/old_err.pdf");
HPDF_AttachFile (pdf, "./att/10.jpg");
HPDF_AttachFile (pdf, "./att/part2.bin");
The content itself seems to be irrelevant: I've zeroed the files size and the issue persists, so it has to be name-related. Also, changing the order (for example, putting old_err.pdf first) seems to take care of the crash, but the attachments are nowhere to be seen in Acrobat Reader's attachments list.
My project's makefile downloads a copy of libharu-2.2.1 and builds it if not present in the developer environment (and that includes every clean overnight build on the CI server).
As of midnight on 16 Jan 2013, the link no longer works:
wget http://libharu.org/files/libharu-2.2.1.tar.gz
...
HTTP request sent, awaiting response... 404 Not Found
The tarball URL on the Libharu home page http://libharu.org/ now points to https://github.com/libharu/libharu/tarball/master and this in turn redirects to the current release, libharu-libharu-RELEASE_2_3_0RC2-21-g915f130.tar.gz.
Unfortunately the wget command doesn't appear to be able to handle https URLs. Is there a suitable mirror from which to download this archive?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.