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

Color inversion problem occurs when exporting images #234

Closed
yufeiran opened this issue Dec 1, 2023 · 1 comment
Closed

Color inversion problem occurs when exporting images #234

yufeiran opened this issue Dec 1, 2023 · 1 comment

Comments

@yufeiran
Copy link

yufeiran commented Dec 1, 2023

Thank you for developing this library! When our program uses your library, some pictures appear to be exported to pdf. When opening this file with CorelDraw, the picture has an inverted color problem.😂I try different version of pdf, all have this problem. I don't know how to sovle it.🤣Could this problem be caused by LibJpeg?
raw picture

1

happen inverted color problem in CorelDraw 2019:
image

I use this code and build with Visual Studio 2022,

#include <iostream>

#include<PDFWriter/PDFWriter.h>
#include<PDFWriter/PDFPage.h>
#include<PDFWriter/AbstractContentContext.h>
#include<PDFWriter/PageContentContext.h>


using namespace std;

int main()
{
	PDFWriter pdfWriter;

	string filePath = "helloPDF.pdf";

	if (pdfWriter.StartPDF(filePath.c_str(), ePDFVersion13) != eSuccess)
	{
		throw std::runtime_error("pdf create failed!");
	}

	string imagePath = "image/1.jpg";

	DoubleAndDoublePair jpgDimensions = pdfWriter.GetImageDimensions(imagePath);
	PDFPage* page = new PDFPage();

	page->SetMediaBox(PDFRectangle(0, 0, jpgDimensions.first, jpgDimensions.second));

	PageContentContext* cxt = pdfWriter.StartPageContentContext(page);


	cxt->DrawImage(10, 10, imagePath.c_str());
	pdfWriter.EndPageContentContext(cxt);
	pdfWriter.WritePageAndRelease(page);

	pdfWriter.EndPDF();

	string cmd = "start " + filePath;
	system(cmd.c_str());


	return 0;
}

the problem pic is below.
1

Thanks a lot!

@galkahana
Copy link
Owner

InvertedColorsJPG.pdf

I created the PDF file (attaching). I don't have coral draw, but opened it in acrobat reader and in chrome and it looks fine in both.
This might be something to ask Coral Draw then.

for the more specific question: JPGs are native in PDFS. you can pretty much embed them as is, which is what this library does, so no libjpg is involved here. libjpeg is only involved when parsing streams that are DCT encoded (examples are...embedding of jpg images), which is a fairly rare usage (you will, for example, use it when extracting images from a PDF).

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