ReStorePrinterOptions using IStream

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

bmills
User
Posts: 6
Joined: Thu Nov 26, 2009 9:24 pm

ReStorePrinterOptions using IStream

Post by bmills »

I am attempting to load desired printer options from a .ppr file previously saved.
When the printer is dynamically created and regcodes added, I want to then check for existence of a .ppr file and load it if exists.
I am using the code below to load a .ppr if found:


'BEGIN OF CODE TO LOAD THE .ppr FILE USING .RestorePrinterOptions
Dim Size As Long
Dim ByteArray() As Byte
Dim f As Integer
Dim mem As Long
Dim ptr As Long
Dim strm As IUnknown
Dim filename As String
filename = App.Path & "\" & PDFPrinter.name & ".ppr"
'if there is a printer profile load it, otherwise manually set options below
If Dir(filename) <> "" Then
' Read the file (fileName) into memory.
Size = FileLen(filename)
ReDim ByteArray(1 To Size)
f = FreeFile
Open filename For Binary Access Read As #f
Get #f, , ByteArray()
Close #f

' Copy it into global memory.
mem = GlobalAlloc(&H2, Size)
ptr = GlobalLock(mem)
MoveMemory ByVal ptr, ByteArray(1), Size
GlobalUnlock mem

' Create an OLE Stream object.
CreateStreamOnHGlobal mem, 1, strm

' Load the stream
Call PDFPrinter.ReStorePrinterOptions(strm)
PDFPrinter.ApplyOptions 0 'after loading printer profile need to applyoptions
Else
With PDFPrinter
.Option("Compression.Graphics") = "Yes"
.Option("Compression.Text") = "Yes"
.Option("Compression.ASCII") = "No"
.Option("Compression.Color.Enabled") = "Yes"
.Option("Compression.Color.Method") = "Auto"
.Option("Compression.Indexed.Enabled") = "Yes"
.Option("Compression.Indexed.Method") = "Auto"
.Option("Compression.Mono.Enabled") = "Yes"
.Option("Compression.Mono.Method") = "Auto"
'.Option("Paper.SheetSizeIndex") = 5 'Letter
.Option("Save.SaveType") = 2
.Option("Save.ShowSaveDialog") = False
.Option("Save.Path") = tstrings.ScanDump
.Option("Save.File") = "Img0001"
.Option("Save.WhenExists") = 2
.Option("Save.AutoNumber.Start") = 1
.Option("Save.AutoNumber.NumDigits") = 4
.Option("Save.RunApp") = False
.ApplyOptions 0
End With
Wait 100
End If
'END OF CODE TO LOAD THE .ppr FILE USING .RestorePrinterOptions



Below is code used as part of a menu selection to Save the current Printer Options to a .ppr file.


'BEGIN OF CODE TO SAVE PRINTER OPTIONS TO .ppr FILE USING .StorePrinterOptions
Dim PDF_PrinterSettings As VBStrm.IStream
Call SHCreateStreamOnFile(App.Path & "\" & PDFPrinter.name & ".ppr", STGM_WRITE Or STGM_SHARE_EXCLUSIVE Or STGM_CREATE, PDF_PrinterSettings)
Call PDFPrinter.StorePrinterOptions(PDF_PrinterSettings)
PDF_PrinterSettings.Commit STGC_DEFAULT
Set PDF_PrinterSettings = Nothing
'END OF CODE TO SAVE PRINTER OPTIONS TO .ppr FILE USING .StorePrinterOptions




If the .ppr file is one which was created by using the Export option within the printer driver properties, then the code above to RestorePrinterOptions from that file appears to work Ok. However if the .ppr file was created by using the above code to StorePrinterOptions, the options do not appear to load. When examining the contents of the .ppr created using the Export option from the printer driver properties, and the one created using the above code, the file data begins the same, however the file created from the Export option is larger and contains more data.

I could not find any code samples for using the .StorePrinterOptions and .RestorePrinterOptions, and am not sure if my problem is related to the call to the driver API, or it has to do with the implementation of the IStream object.

Any information provided to help clarify how to use these functions would be appreciated.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3550
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: ReStorePrinterOptions using IStream

Post by Ivan - Tracker Software »

Can you send me your .ppr file created by your Export routine?
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.
bmills
User
Posts: 6
Joined: Thu Nov 26, 2009 9:24 pm

Re: ReStorePrinterOptions using IStream

Post by bmills »

Thanks Ivan, can you enable posting attachments?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17949
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: ReStorePrinterOptions using IStream

Post by Tracker Supp-Stefan »

Hello bmills,

Attachments up to 5mb are already allowed, but only if those are an archive or a .pdf file. images are explicitly prohibited for direct upload due to some inappropriate ones being posted in the past by bots.

Regards,
Stefan
bmills
User
Posts: 6
Joined: Thu Nov 26, 2009 9:24 pm

Re: ReStorePrinterOptions using IStream

Post by bmills »

Thanks Stefan, I may be missing something here, but I don't see an option to add an attachment and at the bottom of the forum page I see the below permissions.

Bill

Forum permissions

You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You cannot post attachments in this forum
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17949
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: ReStorePrinterOptions using IStream

Post by Tracker Supp-Stefan »

Hello bmills,

You might be using a different skin than I am - but the option to attach files should be at the same place as on my screenshot below.

Regards,
Stefan

P.S. You need to .zip/.rar/.7z files or images will not be uploaded
You do not have the required permissions to view the files attached to this post.
bmills
User
Posts: 6
Joined: Thu Nov 26, 2009 9:24 pm

Re: ReStorePrinterOptions using IStream

Post by bmills »

Thanks Stefan,

It could be the skin I am using as you suggest, or version of IE or my account is missing permissions. Just below the last note in your post the line below appears in red indicating I do not have the required permissions.... which is preventing me from viewing your attached image.

Bill Mills

P.S. You need to .zip/.rar/.7z files or images will not be uploaded

You do not have the required permissions to view the files attached to this post.
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom

Re: ReStorePrinterOptions using IStream

Post by John - Tracker Supp »

Hi Bill - no problem,

please email it to support@pdf-xchange.com for the attention of Ivan and with a link back to this forum post in the email body for reference.

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