Custom Page Size without associated PageMediaSizeName not Working with XpsDocumentWriterI have an application that is using the XpsDocumentWriter to write FixedDocuments that it generates to a PDF print driver installed on the machine.  A PrintTicket is created for the document and passed to the Write method on the XpsDocumentWriter.  For documents that are a custom page size and have no PageMediaSizeName associated with them, the PageMediaSize set on the PrintTicket is created with just the page height and width set.  When these documents with a custom page size are written to a PDF print driver installed on the machine, the resulting PDF page size is not correct, however if the document with a custom page size is written to an XPS file, the XPS displays in the proper custom page size.  Is there anyway to get the custom page size to properly be passed/set on the resulting PDF?  <br/><br/>Here is an example of the code:<br/><br/><span style="font-size:x-small;color:#008000"><span style="font-size:x-small;color:#008000"><font size=2 color="#008000"><font size=2 color="#008000"> <p>//Create XpsDocumentWriter to write to PDF printer installed on machine</p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintServer</span></span><span style="font-size:x-small"> printServer = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintServer</span></span><span style="font-size:x-small">(@<span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;\\&quot;</span></span><span style="font-size:x-small"> + System.</span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">Environment</span></span><span style="font-size:x-small">.MachineName);</span><br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue </span></span>printQueue = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span><span style="font-size:x-small">(printServer, &quot;PDF printer Name&quot;);<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">XpsDocumentWriter </span></span>docWriter = </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span><span style="font-size:x-small">.CreateXpsDocumentWriter(printQueue);<br/><span style="color:#008000"><br/>//Get FixedDocument from custom method.<br/></span></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">FixedDocument</span></span><span style="font-size:x-small"> fixedDoc = GetFixedDocument();<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><span style="color:#008000"><br/>//Create PrintTicket for document and set its page size to the proper custom page size<br/></span>PrintTicket</span></span><span style="font-size:x-small"> printTicket = <span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintTicket</span></span><span style="font-size:x-small">();<br/><span style="color:#008000">//Set the page size to a custom 3.5&quot; x 2.5&quot; page</span><br/><span style="font-size:x-small">printTicket.PageMediaSize = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PageMediaSize</span></span><span style="font-size:x-small">(3.5</span><span style="font-size:x-small"> * 96.0, 2.5 * 96.0);<br/><span style="font-size:x-small"><br/><span style="color:#008000">//Write out the FixedDocument</span><br/>docWriter.Write(fixedDoc, printTicket);</span></span></span></span><br/></span></p> <br/><br/>© 2009 Microsoft Corporation. All rights reserved.Mon, 02 Nov 2009 11:44:04 Z75e224c2-b711-45f2-8247-738d0f47d490http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/75e224c2-b711-45f2-8247-738d0f47d490#75e224c2-b711-45f2-8247-738d0f47d490http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/75e224c2-b711-45f2-8247-738d0f47d490#75e224c2-b711-45f2-8247-738d0f47d490drcarter44http://social.msdn.microsoft.com/Profile/en-US/?user=drcarter44Custom Page Size without associated PageMediaSizeName not Working with XpsDocumentWriterI have an application that is using the XpsDocumentWriter to write FixedDocuments that it generates to a PDF print driver installed on the machine.  A PrintTicket is created for the document and passed to the Write method on the XpsDocumentWriter.  For documents that are a custom page size and have no PageMediaSizeName associated with them, the PageMediaSize set on the PrintTicket is created with just the page height and width set.  When these documents with a custom page size are written to a PDF print driver installed on the machine, the resulting PDF page size is not correct, however if the document with a custom page size is written to an XPS file, the XPS displays in the proper custom page size.  Is there anyway to get the custom page size to properly be passed/set on the resulting PDF?  <br/><br/>Here is an example of the code:<br/><br/><span style="font-size:x-small;color:#008000"><span style="font-size:x-small;color:#008000"><font size=2 color="#008000"><font size=2 color="#008000"> <p>//Create XpsDocumentWriter to write to PDF printer installed on machine</p> </font></font></span><font size=2 color="#008000"> <p> </p> </font></span> <p><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintServer</span></span><span style="font-size:x-small"> printServer = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintServer</span></span><span style="font-size:x-small">(@<span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;\\&quot;</span></span><span style="font-size:x-small"> + System.</span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">Environment</span></span><span style="font-size:x-small">.MachineName);</span><br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue </span></span>printQueue = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span><span style="font-size:x-small">(printServer, &quot;PDF printer Name&quot;);<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">XpsDocumentWriter </span></span>docWriter = </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span><span style="font-size:x-small">.CreateXpsDocumentWriter(printQueue);<br/><span style="color:#008000"><br/>//Get FixedDocument from custom method.<br/></span></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">FixedDocument</span></span><span style="font-size:x-small"> fixedDoc = GetFixedDocument();<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><span style="color:#008000"><br/>//Create PrintTicket for document and set its page size to the proper custom page size<br/></span>PrintTicket</span></span><span style="font-size:x-small"> printTicket = <span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintTicket</span></span><span style="font-size:x-small">();<br/><span style="color:#008000">//Set the page size to a custom 3.5&quot; x 2.5&quot; page</span><br/><span style="font-size:x-small">printTicket.PageMediaSize = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PageMediaSize</span></span><span style="font-size:x-small">(3.5</span><span style="font-size:x-small"> * 96.0, 2.5 * 96.0);<br/><span style="font-size:x-small"><br/><span style="color:#008000">//Write out the FixedDocument</span><br/>docWriter.Write(fixedDoc, printTicket);</span></span></span></span><br/></span></p> <br/><br/>Thu, 14 May 2009 12:56:33 Z2009-05-14T12:56:33Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/75e224c2-b711-45f2-8247-738d0f47d490#cace49b9-30f2-4b56-83f4-0d68420606f0http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/75e224c2-b711-45f2-8247-738d0f47d490#cace49b9-30f2-4b56-83f4-0d68420606f0drcarter44http://social.msdn.microsoft.com/Profile/en-US/?user=drcarter44Custom Page Size without associated PageMediaSizeName not Working with XpsDocumentWriter<p>I determined how to get this to work, at least in my scenario, and I tested it against two different PDF print drivers .  The code change does not seem right or logical but it works.  In summary, if a PageMediaSizeName that is NOT supported by the printer is passed/set on the PageMediaSize for the PrintTicket, and the PrintTicket is merged with the UserPrintTicket of the PrintQueue, then the resulting PDF has the correct custom page size.  Setting the PageMediaSizeName to Unknown did not work, however the resulting ValidatedPrintTicket does show the PageMediaSizeName as Unknown.  The code below should be enhanced to insure the PageMediaSizeName is not supported by the PrintQueue, but it demonstrates the fix.<br/><br/>Code sample:<br/><span style="font-size:xx-small"><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><br/>PrintServer</span></span><span style="font-size:x-small"> printServer = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintServer</span></span></span><span style="font-size:xx-small"><span style="font-size:x-small">(@<span style="font-size:x-small;color:#a31515"><span style="font-size:x-small;color:#a31515">&quot;\\&quot;</span></span><span style="font-size:x-small"> + System.</span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">Environment</span></span><span style="font-size:x-small">.MachineName);<br/></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue </span></span>printQueue = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span></span><span style="font-size:xx-small"><span style="font-size:x-small">(printServer, &quot;PDF printer Name&quot;);<br/><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">XpsDocumentWriter </span></span>docWriter = </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintQueue</span></span></span><span style="font-size:x-small"><span style="font-size:xx-small">.CreateXpsDocumentWriter(printQueue);<br/></span><span style="color:#008000"><br/><span style="font-size:xx-small">//Get FixedDocument from custom method.<br/></span></span></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><span style="font-size:xx-small">FixedDocument</span></span></span><span style="font-size:x-small"><span style="font-size:xx-small"> fixedDoc = GetFixedDocument();<br/></span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><span style="color:#008000"><br/><span style="font-size:xx-small">//Create PrintTicket for document and set its page size to the proper custom page size<br/></span></span><span style="font-size:xx-small">PrintTicket</span></span></span><span style="font-size:x-small"><span style="font-size:xx-small"> printTicket = <span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PrintTicket</span></span></span><span style="font-size:x-small"><span style="font-size:xx-small">();<br/><span style="color:#008000">//Set the page size to a custom 3.5&quot; x 2.5&quot; page passing PageMediaSizeName not supported by print driver</span><br/><span style="font-size:x-small">printTicket.PageMediaSize = </span><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff">new</span></span><span style="font-size:x-small"> </span><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PageMediaSize</span></span><span style="font-size:x-small">(<span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af">PageMediaSizeName</span></span><span style="font-size:x-small">.JapanLPhoto, </span>3.5</span></span><span style="font-size:x-small"><span style="font-size:xx-small"> * 96.0, 2.5 * 96.0);<br/></span><span style="font-size:x-small"><span style="font-size:x-small;color:#2b91af"><span style="font-size:x-small;color:#2b91af"><br/>ValidationResult</span></span><span style="font-size:x-small"> result = printQueue.MergeAndValidatePrintTicket(printQueue.UserPrintTicket, printTicket);<br/>printQueue.UserPrintTicket = result.ValidatedPrintTicket;<span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span><span style="font-size:xx-small"><span style="color:#008000">//Write out the FixedDocument</span><br/>docWriter.Write(fixedDoc, <span style="font-size:x-small">result.ValidatedPrintTicket</span>);</span></span></span></span></span></span></span></span></span></span></span></span></p>Thu, 14 May 2009 20:56:04 Z2009-05-15T12:53:21Z