Print Page | Close Window

Problem with SetRenderDCOffset

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2799
Printed Date: 27 Apr 24 at 10:26PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Problem with SetRenderDCOffset
Posted By: siggeltheturtle
Subject: Problem with SetRenderDCOffset
Date Posted: 20 Dec 13 at 12:13PM
Hi all,

my goal is to send a pdf to a defined printer with defined settings like tray, dpi etc. One important functionality is to shift the pdf to a defined offset position in order to align it precisely for different printers.

I tried some C++ example code and everything works fine - except for the offset having no impact at all. What I did (after unlocking the library and leaving out error handling here, except for the offset the code successfully printed out the given pdf):

QP.LoadFromFile(L"my.pdf", L""));
CustomPrinter = QP.NewCustomPrinter(L"Printername");
QP.SetupCustomPrinter(CustomPrinter, 5, 720) // dpi
...
iPrintOptions = QP.PrintOptions(0,0, L"Printing Sample");
QP.SetRenderDCOffset(50,100); // offset
QP.PrintDocument(CustomPrinter, 1, 1, iPrintOptions);


I tried the offset line at different places, but it had no impact. Am I using it in a wrong way? Or is there a completely different way for shifting the incoming pdf before printing it out?

Thanks in advance for your help,
siggeltheturtle



Replies:
Posted By: AndrewC
Date Posted: 29 Dec 13 at 2:19AM
Siggel,

The QP.SetRenderDCOffset function is only designed to work with the RenderPageToDC function.

One option may be to adjust the MediaBox/CropBox values to offset the whole page in order to simulate the setting of a printer margin.

Andrew.




Posted By: siggeltheturtle
Date Posted: 13 Jan 14 at 9:16PM
My full solution: when only modifying the crop box, I only was able to shift to the outside, but not into the page. I tried different combinations and finally ended up modifying all boxes in the same way to get the desired behavior.


Posted By: AndrewC
Date Posted: 14 Jan 14 at 11:08AM
Siggel,

Another option is to add a transformation matrix to the start to the PDF page to give it an offset.

            QP.LoadFromFile("myPDFfile.pdf", "");
            QP.NormalizePage(0);
            int c = QP.NewContentStream();

            string s = "1.05 0 0 0.5 20 200 cm ";   // ScaleX = 1.05, ScaleY = 0.5, XOffset = 20 points, YOffset = 200 points (from bottom)

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            Byte[] bytes = encoding.GetBytes(s);

            QP.SetContentStreamFromString(bytes);
            QP.MoveContentStream(c, 1);

            QP.SaveToFile("out.pdf");

You can always delete the added content stream after printing to restore the PDF page to its original state.



Posted By: JeffLebowski
Date Posted: 29 Sep 15 at 9:09AM
Hi,

I needed exactly the same thing and I used AndrewC's code (but in VBScript).
It works but only applies the offset to the first page. The other pages in the PDF remain without offset.

I'm not that experienced with the quickpdf functions. Is there an easy way to add the offsetstream to each page?


Posted By: JeffLebowski
Date Posted: 29 Sep 15 at 9:13AM
Nevermind, it was my mistake. Got it to work :)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk