How to convert a colored document to a monochrome one?

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

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

relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi, I've tried to set printing preferences as you advised me. All I achieved you can see in the attachment. Can you recommend me something else? Thanks!

Code: Select all

        private void GrayscaleConversion()
        {
            const int decimalFactor = 10;
            PDFPrinter.SetAsDefaultPrinter();
            bPXCPrinterDefault = true;

            PDFPrinter.Option["Graphics.Color.Convert.Method"] = 1;
            PDFPrinter.Option["Graphics.Color.Downsample.To"] = 300;
            PDFPrinter.Option["Graphics.Indexed.Downsample.To"] = 300;
            PDFPrinter.Option["Graphics.MonoAndDrawings.Downsample.To"] = 300;
            PDFPrinter.Option["Graphics.Indexed.Convert.Method"] = 1;
            PDFPrinter.Option["Graphics.MonoAndDrawings.Convert.Method"] = 1;
            PDFPrinter.Option["Fonts.Subset"] = false;
            PDFPrinter.Option["DevMode.PapSize"] = 256;
            PDFPrinter.Option["DevMode.CWidth"] =  (short)CurrentWidthInMm * decimalFactor; // IF NOT INTEGRAL THEN A4 FORMAT!
            PDFPrinter.Option["DevMode.CHeight"] = (short)CurrentHeightInMm * decimalFactor;
            PDFPrinter.Option["Paper.SheetWidth"] = (short)CurrentWidthInMm * decimalFactor;
            PDFPrinter.Option["Paper.SheetHeight"] = (short)CurrentHeightInMm * decimalFactor;
            PDFPrinter.Option["Paper.SheetSizeIndex"] = -2;
            PDFPrinter.Option["Save.SaveType"] = 2;
            PDFPrinter.Option["Save.ShowSaveDialog"] = false;
            PDFPrinter.Option["Save.File"] = _tempPrintFileForGrayscaleConversion;
            PDFPrinter.Option["Save.WhenExists"] = 1;
            PDFPrinter.Option["Save.RunApp"] = false;
            PDFPrinter.ApplyOptions(0);

            // ALL I FOUND OF PRINTING PROPERTIES THAT ALTER THE OUTPUT DOCUMENT SIZE
            // ViewerSetProperty IS A WRAPPER METHOD INCLUDING A TRY-CATCH BLOCK
            ViewerSetProperty("Print.PaperHeight", (short)CurrentHeightInMm * decimalFactor);
            ViewerSetProperty("Print.PaperWidth", (short)CurrentWidthInMm * decimalFactor);
            ViewerSetProperty("Print.ScaleSimple.AutoCentre", 1);

            pdfViewer.PrintDocument(_documentId, 2);

            if (bPXCPrinterDefault)
            {
                PDFPrinter.RestoreDefaultPrinter();                
                bPXCPrinterDefault = false;
            }
        }
Attachments
grayscalePrintingIntoAFileWithAlteredPrintSettings.zip
(41.47 KiB) Downloaded 262 times
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Hi Relapse,

I will need to discuss this with the colleagues in the Canadian office - so we will post back an update a bit later today.

Cheers,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Hi Relapse,

Could you please send a compilable sample project showing this problem so that we can test here on our end?

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! Thanks for your effort! I'll try to assemble such a sample project but it will take some time.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Thanks Relapse,

Looking forward to the sample!

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! I assembled a test application on the base of your "FullDemo" sample, because it was the quickest solution. The files are in the attachment. Thanks a lot once more!
Attachments
sampleFiles.zip
(2.73 MiB) Downloaded 255 times
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Thanks Relapse,

We will take a look and advise shortly.

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Thanks, Stefan! I've noticed that if the DevMode block is commented out it affects some little difference in the converted file. Please see the screenshots in the attachment.
Attachments
button3_Click.zip
(77.27 KiB) Downloaded 253 times
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Thanks Relapse,

Noted and will be discussed with our Drivers expert when he comes to work in the Vancouver Island office.

Best,
Stefan
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Hi Relapse,

