Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Feb 09, 2015 7:57 am

Hi

Need some guidance. I'm putting together a PDF document in .net to be printed when its done. In this document I want to merge another pdf document received by a Web Service in Base64 String format.

My current solution is to write it to disc and then use pdfDocument.LoadFromFile. A bit clumsy i think.

Bernt

bernt
 
Posts: 6
Joined: Thu Feb 05, 2015 11:45 am

Mon Feb 09, 2015 8:57 am

Hello bernt,

Thanks for your inquiry.

Please refer to the code below to meet your requirement:
Code: Select all
//Load the existing document
MemoryStream ms1 = new MemoryStream(File.ReadAllBytes("xxx.pdf"));
//Load the pdf document received by a Web Service in Base64 String format
MemoryStream ms2 = new MemoryStream(Convert.FromBase64String("xxxx"));

Stream[] stream = { ms1, ms2 };

//Merge and save
PdfDocument.MergeFiles(stream).Save("outpu.pdf", FileFormat.PDF);
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Feb 09, 2015 9:48 am

Hi

Thanks, the memory stream is nice, is there a way to avoid saving it to disc? To print it off to printer directly?

Bernt

bernt
 
Posts: 6
Joined: Thu Feb 05, 2015 11:45 am

Tue Feb 10, 2015 1:21 am

Hello,

Please refer to the code below:
Code: Select all
//Load the existing document
MemoryStream ms1 = new MemoryStream(File.ReadAllBytes("xxx.pdf"));
//Load the pdf document received by a Web Service in Base64 String format
MemoryStream ms2 = new MemoryStream(Convert.FromBase64String("xxxx"));
//Merged file stream
MemoryStream ms3 = new MemoryStream();

Stream[] stream = { ms1, ms2 };
//Merge and print
PdfDocument.MergeFiles(stream).Save(ms3);

new PdfDocument(ms3).PrintDocument.Print();
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Wed Feb 11, 2015 8:57 am

Hello,

Have you tried the code provided? Has your issue been resolved? Could you please give us some feedback if convenience?

Best Regards,
Betsy
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Feb 23, 2015 11:37 am

Hello Thanks for that.

The issue I'm trying to solve is a bit different now. Please let me start over....

I have a PDF document (a transport label) received from DHL via a web service as Base64String.

Code: Select all
                File.WriteAllBytes(pdfFileName, Convert.FromBase64String(val.Value))
                Dim proc As New Process
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                proc.Start("AcroRd32.exe", String.Format("/N /T {0} ""{1}""", pdfFileName, printer))


The only thing I want to do with it is to get it printed on a Datamax printer without losing resolution. I can get this done saving the pdf document on disc and start an adobe process that prints the file. But this only works if I set the default papersize exactly to the pdf document size, otherwise the printed resolution will bad.

SO what I'm looking for is to be able to set the printer papersize based on the pdf document size as received from DHL (it varies with purpose) and print it.

I'm convinced Spire can do this for me, looking forward to You suggestions.

Bernt

bernt
 
Posts: 6
Joined: Thu Feb 05, 2015 11:45 am

Tue Feb 24, 2015 6:52 am

Hello bernt,

Thanks for your inquiry.

For your requirement, please refer to the code below:
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

SizeF pageSize = pdf.Pages[0].Size;

PageSettings ps = new PageSettings();
ps.PaperSize = new PaperSize("MyPaperSize", (int)pageSize.Width, (int)pageSize.Height);

pdf.PrintDocument.DefaultPageSettings = ps;

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.XLS