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

PDF page Extents are too Small #165

Open
ghernando opened this issue Sep 11, 2019 · 1 comment
Open

PDF page Extents are too Small #165

ghernando opened this issue Sep 11, 2019 · 1 comment

Comments

@ghernando
Copy link

I am new to the project and would like to be able to stamp all the pages of a PDF with some text.
I was following some of the C++ examples that use ModifyPDF.
I expected the MediaBox to be the extents of the PDF page, but it seems to be very small.
The size of the sample file I have reports a MediaBox to be 2016 x 2880.
But the actual page seems to be much bigger.
I think maybe I am not correctly acquiring the page.
Could you please suggest what I might be doing wrong?

testfile.pdf
`
pdfWriter.ModifyPDF("./testfile.pdf", ePDFVersion15, "", LogConfiguration(true, true, "SimpleTextUsage.log", PDFCreationSettings(true, inEmbedFonts));

	PDFUsedFont* f = pdfWriter.GetFontForFile(
		RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,
		"TestMaterials/fonts/arial.ttf"));
	PDFParser& modifiedFileParser = pdfWriter.GetModifiedFileParser();

	for (unsigned long i = 0; i < modifiedFileParser.GetPagesCount(); ++i)
	{
		ObjectIDType PageID = modifiedFileParser.GetPageObjectID(i);
		PDFObject* page = modifiedFileParser.ParsePage(i);

		PDFModifiedPage modifiedPage(&pdfWriter, i);

		PageContentContext* contentContext = (PageContentContext*)modifiedPage.StartContentContext();
		AbstractContentContext::TextOptions opt(f, 50, AbstractContentContext::eRGB, 0xFF45DE);

		contentContext->WriteText(75, 105, "Test Text that is supercalofragolisticly long....  I mean really long to see if it goes off the page...", opt);

		PDFPageInput pageInput = PDFPageInput(&modifiedFileParser, page);
		PDFRectangle cropBox = pageInput.GetCropBox();
		PDFRectangle mediaBox = pageInput.GetMediaBox();
		contentContext->DrawRectangle(cropBox.LowerLeftX, cropBox.LowerLeftY, cropBox.UpperRightX, cropBox.UpperRightY);
		cout << mediaBox.UpperRightX - mediaBox.LowerLeftX << " " << mediaBox.UpperRightY - mediaBox.LowerLeftY << "\n";

		modifiedPage.EndContentContext();
		modifiedPage.WritePage();
	}
	status = pdfWriter.EndPDF();`
@HaerBugMaker
Copy link

Hello,I meet the same problem,Did you solve it.Looking forward to your reply,:)

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