We've just found a bug in the Viewer that was causing the incorrect behaviour when converting to greyscale. This is now fixed and the sample project works as expected. The fix will be in the next build of our Viewer.

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi Stefan. I'm glad to hear that, it's a good feeling to help improving your product.

P.S. I've read my messages once more and came to conclusion that it may be not distinct enough what the problem was :D. The only thing I was irritated with was the size of the original object in the converted document after printing with the PrintDocument method of the viewer.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Hi Relapse,

Thanks - yes I figured it was the size that you are having issues with. I will double check with Ivan to confirm this is what he fixed :)

Best,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! I've just installed the last build of the viewer SDK (2.5.207 instead of 2.5.205) but it doesn't function. Maybe the bug fix isn't yet in that version?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Ivan - Tracker Software »

I'm afraid you have to update driver too
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Sorry but it doesn't help :( Maybe I've installed something wrong.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: How to convert a colored document to a monochrome one?

Post by John - Tracker Supp »

Hi Relapse,

we have re-tested here and all is working as required ...

The most likely issue we 'believe' is there are some artifacts of an older build on your system somewhere causing problems - can you please ensure that you definately have the lastest builds only on your system - or better yet if possible install on a clean system and advise if the issue still persists - because despite our best efforts we cannot reproduce here ...

Thanks
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! Sorry for my long silence. I'll try to install all the things on a new virtual machine in order to test it properly. Thanks a lot for your reply. I'll surely inform you about my results.
Last edited by relapse on Fri Dec 14, 2012 1:19 pm, edited 1 time in total.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

:)
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi, I've installed these packages on a new virtual machine:
  • PDF-Tools 4 SDK
    PDF-XChange 5 API
    PDF-XChange Viewer SDK

In the application directory of my program I have amongst others the following dll's:
  • AxInterop.PDFXCviewAxLib.dll 1.0.0.0 05.01.2012
    Interop.PDFXCviewAxLib.dll 1.0.0.0 05.01.2012
    Interop.PXCComLib.dll 1.0.0.0 17.05.2012
    Interop.PXCComLib5.dll 1.0.0.0 21.05.2012
    PDFXCviewAx.dll 2.5.207.0 12.11.2012
    pxclib40.dll 4.0.207.0 12.11.2012
    pxcview.dll 2.5.207.0 12.11.2012
    xcpro40.dll 4.0.207.0 12.11.2012
However it doesn't function yet. Maybe it depends upon the fact that I don't use the full version of the PDF-XChange 5 API?

Are the both files Interop.PXCComLib5.dll and Interop.PXCComLib.dll responsible for the new functionality? I guess the aren't because the both ones are very old :D . I think the corrected functionality is in the library of the PDFXChange Viewer (PDFXCviewAx.dll). But as you see it's up-to-date.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: How to convert a colored document to a monochrome one?

Post by John - Tracker Supp »

Hi,

Both these files are 'helper' DLL's for .NET (like a layer between .NET and our ActiveX).

Visual studio creates them automatically when you add the AX to your C#/VB.NET project.

It is safe to remove them - they will automatically be created on the project's build.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Ivan - Tracker Software »

You sample (modified a bit) works fine on my side.
Please check attachment.
Attachments
FullDemo.rar
(111.99 KiB) Downloaded 216 times
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! I've found the differences between your code and mine in the sample program. These were commands setting the DevMode properties. I've altered my true program a little bit and tested it. Now it works! Thanks a lot! I'm really happy now! :D :D :D

