Problems with PXC_DrawTextExW

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

reinierkops
User
Posts: 93
Joined: Mon Jul 07, 2008 8:41 am

Problems with PXC_DrawTextExW

Post by reinierkops »

When I try to draw some portion of text into a merged PDF file, who is Initiated via

PXCp_init(out PDFid)

then call PXCp_llGetPageByIndex(PDFid, pageToPlace, out pageID);

then call PXC_DrawTextExW(pageID, ref rect, text, 0, text.Length, 0, ref opts);

I receive this error:

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="nl.rechtspraak.zidos.library"
StackTrace:
at nl.rechtspraak.zidos.library.general.XCPro40_Defs.PXC_DrawTextExW(Int32 content, PXC_RectF& rect, String str, Int32 sPos, Int32 len, Int32 flags, PXC_DrawTextStruct& lpOptions)
at nl.rechtspraak.zidos.library.general.ui.PDFMerger.CreateGoToButton(Int32 pageToPlace, Int32 gotoPage, Int32 PDFid, Double left, Double right, Boolean isActive) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.Library\general\ui\PDF.cs:line 292
at nl.rechtspraak.zidos.library.general.ui.PDFMerger.PlaceButtonsOnMergedPDF(Int32 PDFid, MergeDocumentProperties result) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.Library\general\ui\PDF.cs:line 242
at nl.rechtspraak.zidos.library.general.ui.PDFMerger.MergeDocuments() in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.Library\general\ui\PDF.cs:line 132
at nl.rechtspraak.zidos.library.business.Dossier.GenerateMergedDocument(DocumentType aType) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.Library\business\Dossier.cs:line 566
at nl.rechtspraak.zidos.library.ui.commands.CmdOpenDossierDoc.ExecuteImpl(Control aControl, Object aCargo) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.UI\library\ui\commands\CmdOpenDossierDoc.cs:line 72
at nl.rechtspraak.zidos.library.general.ui.CommandBase.Execute(Control aControl, Object aCargo) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.Library\general\ui\CommandBase.cs:line 87
at nl.rechtspraak.zidos.ui.usercontrols.Spam message posted by BOT engine - ignore - to be deleted by admin.DossierDocControl.createAndOpenDossierDocument() in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.UI\usercontrols\Spam message posted by BOT engine - ignore - to be deleted by admin\DossierDocControl.cs:line 178
at nl.rechtspraak.zidos.ui.usercontrols.Spam message posted by BOT engine - ignore - to be deleted by admin.DossierDocControl.buttonAdvNextPage_Click(Object sender, EventArgs e) in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.UI\usercontrols\Spam message posted by BOT engine - ignore - to be deleted by admin\DossierDocControl.cs:line 216
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at Syncfusion.Windows.Forms.ButtonAdv.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at Syncfusion.Windows.Forms.ButtonAdv.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at nl.rechtspraak.zidos.ui.Program.Main() in X:\Projects\Zidos\rr.zidos\19-branches\0.82\Zidos.UI\Program.cs:line 22
InnerException:
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Problems with PXC_DrawTextExW

Post by Lzcat - Tracker Supp »

Yes, this is correct behaviour. Why? Because you are mixed function from different pdf SDKs. Rule is simple: fuctions begin with PXCp_*, PXP_* and PXCV_* representing different pdf SDKs (pdf modification, pdf creation and simple pdf rendering corresponding), and any object created using functions from one of SDKs cannot be used in another two. If you need to add some content on existing PDf you may do thin in two ways:
1. Use xcpro40 Low-Level API only (require alot of work, but allow almost everything that allowed by PDF specification).
2. Create new document with additional content using pxclib40, save it to disk (in temporary file) and then combine with existing pdf using PXCp_PlaceContents function.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
reinierkops
User
Posts: 93
Joined: Mon Jul 07, 2008 8:41 am

Re: Problems with PXC_DrawTextExW

Post by reinierkops »

This is the situation:

We have several PDF documents, listed in a array with PDF file locations

XCPro40_Defs.PXCp_Init(out pdf, XCPro40_Defs.g_RegKey, XCPro40_Defs.g_DevCode);
res = XCPro40_Defs.PXCp_ReadDocumentW(pdf, mInputDocumentList[0].PhysicalFileName, 0);

