PaperSize and custom Paper Types

Hi again,
I’ve got another question regarding trays in a roundabout way. The tray stuff I’m not too concerned about, but what I am interesting in is the use of PaperSizes in Aspose.
Basically I have this situation:

  • I have a printer where you can specify custom paper types
  • I create a paper type with A4 dimensions, but call this paper type “JoJo”
  • I open Word, type some stuff, select that printer
  • I open Page Setup (whichever Word version), go to Paper tab.
  • I select “JoJo” as my paper size (which is A4 with a different paper size name).

Now when I create an Aspose Document class in code, I generally do this:

  • Create new instance of document using file path
  • Create new instance of Printing.PrinterSettings class, set to printer with “JoJo”
  • When I loop through PaperSizes on that printer, I can see “JoJo” and the rawkind.
  • I use code similiar to:
  • Now I’d expect the RawKind of the Aspose call to match the RawKind when I looped through the paper sizes on that printer. But I don’t I usually have 0 returned.

What my question is:
Because I can save that document in Word, open it up again (this is not even considering Aspose in the picture yet) and see that it knows the PaperSize I picked earlier, I’m guessing Word saves this information into the file itself.
Can I read the paper size from the Aspose document? I can if the size is normal and not a custom one, but what I’d like to do ideally is:
- Read document in using Aspose
- Get the custom paper size, specfically the custom name of the paper size for an individual page
Is there anywhere I can do this?


Thanks for your request. Aspose.Words can return only paper sizes, which are listed in the PaperSize enumeration:
If there is no appropriate paper size in this enumeration, PaperSize.Custom is returned.
I think in your case, you can try also reading page dimensions:
So is paper dimensions is the same as A4, but PaperSize returns PaperSize.Custom you can assume that paper size is “JoJo”.
Best regards.

Cheers for that, I was thinking that much.
The situation I have is this basically:

  1. Customer defines 4 paper types on printer, all the same size (A4)
  2. Customer creates 4 different documents in Word
  3. Customer selects different paper sizes for each document (from step 3). Note that only the name is changing, the physical paper size is the same for all documents.

Now I only have this problem for one customer (so far). All the others tend to setup their document based on a page/section goes to a certain tray (which works sweet as now).
I guess this is kinda odd, essentially all the paper sizes are the exact same they are picking from - the only difference on the Word side is the name of the paper size. When Word prints, it seems to send the paper size to Windows, and Windows then relates that to the paper source on the printer and prints from the respective tray.
I would just like to get the name of the paper size selected. From the looks of it, it’s not possible at all and you can only get the different sizes (as you say). And to be honest, that makes sense, just thought I’d ask and see if you would support this because we do have a unique situation where it would be nice to have this working.
Cheers for the help though!

Hi Tyron,

Thank you for additional information. Could you please attach sample document with specified custom paper name? I will check it and provide you more information.
Best regards.

Here you go, there are two attachments:

    This is the simple Word document, has one page, first page is setup to go to a paper size called “Tyron”. I’m not sure you’ll see what I mean though, since “Tyron” is data coming from the printer itself, unless Word saves that paper size name in the document itself? I’m guessing it must do, because Word can differentiate between Tyron (which is A4 size) and just plain old A4.

  2. PAGE_SETUP.jpg

This is just a screenshot of the paper size name, nothing too spectacular here.

Hi Tyron,

Thank you for additional information. It seems MS Word does not store name of paper itself, it seems it stores just a code of paper size. On my side, Ms word shows A4 size. But if I save document to DOCX, I see 134 paper size code:

<w:sectPr w:rsidR="007442F2" w:rsidSect="00382C70">
	<w:pgSz w:w="11907" w:h="16834" w:code="134" />
	<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0" />
	<w:cols w:space="708" />
	<w:docGrid w:linePitch="360" />

Best regards.

Thanks for the super fast replies!
I see what you mean, when I open the DOCX version of the file up in a compression tool and pull out “word\document.xml”, I can see that as well. That code, “134” is the code I need.
Apart from pulling that DOCX file apart using compression libraries in .NET, is there anyway using Aspose I can get this code? Essentially, I’d like to do something like:

Private Function GetPaperSizeCodes(ByVal Filename As String, ByVal PrinterName As String) As Dictionary(Of Integer, Integer)
    Dim pSettings As Printing.PrinterSettings
    Dim aspDoc As Aspose.Words.Document
    Dim pCodes As Dictionary(Of Integer, Integer)

        ' init vars.
        pCodes = New Dictionary(Of Integer, Integer)
        pSettings = New Printing.PrinterSettings
        pSettings.PrinterName = PrinterName
        aspDoc = New Aspose.Words.Document(Filename)

        ' go through each page, get the actual paper size code.
        For i As Integer = 0 To aspDoc.PageCount - 1
            Dim pSize As Printing.PaperSize
            pSize = aspDoc.GetPageInfo(i).GetDotNetPaperSize(pSettings)
            pCodes.Add(i, pSize.RawKind)

        Return pCodes

    Catch ex As Exception
    End Try
End Function

So this would really just trip through the pages in the document, and get the raw kind of paper size from the document. Unfortunately, what the above code returns me is generally the A4 size because “Tyron” is the same physical size as A4. A debug example is:

page: 0, rawkind: 9
I’m guessing I get 9 as the RawKind because in the PaperSize type (in Printing namespace), A4 is of type 9. I’d expect this to say 134 instead of 9. When I just get the Aspose PaperSize (ie. don’t call GetDotNetPaperSize, I just get A4 as the document type - because the dimensions are the same).

Reading the DOCX file directly is an option, but a very, very last resort (and not likely to be taken). And that still leaves DOC files which we still need to support because of other reasons.
So is there any way to get the actual RawKind from the document whilst still using the Aspose object (that is, the value of w:code attribute from the DOCX).
Thanks a million for your help though, awesome stuff!

Hey again - just had another thought on this, you know how you guys have this enumeration:
Where as the System.Printing.PaperSize is a class with Height, Kind, PaperName, RawKind and Width properties, what if the Aspose one was something similiar? Not sure how much this would change things (and to change the enum to a class would probably break functionality everywhere). And you probably wouldn’t have this request asked a lot either!
I guess the other option is when you called GetDotNetPaperSize and pass in the printer settings, it actually returned the PaperSize that was defined in the document.
Unless I’m missing something (which could totally be the case!)

Hi Tyron,

Thank you for additional information. I think we should just add PageInfor.RawPaperSize property, which will return this code. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Best regards.

Legend, thanks heaps for that Alexey!
Looking forward to the release, this is about the last item we have standing using the Aspose components.