These are my code snippets (C#) in the last variant. Don't forget to use the build version of the viewer SDK from the version 2.5.207 (Updated on 12 Nov 2012) and higher!

Code: Select all

using PDFXCviewAxLib;
using PXCComLib5;

...

private CPXCPrinter _pdfPrinter;
private bool _bPxcPrinterDefault;

...

var prnFactory = new CPXCControlEx();
_pdfPrinter = (CPXCPrinter) prnFactory.Printer["", "Simple PDF-XChange 2012", "<REG CODE>", "<DEV CODE>"];
_bPxcPrinterDefault = false;

...

const int factor = 10;
_pdfPrinter.SetAsDefaultPrinter();
_bPxcPrinterDefault = true;
_pdfPrinter.Option["Graphics.Color.Convert.Method"] = 1;
_pdfPrinter.Option["Graphics.Color.Downsample.To"] = 300;
_pdfPrinter.Option["Graphics.Indexed.Downsample.To"] = 300;
_pdfPrinter.Option["Graphics.MonoAndDrawings.Downsample.To"] = 300;
_pdfPrinter.Option["Graphics.Indexed.Convert.Method"] = 1;
_pdfPrinter.Option["Graphics.MonoAndDrawings.Convert.Method"] = 1;
_pdfPrinter.Option["Fonts.Subset"] = false;
_pdfPrinter.Option["DevMode.PapSize"] = 256;
_pdfPrinter.Option["DevMode.CWidth"] = (short)_pdfViewer.CurrentWidthInMm * factor;
_pdfPrinter.Option["DevMode.CHeight"] = (short)_pdfViewer.CurrentHeightInMm * factor;
_pdfPrinter.Option["Save.SaveType"] = 2;
_pdfPrinter.Option["Save.ShowSaveDialog"] = false;
_pdfPrinter.Option["Save.File"] = _tempPrintFileForGrayscaleConversion;
_pdfPrinter.Option["Save.WhenExists"] = 1;
_pdfPrinter.Option["Save.RunApp"] = false;
_pdfPrinter.ApplyOptions(0);
_pdfViewer.SetProperty("Print.ScaleSimple.AutoCentre", 1, 0);
_pdfViewer.PrintDocument(_documentId, 2);
if (!_bPxcPrinterDefault) {
    return;
}
_pdfPrinter.RestoreDefaultPrinter();
_bPxcPrinterDefault = false;
:D
Last edited by relapse on Thu Dec 20, 2012 9:50 am, edited 1 time in total.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Tracker Supp-Stefan »

Glad to hear it's working relapse!

And thanks for posting it here in the forums to make it available for everyone that might need this in the future!

Cheers,
Stefan
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

:D Happy New Year! :D
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: How to convert a colored document to a monochrome one?

Post by John - Tracker Supp »

U too :)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi! :D I've discovered the following phenomenon. I've tried to convert a pdf document including vector graphics into a BW one printing it into a file (as it's described above). Then I found out that the vector graphics were converted into a bitmap (I suppose it's so) with a quality loss (please see the attachment). Are there any properties in the Drivers API controlling the fineness of the vector-bitmap conversion?
Attachments
afterPrinting.zip
(169.74 KiB) Downloaded 209 times
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to convert a colored document to a monochrome one?

Post by Ivan - Tracker Software »

It will depend on the PDF document. The PDF graphics model is not the same as the GDI graphics model and in some circumstances the viewer will rasterise vector graphics during printing (for example, it will be done when pattern filling is used because patterns in the Windows API has some limitations; or when blend modes or transparency are used - blend modes are not supported by the Win GDI, and transparency is not supported by most printers). In other words - using a printer to convert an existing PDF to a PDF never is/was a good idea.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: How to convert a colored document to a monochrome one?

Post by relapse »

Hi, Ivan! I've read in your post your statement that "using a printer to convert an existing PDF to a PDF never is/was a good idea".
1) Can YOU advise me another way to convert a PDF?
2) Enclosed you will find in my attachment an illustration of a phenomenon I've found converting a pdf with PDFdriverAPI and with an Adobe printer. In your variant there is a slight displacement of the coordinates origin. I guess it results through the fact that the setting of the paper size is limited in its exactitude to one tenth of a millimeter. Is it (this displacement) to avoid?


Thanks for your replies!


P.S. I've also noticed a displacement in the pdf printed with Adobe PDF but it's less than after printing with PDFXChangePrinter.
Attachments
sample.zip
(115.67 KiB) Downloaded 213 times
Post Reply