then we will loop through the array, and add the file to the first document:

XCPro40_Defs.PXCp_Init(out pdf_to_merge, XCPro40_Defs.g_RegKey, XCPro40_Defs.g_DevCode);
XCPro40_Defs.PXCp_ReadDocumentW(pdf_to_merge, mInputDocumentList.PhysicalFileName, 0);
XCPro40_Defs.PXCp_CopyPageRange[] pagesRange = new XCPro40_Defs.PXCp_CopyPageRange[1];
pagesRange[0].StartPage = 0;
res = XCPro40_Defs.PXCp_GetPagesCount(pdf_to_merge, out PagesCount);
pagesRange[0].EndPage = PagesCount - 1;
pagesRange[0].InsertBefore = -1;

XCPro40_Defs.PXCp_InsertPagesTo(pdf_to_merge, pdf, pagesRange, 1, 0);

and as last I write the PDF to a file:
XCPro40_Defs.PXCp_WriteDocumentW(pdf, mOutputFileName,
XCPro40_Defs.PXCp_CreationDisposition.
PXCp_CreationDisposition_Overwrite, 0);

But I need to write a portion of text in this PDF file, before it's writed to filesystem. How do i need to do this?
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Problems with PXC_DrawTextExW

Post by Lzcat - Tracker Supp »

Just as I said before - create new document with required text and place it over existing. See https://forum.pdf-xchange.com/ ... =44&t=4648 for short explain.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
reinierkops
User
Posts: 93
Joined: Mon Jul 07, 2008 8:41 am

Re: Problems with PXC_DrawTextExW

Post by reinierkops »

Do you have a DLL definition for c# for function PXCp_PlaceContents.
Or do you have a c# class with all the definitions for XCPro40?
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Problems with PXC_DrawTextExW

Post by Lzcat - Tracker Supp »

Declarations:

Code: Select all

namespace PXCProDemo
{
    public class XCPro35_Defs
    {
		[StructLayout(LayoutKind.Sequential, Pack = 1)]
		public struct _PXCp_ContentPlaceInfo
		{
			 public uint DestPage;
			 public uint SrcPage;
			 public uint Alignment;
		};
		public enum PXCp_ContentPlaceAlign
		{
			 CPA_HorLeft     = 0x0000,
			 CPA_HorCenter   = 0x0001,
			 CPA_HorRigth    = 0x0002,
			 CPA_HorFit      = 0x0003,
			 CPA_VerBottom   = 0x0000,
			 CPA_VerCenter   = 0x0010,
			 CPA_VerTop      = 0x0020,
			 CPA_VerFit      = 0x0030,
			 CPA_Foreground  = 0x0100,
			 CPA_KeepAspect  = 0x0200,
		};

		public const String pxcpro40_lib = "xcpro40";

		[DllImport(pxcpro40_lib)]
		public static extern int PXCp_PlaceContents(IntPtr pDest, IntPtr pSource, UIntPtr cnt, ref _PXCp_ContentPlaceInfo pContentsInfo, uint flags);
	}
}
Call sample (assume that both documents has at least three pages):

Code: Select all

XCPro35_Defs._PXCp_ContentPlaceInfo[] pci = new XCPro35_Defs._PXCp_ContentPlaceInfo[3];

pci[0].DestPage = 0; // place on first page of destination
pci[0].SrcPage = 0;  // first page of source
// as background, fit size (sorce page will be scaled to destination)
pci[0].Alignment = (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_HorFit | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_VerFit;

pci[1].DestPage = 1; // place on second page of destination
pci[1].SrcPage = 2;  // third page of source
// as foreground (over destination), alignement left-bottom
pci[1].Alignment = (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_HorLeft | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_VerBottom | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_Foreground;

pci[2].DestPage = 2; // place on third page of destination
pci[2].SrcPage = 1;  // second page of source
// as foreground, fit size with keep proportion (sorce page will be scaled to destination, but page will be not distorted)
pci[2].Alignment = (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_HorFit | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_VerFit | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_KeepAspect | (uint)XCPro35_Defs.PXCp_ContentPlaceAlign.CPA_Foreground;

int res = XCPro35_Defs.PXCp_PlaceContents(pDestDocHanle, pSourceDocHanle, 3, ref pci[0], 0);
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.