problem in print (white rectangle in page)

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
aleksand
User
Posts: 15
Joined: Tue Apr 24, 2018 6:55 am

problem in print (white rectangle in page)

Post by aleksand »

print.pdf
test.pdf
Hi,
I have some PDF files (test.pdf is an example of such document) that I can't print correctly with C++ Core Api. The problem is that when I start printing this document in my application (it's a Java application that loads DLLs) it prints incorrectly (see print.pdf). On the first page you can see a white rectangle in the middle of the page. As far as I understand, it exists in the PDF, but it should be printed under the text. I tested this file with your Core Api test exe (the latest one) and it prints correctly. Then I compiled the MFCSample project, use the downloaded dll from my project (PDFXCoreAPI.x64.dll) and try again. The result is good again. I copied 2 methods from MFCSample (open and print document) and put them in my print method (it opens this hardcoded path to document and then prints) but the result was bad (white rectangle exists). I have the same bad result even if I open another file in my application (so no hash). As a result, the same code can give different results (maybe it depends on the project settings or loading (calling) some other PDFXCoreAPI.x64.dll methods, but I don't understand why it is critical).
Can you help me?

Thanks,
Evgeny.
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19856
Joined: Mon Jan 12, 2009 8:07 am

Re: problem in print (white rectangle in page)

Post by Stefan - PDF-XChange »

Hello aleksand,

Can you please let us know which build of our products are you currently using?
There seems to be an image object at that section of your page:
image.png
Which when the rest of the image data is removed does not leave much content left:
image(1).png
And it should be with a transparent background:
image(2).png
However I am not sure why on your end it is printed opaque.

It could be an issue with an older build, or with the printer handling the print job, so can you please try with different drivers for that printer (if avaiable)?

Alternatively - you should also be able to use "Print as image" in the settings on our SDK side.

I've just ran some tests with the current latest build (396) and your file prints fine on my end.

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
aleksand
User
Posts: 15
Joined: Tue Apr 24, 2018 6:55 am

Re: problem in print (white rectangle in page)

Post by aleksand »

Hello Stefan,
I use PDFXCoreAPI.x64.dll (10.5.2.395), but problem was exist in version of 2021 year.

About Rectangle (transparent background) I this you are right. As far as I understand, it is also often used (probably for protection) when creating a QR code (breaking the whole picture into overlapping parts).

I can not reproduce problem on your project from examples (MFCSample). I use Adobe PDF printer (but test on PDF 24 printer too). I see big difference between size of output pdf from your test application and my DLL. Your size is 1205204. My is 713452. I do not understand why it is happens because code for open and print is the same.

Problem that when I copy these 2 methods from MFCSample on my dll the problem still exists:

Code: Select all

void PrintDoc(PXC::IPXC_Document* pDoc, HWND hWnd)
{
	if (pDoc == nullptr)
		return;

	CComPtr<PXC::IPXC_Pages> pPages;
	HRESULT hr = pDoc->get_Pages(&pPages);
	if (FAILED(hr))
		return;

	DWORD pagescount = 0;
	hr = pPages->get_Count(&pagescount);
	if (FAILED(hr))
		return;
	//
	PRINTDLG pdlg = { sizeof(PRINTDLG) };
	//
	pdlg.hwndOwner = hWnd;
	pdlg.Flags = PD_NOSELECTION | PD_RETURNDC;
	pdlg.nMinPage = 1;
	pdlg.nMaxPage = (WORD)pagescount;
	pdlg.nCopies = 1;

	if (!PrintDlg(&pdlg))
		return;
	DWORD nStartPage = 1;
	DWORD nEndPage = pagescount;
	if (pdlg.Flags & PD_PAGENUMS)
	{
		nStartPage = pdlg.nFromPage;
		nEndPage = pdlg.nToPage;
	}
	nStartPage--;
	nEndPage--;
	size_t i;

	DOCINFO di = { sizeof(DOCINFO) };
	di.lpszDocName = _T("PXC-View PDF Print");
	// Now Getting Information from DC
	SIZE physicalSize;
	SIZE margin;
	SIZE printigSize;
	physicalSize.cx = GetDeviceCaps(pdlg.hDC, PHYSICALWIDTH);
	physicalSize.cy = GetDeviceCaps(pdlg.hDC, PHYSICALHEIGHT);
	margin.cx = GetDeviceCaps(pdlg.hDC, PHYSICALOFFSETX);
	margin.cy = GetDeviceCaps(pdlg.hDC, PHYSICALOFFSETY);
	printigSize.cx = GetDeviceCaps(pdlg.hDC, HORZRES);
	printigSize.cy = GetDeviceCaps(pdlg.hDC, VERTRES);
	//
	CRect or_prect;
	or_prect.left = margin.cx;
	or_prect.right = or_prect.left + printigSize.cx;
	or_prect.top = margin.cy;
	or_prect.bottom = or_prect.top + printigSize.cy;
	//
	if (::StartDoc(pdlg.hDC, &di) > 0)
	{

		for (i = nStartPage; i <= nEndPage; i++)
		{
			::StartPage(pdlg.hDC);
			//
			CComPtr<PXC::IPXC_Page> pPage;
			hr = pPages->get_Item((PXC::ULONG_T)i, &pPage);
			if (FAILED(hr))
				return;

			//double doc_page_w, doc_page_h;
			//hr = pPage->GetDimension(&doc_page_w, &doc_page_h);
			//if (FAILED(hr))
			//	return;
			//PXC::PXC_Matrix dm = {0};
			//pPage->GetMatrix(PXC::PBox_MediaBox, &dm);
			//dm.e -= or_prect.left;
			//dm.f -= or_prect.top;
			CRect DrawRect(0, 0, or_prect.Width(), or_prect.Height());
			CComPtr<PXC::IPXC_OCContext> pROpt;
			g_Inst->CreateStdOCCtx(&pROpt);
			pROpt->put_PrintContentFlags(PXC::RenderType_ModePrint);
			// when matrix is not provided, entire page will be rendred to fit DrawRect
			// matrix is required only if we need to render portion of the page.
			// In this case Cropbox rect of the page is transformed by the matrix,
			// and only portion of the page that after transofmation is in DrawRect will be printed
			pPage->DrawToDevice((PXC::HANDLE_T)pdlg.hDC, DrawRect, /*&dm*/nullptr, PXC::DDF_AsVector, nullptr, pROpt, nullptr);
			::EndPage(pdlg.hDC);
		}
		::EndDoc(pdlg.hDC);
	}
	DeleteDC(pdlg.hDC);
}

Code: Select all

HRESULT OpenDocFromFile(LPCWSTR sFileName, CComPtr<PXC::IPXC_Document>& pDoc, PXC::IPXC_Inst* g_Inst)
{
	HRESULT hr = S_OK;
	pDoc = nullptr;
	do
	{
		//BreakOnNull(g_Inst, hr, E_FAIL, L"SDK not initialized");
		CDocAuthCallback authCallback;
		PXC::IPXC_DocAuthCallback* pAuthCallback = (PXC::IPXC_DocAuthCallback*)authCallback.GetInterface(&__uuidof(PXC::IPXC_DocAuthCallback));
		hr = g_Inst->OpenDocumentFromFile((LPWSTR)sFileName, pAuthCallback, nullptr, 0, 0, &pDoc);
		if (FAILED(hr))
		{
			CString str;
			//LOG(hr, L"Error opening document '<i>%s</i>': <r><b>0x%.8lx</b> - %s</r>", sFileName, hr, GetErrorDesc(hr, str));
		}
		else
		{
			//LOG(hr, L"Document '<i>%s</i>' opened successfully.", sFileName);
		}
	} while (false);
	return hr;
}
My call from my function of print (so before I use a lot of other methods of PDFXCoreAPI.x64.dll like get position of text and convert it to png, but for test I use it for another file) :

Code: Select all

	if (true) {
		CComPtr<PXC::IPXC_Document> pDocTest;
		LPCWSTR sFileName = L"c:\\Users\\evgeny\\Documents\\2\\test.pdf";
		OpenDocFromFile(sFileName, pDocTest, g_Inst);
		PrintDoc(pDocTest, NULL);
		return -1;
	}
Thanks,
Evgeny.