1

我正在尝试通过System.Printing命名空间打印 XPS 流

    Stream stm = pdftron.PDF.Convert.ToXps(pdfdoc);

    LocalPrintServer localPrintServer = new LocalPrintServer();
    PrintQueueCollection pqc = localPrintServer.GetPrintQueues();
    PrintQueue defaultPrintQueue = localPrintServer.GetPrintQueue(_PrinterName);
    MemoryStream ms = defaultPrintQueue.GetPrintCapabilitiesAsXml();


    // Call AddJob
    System.Printing.PrintTicket printTicket = defaultPrintQueue.DefaultPrintTicket;


    PrintSystemJobInfo myPrintJob = defaultPrintQueue.AddJob();

    Stream myStream = myPrintJob.JobStream;//may be this line is wrong, can you suggest alternative?
    myStream = stm;//may be this line is wrong, can you suggest alternative?
    myStream.Close();//may be this line is wrong, can you suggest alternative?
    var inp= defaultPrintQueue.GetPrintCapabilities().InputBinCapability;
    System.Printing.PrintTicket newprintTicket = XpsPrinterUtils.ModifyPrintTicket(printTicket, "psk:JobInputBin", "NS0000:" + _PaperSource);
    System.Printing.ValidationResult vr = defaultPrintQueue.MergeAndValidatePrintTicket(printTicket, newprintTicket);// this line giving exception while changing page source merge and validate
    myPrintJob.Commit();

来自 github 的 XpsPrinterUtils.ModifyPrintTicket

代码不工作,我坚持这一点。

任何人对此都有很好的想法或解决方案,可以使用 system.printing 命名空间打印(pdftron 获得的 Xps 文件流)并动态更改页面源。

4

1 回答 1

0

我没有测试,但这似乎更接近正确的解决方案。

Stream stream_source = pdftron.PDF.Convert.ToXps(pdfdoc);
Stream stream_sink = myPrintJob.JobStream;
stream_source.CopyTo(stream_sink);

您可能希望通过将 stream_sink 创建为磁盘上文件的流来测试上述内容,并验证 stream_source.CopyTo(stream_sink) 是否按预期工作。如果是这样,那么任何剩余的问题都是使用 System.Printing API,而不是 PDFNet。

于 2016-05-04T19:05:32.267 回答