How can I print the PDF by sending the PDF bytes?

Viewed 611

I want to print pdf directly using wifi. Some printing programs send packages as follows.

enter image description here

Actually, the important part is here. PDF bytes are sent this way. (I did not copy them all)

.........!...*b8V}2.......*b16W....```....".tt..*b7V.?......*b0W.*b7V.?......*b0
W.*b7V.?......*b0W.*b8V}2.......*b39W....~~~.........    
.&&&...................*b10V.>.........*b37W....gg..aa...a..4..9.E...aa...abb.|...*b3Vx5..*b35W....

But when I split a pdf into bytes, something different happens.

enter image description here

How can I convert PDF to bytes like these programs?

NOTE: Worked on the same pdf. NOTE2: There is no problem with the parts starting with @PJL. I'm adding those already. The main problem is they split the PDF into bytes differently. I want to know how.

1 Answers

Convert loading file to byte array

 //Converting loaded file to Byte array 

        byte[] dataBytes = File.ReadAllBytes("loaded.pdf"); 


        //Saving individual pages as  PdfDocument 

        List<PdfDocument> seperatePDF = SeperateAsPDF(dataBytes); 

Code snippet for saving each page to list as individual PdfDocument:

 public static List<PdfDocument> SeperateAsPDF(byte[] myFile) 
    { 
        //Load document. 

        PdfLoadedDocument loadedDocument = new PdfLoadedDocument(myFile); 

        List<PdfDocument> PdfList = new List<PdfDocument>(); 

        for(int i = 0; i < loadedDocument.Pages.Count; i++) 
        { 
            PdfDocument doc = new PdfDocument(); 
            doc.ImportPageRange(loadedDocument, i, i); 
            PdfList.Add(doc); 
            
        } 
        return PdfList; 

     } 

Essential PDF also allows to split the pages of an existing PDF document into multiple individual PDF documents. The following code snippet explains the same.

 //Load document. 

        PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Output.pdf"); 

        //Sets pattern. 

        const string destFilePattern = "Output" + "{0}.pdf"; 

        //Split the pages into separate documents. 

        loadedDocument.Split(destFilePattern); 

        //close the document 

        loadedDocument.Close(true); 

Note : This code is in C#. Please inform if it works.

Related