Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Feb 23, 2015 3:29 pm

Hello

The issue I'm trying to solve is this:
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 load the Bas64String and 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:51 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
User avatar

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

Wed Feb 25, 2015 3:44 pm

Hi

Thanks for that but it doesn't work... the label gets scrinked. I guess this method uses the defaultPrinter settings from the file.

I want help with 2 things.

1 Load the pdf directly from memory Base64String into the PdfDocument(), and avoid saving it to a file.
2 Does Not understand what property to work with to get the size and margins right. Is it pdf.PrintDocument.DefaultPageSettings.

Bernt

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

Thu Feb 26, 2015 3:33 am

Hello bernt,

To help us resolve the problem, can you provide us this pdf document with Base64String format? Also, it would be very helpful if you can share a sample project?

Thank you.
Best Regards,
Burning
E-iceblue Support Team
User avatar

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

Thu Feb 26, 2015 9:45 am

Hi burning.liu

Great, lets start with the file. I receive the Bas64String from DHL webservice, L025139211.pdf. As you see below in the "Create File" code, the only thing I do is to write it to disc as byte().

If I open L025139211.pdf. with Adobe, pick the label printer (Datamax O´neal MP Compact 4 Mark II) I can see that the document is 4.1 by 6.7 inc. So I have created a staple on the printer with that size, using that staple: the printout from this manual process is perfekt.See Manual Adobe.pdf.

The "Print with Spire" code generate Auto Spire.pdf. The problem with it is that it is adjusted in size (I think) so the barcode is not sharp enough, the header "DHL PAKET" is gone.

What I want is to load the Base64String directly into the pdfDocument.
Print it with Spire so it looks like the Manual Adobe.pdf scan.

If possible it would be great if I could determine the document size and set the papersize dynamically in code based on what I receive from the DHL Webservice.


Bernt

-----------------------------------


'Create File
Dim outputParamameterCollection As ShippingParameterCollection
Dim responce = BlackboxService.PrintParcel(bbpHeader, inputParamCollection, outputParamameterCollection)
Dim val = outputParamameterCollection.FirstOrDefault(Function(p) p.Name.StartsWith("LABEL"))
File.WriteAllBytes(pdfFileName, Convert.FromBase64String(val.Value))



'Print With Spire
Dim myDoc As New PdfDocument
myDoc.PrinterName = "PP3"
myDoc.PageScaling = PdfPrintPageScaling.ActualSize
Dim ps As New PageSettings
ps.PaperSize = myDoc.PrintDocument.PrinterSettings.PaperSizes.Item(1)
ps.PrinterSettings.PrinterName = printer
ps.Margins.Top = 0
ps.Margins.Bottom = 0
ps.Margins.Left = 0
ps.Margins.Right = 0

myDoc.PrintDocument.DefaultPageSettings = ps
myDoc.PrintDocument.Print()

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

Fri Feb 27, 2015 7:08 am

Hello Bernt,

After some investigation about this problem, I found out that you must add custom papersize to the printer first, then you can print the document with the right size.

Here are some links that would help you:
http://stackoverflow.com/questions/6848 ... paper-size
http://stackoverflow.com/questions/2182 ... paper-size
http://www.codeproject.com/Articles/122 ... d-printers
Best Regards,
Burning
E-iceblue Support Team
User avatar

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

Return to Spire.PDF