galkahana/HummusJS

PDFHummus is working when I run it from visual studio but fail when using the executable

salentoq opened this issue · 7 comments

I am trying to use PDFHummus to generate a pdf that shows a plot, I put all the libs and dlls in the main folder and created a very simple pdf of one page with text and an image using this code:

#include <iostream>
#include <string>
// end standard library includes

// pdfwriter library includes
#include "PDFWriter.h"
#include "PDFPage.h"
#include "PageContentContext.h"
#include "PDFFormXObject.h"
#include "ResourcesDictionary.h"
// end pdfwriter library includes

using namespace PDFHummus;

int main(int argc, char** const argv) {
    // Step 1: Create a PDFWriter instance
    PDFWriter pdfWriter;
    if (pdfWriter.StartPDF("HelloWorld.pdf", ePDFVersion13) != PDFHummus::eSuccess)
        return;
    PDFPage* page = new PDFPage();
    page->SetMediaBox(PDFRectangle(0, 0, 791, 612));
    PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
    cxt->DrawImage(300, 570, "avent3.pdf");
//  cxt->DrawImage(300, 570, "avent3.png");
    PDFUsedFont* font = pdfWriter.GetFontForFile("times.ttf");
    AbstractContentContext::TextOptions textOptions(font, 14, AbstractContentContext::eGray, 0);
    cxt->WriteText(30, 570, "Hello World", textOptions);
    pdfWriter.EndPageContentContext(cxt);
    pdfWriter.WritePage(page);
    delete page;


    // Step 2 Close the PDF
    pdfWriter.EndPDF();

    return 0;
}

I added all libs to the linker and all the includes to the c++ part of the properties, when I run it from visual studio in release mode it works fine, but when I run the executable the pdf fails to create correctly (it creates the file but is corrupted).

If I comment all the insert image lines and leave only the text it works fine If I leave the text and insert the png file it works fine

is when I try to add the pdf vector image file that the executable stops working, but again, from visual studio it works fine. I think I am missing a dll that I have to add to the working folder but can't figure out which one

any ideas are surely appreciated

I suspect cxt->DrawImage(300, 570, "avent3.pdf"); is what is causing the problem, when I comment that line and use cxt->DrawImage(300, 570, "avent3.png"); instead everything works

Maybe it cant find a file. Maybe share a sample project?

Executablefolder
mainfolder

Thank you for your response, this is screenshots of my main folder and the executable folder

includes
libraries

And this is screenshot of the includes and libraries.

when run from Visual studio works great, not so much from the executable
The code is the one I put in the first post.

Im gonna need the files to recreate the problem. Otherwise cant help you.

Also, test with abs paths. Might be it cant find the pdf file to read it

And start up hummus with logs. Might be able to tell you something.
Example of creating logs:
https://github.com/galkahana/PDF-Writer/blob/master/PDFWriterTesting/HighLevelImages.cpp#L39

Sorry I didn't get back to you sooner I was out of town.

So the weirdest thing happened, I started a new project from scratch, and started adding the same lines of code I brought here and same files reported in the screenshots. I added a line and tested. At the end of the day the new project worked.

The only difference between the two projects is that when I was creating it on Visual Studio it asked me if I wanted the project in the same folder as the solution and the first time I said yes and the second time I said no.

I don't not why or even if that made the difference, I just put it here in case someone has the same problem could give it a try.

Thank you for your work and your help!!