Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
salentoq opened this issue Nov 14, 2023 · 7 comments

Comments

@salentoq
Copy link

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

@salentoq
Copy link
Author

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

@galkahana
Copy link
Owner

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

@salentoq
Copy link
Author

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.

@galkahana
Copy link
Owner

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

@galkahana
Copy link
Owner

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

@galkahana
Copy link
Owner

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

@salentoq
Copy link
Author

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants